added mqtt publishing
authorDobrica Pavlinusic <dpavlin@rot13.org>
Mon, 20 Mar 2017 09:23:10 +0000 (10:23 +0100)
committerDobrica Pavlinusic <dpavlin@rot13.org>
Mon, 20 Mar 2017 09:23:10 +0000 (10:23 +0100)
serial.pl

index 4f60390..3c091ea 100755 (executable)
--- 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;
+               }
+
        }
 }