X-Git-Url: http://git.rot13.org/?p=air-quality;a=blobdiff_plain;f=mh-z19b.pl;h=968f315f28eb0d5135169a88af3d01035a92b249;hp=c925661d169c5646ddc90c60ef6ab215d3c412d5;hb=2889cdfcabc2487e9bf2fc1e193f7e14145ddc42;hpb=395e7f06a7d973f3dd808ca87676dde1a3f5246a diff --git a/mh-z19b.pl b/mh-z19b.pl index c925661..968f315 100755 --- a/mh-z19b.pl +++ b/mh-z19b.pl @@ -6,9 +6,8 @@ use Device::SerialPort; use Time::HiRes; use Data::Dump qw(dump); -my $port = shift @ARGV || '/dev/ttyUSB0'; -my $influx_url = shift @ARGV || 'http://10.13.37.229:8186/write?db=telegraf'; -$influx_url = 'http://10.13.37.92:8086/write?db=rot13'; +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 $s = new Device::SerialPort( $port ) || die $!; $s->baudrate(9600); @@ -16,7 +15,7 @@ $s->databits(8); $s->parity('none'); $s->stopbits(1); $s->handshake('none'); -$s->read_char_time(0); +$s->read_char_time(1); $s->read_const_time(10); $s->debug(1); @@ -29,7 +28,9 @@ while (1) { die $! if ! defined($len); if ( $len > 0 ) { my @v = unpack('C*', $string); - #warn "# $len ",dump($string), dump( @v ), $/; + if ( $#v < 8 ) { + die "# $len ",dump($string), dump( @v ), $/; + } my $sum = 0; foreach my $i ( 1 .. $#v - 1 ) { @@ -44,6 +45,8 @@ while (1) { my $influx = "mh-z19b,dc=trnjanska co2=$co2 $t"; print "$influx\n"; system "curl --silent -XPOST '$influx_url' --data-binary '$influx'" + } else { + die "checksum error"; } sleep 1; $s->write("\xFF\x01\x86\x00\x00\x00\x00\x00\x79");