From: Dobrica Pavlinusic Date: Sun, 22 Jan 2023 10:05:05 +0000 (+0100) Subject: collect Xiomi Mijia values and send them to influx X-Git-Url: http://git.rot13.org/?p=air-quality;a=commitdiff_plain;h=3f56683394d6ea2a0bb02a5f885ba2877c8de9f1 collect Xiomi Mijia values and send them to influx --- 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