collect Xiomi Mijia values and send them to influx
authorDobrica Pavlinusic <dpavlin@rot13.org>
Sun, 22 Jan 2023 10:05:05 +0000 (11:05 +0100)
committerDobrica Pavlinusic <dpavlin@rot13.org>
Sun, 22 Jan 2023 15:06:36 +0000 (16:06 +0100)
ble-mijia.sh [new file with mode: 0755]

diff --git a/ble-mijia.sh b/ble-mijia.sh
new file mode 100755 (executable)
index 0000000..078c4db
--- /dev/null
@@ -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