X-Git-Url: http://git.rot13.org/?a=blobdiff_plain;f=serial.pl;fp=serial.pl;h=2ba83e8872fc9351a9eed00a42a1a47867890e79;hb=f668ba4121cfeee0269e78bdbb8a418bbf2e7994;hp=c08a73e1397514479fd3ef093abe0f6e74ab33a0;hpb=cdac63d722919de63ac5cd83dd4a48aea791c33c;p=vaillant-thermostat diff --git a/serial.pl b/serial.pl index c08a73e..2ba83e8 100755 --- a/serial.pl +++ b/serial.pl @@ -4,6 +4,7 @@ use strict; use Device::SerialPort; use Data::Dump qw(dump); use Time::HiRes qw(time); +use LWP::UserAgent; my $read_len = 255; @@ -11,6 +12,8 @@ my $path = shift @ARGV || '/dev/serial/by-path/platform-20980000.usb-usb-0:1.2:1 $|=1; +my $ua = LWP::UserAgent->new; + connect_again: my $s = new Device::SerialPort( $path ) || die $!; @@ -75,6 +78,30 @@ while (1) { _mqtt_pub "stat/boiler/" . shift(@n) => $_; } + my $t = int( $ts * 1_000_000_000 ); + my @a = split(/ /, $hex); + if ( $#a == 66 ) { + my $measurement = "boiler " . join(',', + "o19=".hex( $a[19] ), + "o25=".hex( $a[35] . $a[36] ), + "o30=".hex( $a[38] . $a[39] ), + "o41=".hex( $a[41] ), + "o47=".hex( $a[47] ), + "o49=".hex( $a[49] ), + "o50=".hex( $a[50] ), + "o51=".hex( $a[51] ), + "o53=".hex( $a[53] ), + "ds18b20_temp=$v[0]", "dht22_temp=$v[1]", "dht22_hum=$v[2]" + ); + my $response = $ua->post( "http://10.60.0.92:8086/write?db=rot13", Content => $measurement ); + chomp(my $content = $response->content()); + if ($response->is_success()) { + #warn "OK $content\n"; + } else { + warn "ERROR $content\n"; + die $response->status_line; + } + } } }