projects
/
air-quality
/ blobdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
|
commitdiff
|
tree
raw
|
inline
| side by side
added --max-time to curl so we fail quickly without network
[air-quality]
/
pms3003.pl
diff --git
a/pms3003.pl
b/pms3003.pl
index
2d52db8
..
f1d458a
100755
(executable)
--- 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 strict;
# sudo apt install libdevice-serialport-perl libdata-dump-perl
use Device::SerialPort;
+use Time::HiRes;
use Data::Dump qw(dump);
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;
my $debug = $ENV{DEBUG} || 0;
@@
-36,6
+36,8
@@
pm10_r
while (1) {
my ($len, $string) = $s->read(24);
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;
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 .= "$names[$i]=$v[$i],";
};
$influx =~ s/,$//;
+ $influx .= " $t";
print "$influx\n";
print "$influx\n";
- system "curl --silent -XPOST '$influx_url' --data-binary '$influx'"
+ system "curl --
max-time 2 --
silent -XPOST '$influx_url' --data-binary '$influx'"
}
}
}
}