projects
/
air-quality
/ blobdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
|
commitdiff
|
tree
raw
|
inline
| side by side
handle slower iio_info and skip sleep
[air-quality]
/
iio2mqtt.pl
diff --git
a/iio2mqtt.pl
b/iio2mqtt.pl
index
e9ba122
..
40c4983
100755
(executable)
--- a/
iio2mqtt.pl
+++ b/
iio2mqtt.pl
@@
-8,6
+8,8
@@
use Time::HiRes;
my $influx_url = shift @ARGV || 'http://10.13.37.92:8086/write?consistency=any&db=rot13';
my $influx_url = shift @ARGV || 'http://10.13.37.92:8086/write?consistency=any&db=rot13';
+my $delay = $ENV{DELAY} || 1;
+
my $hostname = `hostname -s`;
chomp($hostname);
my $hostname = `hostname -s`;
chomp($hostname);
@@
-29,6
+31,8
@@
while(1) {
if ( $influx =~ m/,$/ ) {
$influx =~ s/,$/ $t_influx\n/;
if ( $influx =~ m/,$/ ) {
$influx =~ s/,$/ $t_influx\n/;
+ } elsif ( $influx =~ m/ $/ ) { # only device
+ $influx =~ s/\S+\s$//;
}
$influx .= "iio,dc=trnjanska,host=$hostname,device=$device ";
}
$influx .= "iio,dc=trnjanska,host=$hostname,device=$device ";
@@
-53,5
+57,8
@@
while(1) {
system "curl --silent -XPOST '$influx_url' --data-binary '$influx'";
warn "$influx\n";
system "curl --silent -XPOST '$influx_url' --data-binary '$influx'";
warn "$influx\n";
- sleep Time::HiRes::time + 1 - $t;
+ my $dt = Time::HiRes::time + $delay - $t - 100;
+ if ( $dt > 0 ) {
+ sleep $dt;
+ }
}
}