X-Git-Url: http://git.rot13.org/?p=air-quality;a=blobdiff_plain;f=pms3003.pl;h=72771f5a45153a9a8626531ef229d71bbd6ee8b4;hp=2d52db88c23f1e1eb1a7dcd114162eb69cef3526;hb=226479f66d7f2238e37841ec70343aa414d202c5;hpb=4c4ac1b3c73200728f1f56193fe9905aa391abd4 diff --git a/pms3003.pl b/pms3003.pl index 2d52db8..72771f5 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,6 +58,7 @@ while (1) { $influx .= "$names[$i]=$v[$i],"; }; $influx =~ s/,$//; + $influx .= " $t"; print "$influx\n"; system "curl --silent -XPOST '$influx_url' --data-binary '$influx'" }