X-Git-Url: http://git.rot13.org/?a=blobdiff_plain;f=serial.pl;h=c08a73e1397514479fd3ef093abe0f6e74ab33a0;hb=a5908cb30d5fdef3320f80879fa5277fd37097a1;hp=06a1d15b96235d41f5d987468c5ed1b93b458937;hpb=95f8429ee183074531fb3f33c6fd69a141439770;p=vaillant-thermostat diff --git a/serial.pl b/serial.pl index 06a1d15..c08a73e 100755 --- a/serial.pl +++ b/serial.pl @@ -7,7 +7,7 @@ use Time::HiRes qw(time); my $read_len = 255; -my $path = shift @ARGV || '/dev/serial/by-path/platform-20980000.usb-usb-0:1.3.1:1.0-port0'; +my $path = shift @ARGV || '/dev/serial/by-path/platform-20980000.usb-usb-0:1.2:1.0-port0'; $|=1; @@ -30,9 +30,9 @@ my $sym; sub _mqtt_pub { my ( $t, $m ) = @_; - my $cmd = "mosquitto_pub -h rpi2 -t 'stat/rpi/$t' -m '$m'"; + my $cmd = "mosquitto_pub -h rpi2 -t '$t' -m '$m'"; #warn "# _mqtt_pub [$t] = [$m]\n"; - warn "## $cmd"; + #warn "## $cmd"; system $cmd; } @@ -45,8 +45,9 @@ while (1) { my $hex = unpack('H*',$string); $hex =~ s/(..)/$1 /g; - my $temp = `curl localhost:3000/temp.txt`; + my $temp = `curl --silent localhost:3000/temp.txt`; $temp =~ s/\s+/ /gs; + $temp =~ s/^\s+//; #printf "%s %2d %s\n", time(), $len, $hex; printf "%8.4f %6.2f %2d %s | %s\n", $ts, $ts - $t, $len, $hex, $temp; @@ -67,6 +68,13 @@ while (1) { _mqtt_pub "stat/boiler/" . chr(ord('a') + $_) => $d[$_] foreach 0 .. $#d; } + my @v = split(/\s+/, $temp, 4); + my @n = qw( DS18B20/temperature DHT22/temperature DHT22/humidity DHT22/errors ); + @n = qw( DS18B20/temperature DHT22/temperature DHT22/humidity DHT22/errors ) if $#v == 1; # no DS18B20 + foreach (@v) { + _mqtt_pub "stat/boiler/" . shift(@n) => $_; + } + } }