From 7e9e35556b30266de3c40b941490cb150cb4ace6 Mon Sep 17 00:00:00 2001 From: Dobrica Pavlinusic Date: Mon, 20 Mar 2017 10:23:10 +0100 Subject: [PATCH] added mqtt publishing --- serial.pl | 25 ++++++++++++++++++++++++- 1 file changed, 24 insertions(+), 1 deletion(-) 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; + } + } } -- 2.20.1