From: Dobrica Pavlinusic Date: Mon, 20 Mar 2017 09:23:10 +0000 (+0100) Subject: added mqtt publishing X-Git-Url: http://git.rot13.org/?p=vaillant-thermostat;a=commitdiff_plain;h=7e9e35556b30266de3c40b941490cb150cb4ace6;hp=e49e2a6d2d52684e6e42dea66e0d3bd3015703ca added mqtt publishing --- diff --git a/serial.pl b/serial.pl index 4f60390..3c091ea 100755 --- a/serial.pl +++ b/serial.pl @@ -25,7 +25,14 @@ $s->read_const_time(3); my $t = time(); my $sym; -my $chr = 'A'; + +sub _mqtt_pub { + my ( $t, $m ) = @_; + my $cmd = "mosquitto_pub -h rpi2 -t 'stat/rpi/$t' -m '$m'"; + #warn "# _mqtt_pub [$t] = [$m]\n"; + warn "## $cmd"; + system $cmd; +} while (1) { my ($len, $string) = $s->read($read_len); @@ -48,6 +55,22 @@ while (1) { #printf "%s %2d %s\n", time(), $len, $hex; printf "%8.4f %6.2f %2d %s | %s\n", $ts, $ts - $t, $len, $hex, $temp; $t = time(); + + if ( $hex =~ m/^.+aa fc 39 aa (.+)/ ) { + my @l = split(/\s+/,$1); + my @d = ( + hex( $l[0] . $l[1] ), + hex( $l[3] . $l[4] ), + hex( $l[6] ), + hex( $l[12] ), + hex( $l[14] ), # * 300, + hex( $l[15] ), # * 400, + hex( $l[18] ), + ); + + _mqtt_pub "stat/boiler/" . chr(ord('a') + $_) => $d[$_] foreach 0 .. $#d; + } + } }