added influxdb export and temperature extraction
authorDobrica Pavlinusic <dpavlin@rot13.org>
Thu, 2 Mar 2017 13:23:41 +0000 (14:23 +0100)
committerDobrica Pavlinusic <dpavlin@rot13.org>
Thu, 2 Mar 2017 13:23:41 +0000 (14:23 +0100)
parse.pl

index 6f6911a..593f1ab 100755 (executable)
--- a/parse.pl
+++ b/parse.pl
@@ -2,22 +2,37 @@
 use warnings;
 use strict;
 
+my $curl;
+my $influx = $ENV{INFLUX}; # || 'http://127.0.0.1:8086/write?db=boiler';
+
+my $temp = '';
+
 while(<>) {
        chomp;
+       if ( s/\s+\|\s+(\d+\.\d\d).+$// ) {
+               $temp = $1;
+       }
+#$temp = ( $temp - 20 ) * 500 + 500;
        if ( m/^([0-9\.]+) .+aa fc 39 aa (.+)/ ) {
+               my $t = $1;
                #warn "# $1 $2\n";
                my @l = split(/\s/,$2);
                my @d = (
-                       $1,
+                       $t,
                        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[14] ), # * 300,
+                       hex( $l[15] ), # * 400,
                        hex( $l[18] ),
                );
-               print join(',', @d),$/;
+               if ( $influx ) {
+                       open($curl, '|-', qq( tee /dev/shm/parse.curl | curl -XPOST $influx --data-binary \@- )) unless $curl;
+                       print $curl "thermostat ",join(',', map { chr( ord('a') + $_ ) . '=' . $d[$_] . 'i' } 1 .. $#d ), ($temp ? ",temp=$temp" : ""), " ", int($t * 1_000_000_000), "\n";
+               } else {
+                       print join(',', @d,$temp),$/;
+               }
        } else {
                warn "# $_\n";
        }