X-Git-Url: http://git.rot13.org/?p=air-quality;a=blobdiff_plain;f=iio2mqtt.pl;h=e9ba122aff4f68fcd595780c89a151c4dac4bcf5;hp=1879ce117e32dcc2d2189a052a281c4d8df8184a;hb=c812ac6be426a9e1f43dfa15239dad8057edf0ca;hpb=0d538f686d23b6779e07a4efa9e0faebc636c5ed diff --git a/iio2mqtt.pl b/iio2mqtt.pl index 1879ce1..e9ba122 100755 --- a/iio2mqtt.pl +++ b/iio2mqtt.pl @@ -21,10 +21,17 @@ while(1) { my $device; my $name; - my @influx; + my $influx = ''; + foreach ( split(/\n/, $iio) ) { if ( m/iio:device\d+:\s+(\S+)/ ) { $device = $1; + + if ( $influx =~ m/,$/ ) { + $influx =~ s/,$/ $t_influx\n/; + } + $influx .= "iio,dc=trnjanska,host=$hostname,device=$device "; + } elsif ( m/(\S+):\s+\(input\)/ ) { $name = $1; } elsif ( m/attr\s+0:\s+input\svalue: (\d+[\.\d]+)/ ) { @@ -36,13 +43,15 @@ while(1) { #print "$topic $val\n"; system "mosquitto_pub -h rpi2 -t $topic -m $val"; - push @influx, "${device}_${name}=$val"; + $influx .= "$name=$val,"; } else { #warn "# $_\n"; } } - my $influx = "iio,dc=trnjanska,host=$hostname " . join(",", @influx) . " $t_influx"; + + $influx =~ s/,$/ $t_influx/; system "curl --silent -XPOST '$influx_url' --data-binary '$influx'"; + warn "$influx\n"; sleep Time::HiRes::time + 1 - $t; }