X-Git-Url: http://git.rot13.org/?p=air-quality;a=blobdiff_plain;f=zph02.pl;h=d0797d9db6331be3a5d5117112c60331dc8394e6;hp=42336609b724bc830e428b33c8d60234d6403d33;hb=55508ede1cc74bae5129acae12e214de0bd0c4f1;hpb=a18f9c9581e10c5c0f5b27bb6a8f9da2079093d6 diff --git a/zph02.pl b/zph02.pl index 4233660..d0797d9 100755 --- a/zph02.pl +++ b/zph02.pl @@ -3,6 +3,7 @@ use warnings; use strict; # sudo apt install libdevice-serialport-perl libdata-dump-perl use Device::SerialPort; +use Time::HiRes; use Data::Dump qw(dump); my $port = shift @ARGV || '/dev/ttyUSB0'; @@ -22,6 +23,8 @@ $s->read_const_time(10); while (1) { my ($len, $string) = $s->read(9); + my $t = int( Time::HiRes::time() * 1_000_000_000 ); + die $! if ! defined($len); if ( $len > 0 ) { my @v = unpack('C*', $string); #warn "# $len ",dump($string), dump( @v ), $/; @@ -37,7 +40,7 @@ while (1) { my $checksum = $v[8]; my $pcnt = $v[3] + ( $v[4] / 100 ); if ( $v[0] == 0xff && $sum == $checksum ) { - my $influx = "zph02,dc=trnjanska pm25_pcnt=$pcnt"; + my $influx = "zph02,dc=trnjanska pm25_pcnt=$pcnt $t"; print "$influx\n"; system "curl --silent -XPOST '$influx_url' --data-binary '$influx'" }