X-Git-Url: http://git.rot13.org/?p=air-quality;a=blobdiff_plain;f=pms3003.pl;h=f1d458ab6914a10597fa61f883785e965495059a;hp=2d52db88c23f1e1eb1a7dcd114162eb69cef3526;hb=32bcafc453e010a0115903d346d4d3d6acdc33a0;hpb=4c4ac1b3c73200728f1f56193fe9905aa391abd4 diff --git a/pms3003.pl b/pms3003.pl index 2d52db8..f1d458a 100755 --- a/pms3003.pl +++ b/pms3003.pl @@ -3,11 +3,11 @@ 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'; -my $influx_url = shift @ARGV || 'http://10.13.37.229:8186/write?db=telegraf'; -$influx_url = 'http://10.13.37.92:8086/write?db=rot13'; +my $port = shift @ARGV || '/dev/serial/by-path/platform-3f980000.usb-usb-0:1.3:1.0-port0'; +my $influx_url = shift @ARGV || 'http://10.13.37.92:8086/write?consistency=any&db=rot13'; my $debug = $ENV{DEBUG} || 0; @@ -36,6 +36,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,8 +58,9 @@ while (1) { $influx .= "$names[$i]=$v[$i],"; }; $influx =~ s/,$//; + $influx .= " $t"; print "$influx\n"; - system "curl --silent -XPOST '$influx_url' --data-binary '$influx'" + system "curl --max-time 2 --silent -XPOST '$influx_url' --data-binary '$influx'" } }