7 # sudo apt install libiio-utils mosquitto-clients
9 my $influx_url = shift @ARGV || 'http://10.13.37.92:8086/write?consistency=any&db=rot13';
11 my $hostname = `hostname -s`;
16 my $t = Time::HiRes::time;
17 my $t_influx = int( $t * 1_000_000_000 );
24 foreach ( split(/\n/, $iio) ) {
25 if ( m/iio:device\d+:\s+(\S+)/ ) {
27 } elsif ( m/(\S+):\s+\(input\)/ ) {
29 } elsif ( m/attr\s+0:\s+input\svalue: (\d+[\.\d]+)/ ) {
31 if ( $val !~ m/\d+\.\d+/ ) {
34 my $topic = "iio/$hostname/$device/$name";
35 #print "$topic $val\n";
36 system "mosquitto_pub -h rpi2 -t $topic -m $val";
38 my $influx = "iio,dc=trnjanska,host=$hostname,device=$device $name=$val $t_influx";
39 system "curl --silent -XPOST '$influx_url' --data-binary '$influx'";
45 sleep Time::HiRes::time + 1 - $t;