4 use Device::SerialPort;
5 use Data::Dump qw(dump);
6 use Time::HiRes qw(time);
10 my $path = shift @ARGV || '/dev/serial/by-path/platform-20980000.usb-usb-0:1.3.1:1.0-port0';
16 my $s = new Device::SerialPort( $path ) || die $!;
21 $s->handshake('none');
22 $s->read_char_time(2);
23 $s->read_const_time(3);
33 my $cmd = "mosquitto_pub -h rpi2 -t '$t' -m '$m'";
34 #warn "# _mqtt_pub [$t] = [$m]\n";
40 my ($len, $string) = $s->read($read_len);
41 goto connect_again if ! defined $len;
45 my $hex = unpack('H*',$string);
48 my $temp = `curl localhost:3000/temp.txt`;
52 #printf "%s %2d %s\n", time(), $len, $hex;
53 printf "%8.4f %6.2f %2d %s | %s\n", $ts, $ts - $t, $len, $hex, $temp;
56 if ( $hex =~ m/^.+aa fc 39 aa (.+)/ ) {
57 my @l = split(/\s+/,$1);
63 hex( $l[14] ), # * 300,
64 hex( $l[15] ), # * 400,
68 _mqtt_pub "stat/boiler/" . chr(ord('a') + $_) => $d[$_] foreach 0 .. $#d;
71 my @v = split(/\s+/, $temp, 3);
72 my @n = qw( DS18B20/temperature DHT22/temperature DHT22/humidity );
74 _mqtt_pub "stat/boiler/" . shift(@n) => $_;