X-Git-Url: http://git.rot13.org/?p=air-quality;a=blobdiff_plain;f=pms3003.pl;h=7c0205e7a3216d09b0d9a759927bc735b655fa38;hp=2d52db88c23f1e1eb1a7dcd114162eb69cef3526;hb=600961033ca0ef7e42ebd2f93c894edcea3c3206;hpb=4c4ac1b3c73200728f1f56193fe9905aa391abd4 diff --git a/pms3003.pl b/pms3003.pl index 2d52db8..7c0205e 100755 --- a/pms3003.pl +++ b/pms3003.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'; @@ -36,6 +37,8 @@ pm10_r while (1) { my ($len, $string) = $s->read(24); + my $t = int( Time::HiRes::time() * 1_000_000_000 ); + die $! if ! defined($len); if ( $len > 0 ) { my @v = unpack('n*', $string); warn "# $len ",dump($string), dump( @v ), $/ if $debug; @@ -56,6 +59,7 @@ while (1) { $influx .= "$names[$i]=$v[$i],"; }; $influx =~ s/,$//; + $influx .= " $t"; print "$influx\n"; system "curl --silent -XPOST '$influx_url' --data-binary '$influx'" }