1
0
Fork 0
mirror of https://github.com/munin-monitoring/contrib.git synced 2025-07-22 02:51:03 +00:00

Update voltcraft_tcm220_

v0.2 - added checksum validation of the parsed values
This commit is contained in:
nagyrobi 2014-04-02 13:26:19 +02:00
parent ddc595889f
commit 553811f889

View file

@ -39,8 +39,9 @@
# instead the 10 seconds default - this can be used to speed up the data acquisition process, however
# it can decrease battery life (with default values, two AAA alkaline batteries last cca 2 years).
#
# Tested & working with munin v.2.0.14 on Ubuntu LTS 12.04.2
# Created in 2013 by robi
# Tested & working with munin v.2.0.19-2 on Ubuntu LTS 12.04.4
# Created in 2014 by robi
# v0.2 - added checksum validation
# v0.1 - initial version
#########################################################################################################
## Magic Markers
@ -119,21 +120,29 @@ my $ch2temp = "U";
if ($response // "") {
my $hex = unpack 'H*', $response;
#print "$response\n"; #debug
#print "$hex\n"; #$hex should be something like "abc102999babc2017677" for +29.9 and +17.6
# print "$hex\n"; #$hex should be something like "abc102999babc2017677" for +29.9 and +17.6
my $ch1z ="";
my $ch2z ="";
my $ch1sum = substr($hex, 4, 1) + substr($hex, 5, 1) + substr($hex, 6, 1) + substr($hex, 7, 1);
my $ch1sul = substr(sprintf("%02d", $ch1sum), 1, 1);
my $ch2sum = substr($hex, 14, 1) + substr($hex, 15, 1) + substr($hex, 16, 1) + substr($hex, 17, 1);
my $ch2sul = substr(sprintf("%02d", $ch2sum), 1, 1);
if (substr($hex, 9, 1) == $ch1sul) {
my $ch1z = "";
if (substr($hex, 4, 1) == "5") {
$ch1z ="-";
}
$ch1temp = $ch1z . substr($hex, 5, 2) . "." . substr($hex, 7, 1);
}
if (substr($hex, 19, 1) == $ch2sul) {
my $ch2z = "";
if (substr($hex, 14, 1) == "5") {
$ch2z ="-";
}
$ch1temp = $ch1z . substr($hex, 5, 2) . "." . substr($hex, 7, 1);
$ch2temp = $ch2z . substr($hex, 15, 2) . "." . substr($hex, 17, 1);
}
}
print "ch1.value $ch1temp\n";