turn debug on with: touch /dev/shm/air-debug
[air-quality] / mh-z19b.pl
index 968f315..927951b 100755 (executable)
@@ -7,7 +7,7 @@ use Time::HiRes;
 use Data::Dump qw(dump);
 
 my $port = shift @ARGV || '/dev/serial/by-path/platform-3f980000.usb-usb-0:1.5:1.2';
-my $influx_url = shift @ARGV || 'http://10.13.37.92:8086/write?consistency=any&db=rot13';
+my $influx_url = shift @ARGV || 'http://10.60.0.92:8086/write?consistency=any&db=rot13';
 
 my $s = new Device::SerialPort( $port ) || die $!;
 $s->baudrate(9600);
@@ -43,8 +43,9 @@ while (1) {
                my $co2 = $v[2] * 255 + $v[3];
                if ( $v[0] == 0xff && $sum == $checksum ) {
                        my $influx = "mh-z19b,dc=trnjanska co2=$co2 $t";
-                       print "$influx\n";
-                       system "curl --silent -XPOST '$influx_url' --data-binary '$influx'"
+                       print "$influx\n" if -e '/dev/shm/air-debug';
+                       system "curl --max-time 2 --silent -XPOST '$influx_url' --data-binary '$influx'";
+                       system "mosquitto_pub -h rpi2 -t 'air/mh-z19b/co2' -m $co2";
                } else {
                        die "checksum error";
                }