From: Dobrica Pavlinusic Date: Sun, 21 Feb 2021 09:18:15 +0000 (+0000) Subject: send data with timestamp to influx X-Git-Url: http://git.rot13.org/?p=air-quality;a=commitdiff_plain;h=3891fbda4dc76328c3c53d890609cb1b31070359;hp=c9bfa79f7249f0963798648a565243e4a3e63161 send data with timestamp to influx This will hide network latency from readings --- diff --git a/iio2mqtt.pl b/iio2mqtt.pl index a9dce9f..4081540 100755 --- a/iio2mqtt.pl +++ b/iio2mqtt.pl @@ -6,12 +6,15 @@ use Time::HiRes; # sudo apt install libiio-utils mosquitto-clients +my $influx_url = shift @ARGV || 'http://10.13.37.92:8086/write?consistency=any&db=rot13'; + my $hostname = `hostname -s`; chomp($hostname); while(1) { my $t = Time::HiRes::time; + my $t_influx = int( $t * 1_000_000_000 ); my $iio = `iio_info`; @@ -31,6 +34,9 @@ while(1) { my $topic = "iio/$hostname/$device/$name"; #print "$topic $val\n"; system "mosquitto_pub -h rpi2 -t $topic -m $val"; + + my $influx = "iio,dc=trnjanska,host=$hostname,device=$device $name=$val $t_influx"; + system "curl --silent -XPOST '$influx_url' --data-binary '$influx'"; } else { #warn "# $_\n"; }