From bc051f377da102bb67c6465b810a07dc7b400e13 Mon Sep 17 00:00:00 2001 From: Dobrica Pavlinusic Date: Sun, 21 Feb 2021 12:20:10 +0000 Subject: [PATCH 01/16] handle slower iio_info and skip sleep --- iio2mqtt.pl | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/iio2mqtt.pl b/iio2mqtt.pl index 14c9430..40c4983 100755 --- a/iio2mqtt.pl +++ b/iio2mqtt.pl @@ -57,5 +57,8 @@ while(1) { system "curl --silent -XPOST '$influx_url' --data-binary '$influx'"; warn "$influx\n"; - sleep Time::HiRes::time + $delay - $t; + my $dt = Time::HiRes::time + $delay - $t - 100; + if ( $dt > 0 ) { + sleep $dt; + } } -- 2.20.1 From a62e5f83f1b7e8830c258771a7601146e115997f Mon Sep 17 00:00:00 2001 From: Dobrica Pavlinusic Date: Sun, 21 Feb 2021 12:36:29 +0000 Subject: [PATCH 02/16] send influx data directly --- iio2mqtt.pl | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/iio2mqtt.pl b/iio2mqtt.pl index 40c4983..855e8ca 100755 --- a/iio2mqtt.pl +++ b/iio2mqtt.pl @@ -6,7 +6,7 @@ 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 $influx_url = shift @ARGV || 'http://10.60.0.92:8086/write?consistency=any&db=rot13'; my $delay = $ENV{DELAY} || 1; -- 2.20.1 From d49e42f2b00fdc27eb5244f8add6e271bdd04141 Mon Sep 17 00:00:00 2001 From: Dobrica Pavlinusic Date: Sun, 21 Feb 2021 12:38:51 +0000 Subject: [PATCH 03/16] fix small offset to trigger every DELAY --- iio2mqtt.pl | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/iio2mqtt.pl b/iio2mqtt.pl index 855e8ca..a469024 100755 --- a/iio2mqtt.pl +++ b/iio2mqtt.pl @@ -57,7 +57,7 @@ while(1) { system "curl --silent -XPOST '$influx_url' --data-binary '$influx'"; warn "$influx\n"; - my $dt = Time::HiRes::time + $delay - $t - 100; + my $dt = Time::HiRes::time + $delay - $t - 0.01; if ( $dt > 0 ) { sleep $dt; } -- 2.20.1 From 32bcafc453e010a0115903d346d4d3d6acdc33a0 Mon Sep 17 00:00:00 2001 From: Dobrica Pavlinusic Date: Mon, 8 Mar 2021 16:52:00 +0100 Subject: [PATCH 04/16] added --max-time to curl so we fail quickly without network --- mh-z19b.pl | 2 +- pms3003.pl | 2 +- zph02.pl | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/mh-z19b.pl b/mh-z19b.pl index 1d7b894..8307838 100755 --- a/mh-z19b.pl +++ b/mh-z19b.pl @@ -44,7 +44,7 @@ while (1) { 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'"; + 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"; diff --git a/pms3003.pl b/pms3003.pl index 72771f5..f1d458a 100755 --- a/pms3003.pl +++ b/pms3003.pl @@ -60,7 +60,7 @@ while (1) { $influx =~ s/,$//; $influx .= " $t"; print "$influx\n"; - system "curl --silent -XPOST '$influx_url' --data-binary '$influx'" + system "curl --max-time 2 --silent -XPOST '$influx_url' --data-binary '$influx'" } } diff --git a/zph02.pl b/zph02.pl index 44d35ef..8b7018a 100755 --- a/zph02.pl +++ b/zph02.pl @@ -46,7 +46,7 @@ while (1) { if ( $v[0] == 0xff && $sum == $checksum ) { my $influx = "zph02,dc=trnjanska pm25_pcnt=$pcnt $t"; print "$influx\n"; - system "curl --silent -XPOST '$influx_url' --data-binary '$influx'"; + system "curl --max-time 2 --silent -XPOST '$influx_url' --data-binary '$influx'"; system "mosquitto_pub -h rpi2 -t 'air/zph02/pm25' -m $pcnt"; } } -- 2.20.1 From 9c27794df65d335b028e0feb2d7783f7ec8a6014 Mon Sep 17 00:00:00 2001 From: Dobrica Pavlinusic Date: Fri, 21 May 2021 16:44:36 +0200 Subject: [PATCH 05/16] update to local wireguard ip --- mh-z19b.pl | 2 +- pms3003.pl | 2 +- zph02.pl | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/mh-z19b.pl b/mh-z19b.pl index 8307838..9076414 100755 --- a/mh-z19b.pl +++ b/mh-z19b.pl @@ -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); diff --git a/pms3003.pl b/pms3003.pl index f1d458a..c1708f6 100755 --- a/pms3003.pl +++ b/pms3003.pl @@ -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.3:1.0-port0'; -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 $debug = $ENV{DEBUG} || 0; diff --git a/zph02.pl b/zph02.pl index 8b7018a..0a01d36 100755 --- a/zph02.pl +++ b/zph02.pl @@ -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.0'; -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); -- 2.20.1 From 59b28a41e509a3d933d3dac493ad78e60561e1d9 Mon Sep 17 00:00:00 2001 From: Dobrica Pavlinusic Date: Fri, 21 May 2021 17:11:30 +0200 Subject: [PATCH 06/16] turn debug on with: touch /dev/shm/air-debug --- dsm501.pl | 4 ++-- mh-z19b.pl | 2 +- pms3003.pl | 2 +- zph02.pl | 2 +- 4 files changed, 5 insertions(+), 5 deletions(-) diff --git a/dsm501.pl b/dsm501.pl index a821aaf..33277e5 100755 --- a/dsm501.pl +++ b/dsm501.pl @@ -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.3:1.0-port0'; -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 $measurement = $ENV{MEASUREMENT} || 'dsm501'; my $s = new Device::SerialPort( $port ) || die $!; @@ -31,7 +31,7 @@ while (1) { $string =~ s/[\r\n]+$//; $string =~ s/\s/,/g; my $influx = "$measurement,dc=trnjanska $string $t"; - print "$influx\n"; + print "$influx\n" if -e '/dev/shm/air-debug'; system "curl --silent -XPOST '$influx_url' --data-binary '$influx'" } else { warn "SKIP: $string\n"; diff --git a/mh-z19b.pl b/mh-z19b.pl index 9076414..927951b 100755 --- a/mh-z19b.pl +++ b/mh-z19b.pl @@ -43,7 +43,7 @@ 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"; + 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 { diff --git a/pms3003.pl b/pms3003.pl index c1708f6..cb68af2 100755 --- a/pms3003.pl +++ b/pms3003.pl @@ -59,7 +59,7 @@ while (1) { }; $influx =~ s/,$//; $influx .= " $t"; - print "$influx\n"; + print "$influx\n" if -e '/dev/shm/air-debug'; system "curl --max-time 2 --silent -XPOST '$influx_url' --data-binary '$influx'" } } diff --git a/zph02.pl b/zph02.pl index 0a01d36..00d8c2d 100755 --- a/zph02.pl +++ b/zph02.pl @@ -45,7 +45,7 @@ while (1) { my $pcnt = $v[3] + ( $v[4] / 100 ); if ( $v[0] == 0xff && $sum == $checksum ) { my $influx = "zph02,dc=trnjanska pm25_pcnt=$pcnt $t"; - print "$influx\n"; + 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/zph02/pm25' -m $pcnt"; } -- 2.20.1 From a1a1be98b3279adce682f3508bcba6a0dddea715 Mon Sep 17 00:00:00 2001 From: Dobrica Pavlinusic Date: Sat, 6 Nov 2021 12:16:07 +0100 Subject: [PATCH 07/16] RestartSec --- system/air-mq7.service | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/system/air-mq7.service b/system/air-mq7.service index fb20c10..2175f9c 100644 --- a/system/air-mq7.service +++ b/system/air-mq7.service @@ -5,6 +5,7 @@ Description=Air User=pi ExecStart=/home/pi/air-quality/mq7.sh Restart=on-failure +RestartSec=2s [Install] -WantedBy=multi-user.target +WantedBy=network-online.target -- 2.20.1 From 697e0d92e26053ced2fcf5fb6651f6432da77cf2 Mon Sep 17 00:00:00 2001 From: Dobrica Pavlinusic Date: Sat, 6 Nov 2021 12:16:35 +0100 Subject: [PATCH 08/16] pms3003 service --- system/air-pms3003.service | 11 +++++++++++ 1 file changed, 11 insertions(+) create mode 100644 system/air-pms3003.service diff --git a/system/air-pms3003.service b/system/air-pms3003.service new file mode 100644 index 0000000..a26ce98 --- /dev/null +++ b/system/air-pms3003.service @@ -0,0 +1,11 @@ +[Unit] +Description=Air + +[Service] +User=pi +ExecStart=/home/pi/air-quality/pms3003.pl +Restart=on-failure +RestartSec=2s + +[Install] +WantedBy=network-online.target -- 2.20.1 From 3f56683394d6ea2a0bb02a5f885ba2877c8de9f1 Mon Sep 17 00:00:00 2001 From: Dobrica Pavlinusic Date: Sun, 22 Jan 2023 11:05:05 +0100 Subject: [PATCH 09/16] collect Xiomi Mijia values and send them to influx --- ble-mijia.sh | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) create mode 100755 ble-mijia.sh diff --git a/ble-mijia.sh b/ble-mijia.sh new file mode 100755 index 0000000..078c4db --- /dev/null +++ b/ble-mijia.sh @@ -0,0 +1,20 @@ +#!/bin/bash -e +mac=A4:C1:38:D8:3F:9C +test ! -z "$1" && mac=$1 + + +gatttool -b $mac --char-write-req --handle='0x0038' --value="0100" --listen | tee /dev/stderr | grep --line-buffered value: | while read bt ; do + +#echo "XXX[$bt]" + +temphexa=$(echo $bt | awk -F ' ' '{print $7$6}'| tr [:lower:] [:upper:] ) +humhexa=$(echo $bt | awk -F ' ' '{print $8}'| tr [:lower:] [:upper:]) +temperature100=$(echo "ibase=16; $temphexa" | bc) +humidity=$(echo "ibase=16; $humhexa" | bc) +temperature=$(echo "scale=2;$temperature100/100"|bc) + +echo $(date +%Y-%m-%d\ %H:%M:%S) $temperature $humidity + +curl --silent -XPOST 'http://10.60.0.92:8086/write?consistency=any&db=rot13' --data-binary "mijia,dc=trnjanska,mac=$mac temperature=$temperature,humidity=$humidity" + +done # gattool -- 2.20.1 From 079bff1f15bacd8774031c4413b3121f48e5470c Mon Sep 17 00:00:00 2001 From: Dobrica Pavlinusic Date: Sun, 22 Jan 2023 17:13:04 +0100 Subject: [PATCH 10/16] single awk for conversion, send all data to influx --- ble-mijia.sh | 10 +++------- 1 file changed, 3 insertions(+), 7 deletions(-) diff --git a/ble-mijia.sh b/ble-mijia.sh index 078c4db..e97d920 100755 --- a/ble-mijia.sh +++ b/ble-mijia.sh @@ -7,14 +7,10 @@ gatttool -b $mac --char-write-req --handle='0x0038' --value="0100" --listen | te #echo "XXX[$bt]" -temphexa=$(echo $bt | awk -F ' ' '{print $7$6}'| tr [:lower:] [:upper:] ) -humhexa=$(echo $bt | awk -F ' ' '{print $8}'| tr [:lower:] [:upper:]) -temperature100=$(echo "ibase=16; $temphexa" | bc) -humidity=$(echo "ibase=16; $humhexa" | bc) -temperature=$(echo "scale=2;$temperature100/100"|bc) +v=$( echo $bt | awk '{ print "temperature=" strtonum("0x"$7$6) / 100, "humidity=" strtonum("0x"$8), "a=" strtonum("0x"$9), "b="strtonum("0x"$10) }' | sed 's/ /,/g' ) -echo $(date +%Y-%m-%d\ %H:%M:%S) $temperature $humidity +echo $(date +%Y-%m-%d\ %H:%M:%S) $mac $v -curl --silent -XPOST 'http://10.60.0.92:8086/write?consistency=any&db=rot13' --data-binary "mijia,dc=trnjanska,mac=$mac temperature=$temperature,humidity=$humidity" +curl --silent -XPOST 'http://10.60.0.92:8086/write?consistency=any&db=rot13' --data-binary "mijia,dc=trnjanska,mac=$mac $v" done # gattool -- 2.20.1 From 8dbc08b2949aa2efdbb31d65f6268f250af99ffe Mon Sep 17 00:00:00 2001 From: Dobrica Pavlinusic Date: Mon, 23 Jan 2023 17:10:46 +0100 Subject: [PATCH 11/16] ble-mijia@.service --- system/ble-mijia@.service | 11 +++++++++++ 1 file changed, 11 insertions(+) create mode 100644 system/ble-mijia@.service diff --git a/system/ble-mijia@.service b/system/ble-mijia@.service new file mode 100644 index 0000000..b12201c --- /dev/null +++ b/system/ble-mijia@.service @@ -0,0 +1,11 @@ +[Unit] +Description=Xiomi Mijia %i + +[Service] +User=pi +ExecStart=/home/pi/air-quality/ble-mijia.sh %i +Restart=always +RestartSec=3s + +[Install] +WantedBy=network-online.target -- 2.20.1 From d50681e1da5d929ba38772d7edd6782380106996 Mon Sep 17 00:00:00 2001 From: Dobrica Pavlinusic Date: Mon, 23 Jan 2023 17:10:54 +0100 Subject: [PATCH 12/16] don't emit readings so systemd doesn't have to log it --- ble-mijia.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ble-mijia.sh b/ble-mijia.sh index e97d920..016675b 100755 --- a/ble-mijia.sh +++ b/ble-mijia.sh @@ -9,7 +9,7 @@ gatttool -b $mac --char-write-req --handle='0x0038' --value="0100" --listen | te v=$( echo $bt | awk '{ print "temperature=" strtonum("0x"$7$6) / 100, "humidity=" strtonum("0x"$8), "a=" strtonum("0x"$9), "b="strtonum("0x"$10) }' | sed 's/ /,/g' ) -echo $(date +%Y-%m-%d\ %H:%M:%S) $mac $v +#echo $(date +%Y-%m-%d\ %H:%M:%S) $mac $v curl --silent -XPOST 'http://10.60.0.92:8086/write?consistency=any&db=rot13' --data-binary "mijia,dc=trnjanska,mac=$mac $v" -- 2.20.1 From 018f7c730b6cd7757531681e748431288da59382 Mon Sep 17 00:00:00 2001 From: Dobrica Pavlinusic Date: Fri, 27 Jan 2023 10:13:02 +0100 Subject: [PATCH 13/16] simplify script to use only gattool, awk and curl --- ble-mijia.sh | 17 +++++------------ 1 file changed, 5 insertions(+), 12 deletions(-) diff --git a/ble-mijia.sh b/ble-mijia.sh index 016675b..9659e29 100755 --- a/ble-mijia.sh +++ b/ble-mijia.sh @@ -1,16 +1,9 @@ -#!/bin/bash -e -mac=A4:C1:38:D8:3F:9C +#!/bin/sh -e +mac=A4:C1:38:90:DC:63 test ! -z "$1" && mac=$1 -gatttool -b $mac --char-write-req --handle='0x0038' --value="0100" --listen | tee /dev/stderr | grep --line-buffered value: | while read bt ; do +gatttool -b $mac --char-write-req --handle='0x0038' --value="0100" --listen | \ + awk 'BEGIN { OFS=","; ORS="\n" } /value:/ { print "temperature=" strtonum("0x"$7$6) / 100, "humidity=" strtonum("0x"$8), "a=" strtonum("0x"$9), "b="strtonum("0x"$10) ; fflush() }' | \ + xargs -i curl --silent -XPOST 'http://10.60.0.92:8086/write?consistency=any&db=rot13' --data-binary "mijia,dc=trnjanska,mac=$mac {}" -#echo "XXX[$bt]" - -v=$( echo $bt | awk '{ print "temperature=" strtonum("0x"$7$6) / 100, "humidity=" strtonum("0x"$8), "a=" strtonum("0x"$9), "b="strtonum("0x"$10) }' | sed 's/ /,/g' ) - -#echo $(date +%Y-%m-%d\ %H:%M:%S) $mac $v - -curl --silent -XPOST 'http://10.60.0.92:8086/write?consistency=any&db=rot13' --data-binary "mijia,dc=trnjanska,mac=$mac $v" - -done # gattool -- 2.20.1 From 921f4897fcc86708684b85328496a74b2dc6349f Mon Sep 17 00:00:00 2001 From: Dobrica Pavlinusic Date: Sat, 28 Jan 2023 09:06:15 +0100 Subject: [PATCH 14/16] decode battery voltage --- ble-mijia.sh | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/ble-mijia.sh b/ble-mijia.sh index 9659e29..908d63f 100755 --- a/ble-mijia.sh +++ b/ble-mijia.sh @@ -2,8 +2,11 @@ mac=A4:C1:38:90:DC:63 test ! -z "$1" && mac=$1 +# based on https://ndimension.design.blog/2021/12/16/reading-data-from-xiaomi-mi-temperature-and-humidity-monitor-2-lywsd03mmc/ +# find sensor with: sudo hcitool lescan +# A4:C1:38:D8:3F:9C LYWSD03MMC gatttool -b $mac --char-write-req --handle='0x0038' --value="0100" --listen | \ - awk 'BEGIN { OFS=","; ORS="\n" } /value:/ { print "temperature=" strtonum("0x"$7$6) / 100, "humidity=" strtonum("0x"$8), "a=" strtonum("0x"$9), "b="strtonum("0x"$10) ; fflush() }' | \ + awk 'BEGIN { OFS=","; ORS="\n" } /value:/ { print "temperature=" strtonum("0x"$7$6) / 100, "humidity=" strtonum("0x"$8), "battery=" strtonum("0x"$10$9) / 1000 ; fflush() }' | \ xargs -i curl --silent -XPOST 'http://10.60.0.92:8086/write?consistency=any&db=rot13' --data-binary "mijia,dc=trnjanska,mac=$mac {}" -- 2.20.1 From 80cbace6598e0bfb9a4798cccfb13611049d2e1b Mon Sep 17 00:00:00 2001 From: Dobrica Pavlinusic Date: Sat, 12 Aug 2023 12:38:37 +0200 Subject: [PATCH 15/16] update to local influxdb --- dsm501.pl | 2 +- iio2mqtt.pl | 2 +- mh-z19b.pl | 2 +- pms3003.pl | 2 +- zph02.pl | 2 +- 5 files changed, 5 insertions(+), 5 deletions(-) diff --git a/dsm501.pl b/dsm501.pl index 33277e5..0a237a7 100755 --- a/dsm501.pl +++ b/dsm501.pl @@ -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.3:1.0-port0'; -my $influx_url = shift @ARGV || 'http://10.60.0.92:8086/write?consistency=any&db=rot13'; +my $influx_url = shift @ARGV || 'http://192.168.3.40:8086/write?consistency=any&db=rot13'; my $measurement = $ENV{MEASUREMENT} || 'dsm501'; my $s = new Device::SerialPort( $port ) || die $!; diff --git a/iio2mqtt.pl b/iio2mqtt.pl index a469024..50668f0 100755 --- a/iio2mqtt.pl +++ b/iio2mqtt.pl @@ -6,7 +6,7 @@ use Time::HiRes; # sudo apt install libiio-utils mosquitto-clients -my $influx_url = shift @ARGV || 'http://10.60.0.92:8086/write?consistency=any&db=rot13'; +my $influx_url = shift @ARGV || 'http://192.168.3.40:8086/write?consistency=any&db=rot13'; my $delay = $ENV{DELAY} || 1; diff --git a/mh-z19b.pl b/mh-z19b.pl index 927951b..52e3812 100755 --- a/mh-z19b.pl +++ b/mh-z19b.pl @@ -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.60.0.92:8086/write?consistency=any&db=rot13'; +my $influx_url = shift @ARGV || 'http://192.168.3.40:8086/write?consistency=any&db=rot13'; my $s = new Device::SerialPort( $port ) || die $!; $s->baudrate(9600); diff --git a/pms3003.pl b/pms3003.pl index cb68af2..e90d1c0 100755 --- a/pms3003.pl +++ b/pms3003.pl @@ -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.3:1.0-port0'; -my $influx_url = shift @ARGV || 'http://10.60.0.92:8086/write?consistency=any&db=rot13'; +my $influx_url = shift @ARGV || 'http://192.168.3.40:8086/write?consistency=any&db=rot13'; my $debug = $ENV{DEBUG} || 0; diff --git a/zph02.pl b/zph02.pl index 00d8c2d..731a432 100755 --- a/zph02.pl +++ b/zph02.pl @@ -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.0'; -my $influx_url = shift @ARGV || 'http://10.60.0.92:8086/write?consistency=any&db=rot13'; +my $influx_url = shift @ARGV || 'http://192.168.3.40:8086/write?consistency=any&db=rot13'; my $s = new Device::SerialPort( $port ) || die $!; $s->baudrate(9600); -- 2.20.1 From 4914d51b06240ba013d2534cd3cebf0f7ce9c8f1 Mon Sep 17 00:00:00 2001 From: Dobrica Pavlinusic Date: Sun, 10 Mar 2024 14:14:51 +0100 Subject: [PATCH 16/16] don't send 0 values --- zph02.pl | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/zph02.pl b/zph02.pl index 731a432..10f961e 100755 --- a/zph02.pl +++ b/zph02.pl @@ -43,7 +43,7 @@ while (1) { my $checksum = $v[8]; my $pcnt = $v[3] + ( $v[4] / 100 ); - if ( $v[0] == 0xff && $sum == $checksum ) { + if ( $v[0] == 0xff && $sum == $checksum && $pcnt > 0) { my $influx = "zph02,dc=trnjanska pm25_pcnt=$pcnt $t"; print "$influx\n" if -e '/dev/shm/air-debug'; system "curl --max-time 2 --silent -XPOST '$influx_url' --data-binary '$influx'"; -- 2.20.1