016675be72f10feb9c9131f2adf78dfccec5df47
[air-quality] / ble-mijia.sh
1 #!/bin/bash -e
2 mac=A4:C1:38:D8:3F:9C
3 test ! -z "$1" && mac=$1
4
5
6 gatttool -b $mac --char-write-req --handle='0x0038' --value="0100" --listen | tee /dev/stderr | grep --line-buffered value: | while read bt ; do
7
8 #echo "XXX[$bt]"
9
10 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' )
11
12 #echo $(date +%Y-%m-%d\ %H:%M:%S) $mac $v
13
14 curl --silent -XPOST 'http://10.60.0.92:8086/write?consistency=any&db=rot13' --data-binary "mijia,dc=trnjanska,mac=$mac $v"
15
16 done # gattool