4 use Device::SerialPort;
5 use Data::Dump qw(dump);
6 use Time::HiRes qw(time);
11 my $path = shift @ARGV || '/dev/serial/by-path/platform-20980000.usb-usb-0:1.2:1.0-port0';
15 my $ua = LWP::UserAgent->new;
19 my $s = new Device::SerialPort( $path ) || die $!;
24 $s->handshake('none');
25 $s->read_char_time(2);
26 $s->read_const_time(3);
36 my $cmd = "mosquitto_pub -h rpi2 -t '$t' -m '$m'";
37 #warn "# _mqtt_pub [$t] = [$m]\n";
43 my ($len, $string) = $s->read($read_len);
44 goto connect_again if ! defined $len;
48 my $hex = unpack('H*',$string);
51 my $temp = `curl --silent localhost:3000/temp.txt`;
55 #printf "%s %2d %s\n", time(), $len, $hex;
56 printf "%8.4f %6.2f %2d %s | %s\n", $ts, $ts - $t, $len, $hex, $temp;
59 if ( $hex =~ m/^.+aa fc 39 aa (.+)/ ) {
60 my @l = split(/\s+/,$1);
66 hex( $l[14] ), # * 300,
67 hex( $l[15] ), # * 400,
71 _mqtt_pub "stat/boiler/" . chr(ord('a') + $_) => $d[$_] foreach 0 .. $#d;
74 my @v = split(/\s+/, $temp, 4);
75 my @n = qw( DS18B20/temperature DHT22/temperature DHT22/humidity DHT22/errors );
76 @n = qw( DS18B20/temperature DHT22/temperature DHT22/humidity DHT22/errors ) if $#v == 1; # no DS18B20
78 _mqtt_pub "stat/boiler/" . shift(@n) => $_;
81 my $t = int( $ts * 1_000_000_000 );
82 my @a = split(/ /, $hex);
84 my $measurement = "boiler " . join(',',
86 "o25=".hex( $a[35] . $a[36] ),
87 "o30=".hex( $a[38] . $a[39] ),
94 "ds18b20_temp=$v[0]", "dht22_temp=$v[1]", "dht22_hum=$v[2]"
96 my $response = $ua->post( "http://10.60.0.92:8086/write?db=rot13", Content => $measurement );
97 chomp(my $content = $response->content());
98 if ($response->is_success()) {
99 #warn "OK $content\n";
101 warn "ERROR $content\n";
102 die $response->status_line;