From: Dobrica Pavlinusic Date: Fri, 27 Jan 2023 09:13:02 +0000 (+0100) Subject: simplify script to use only gattool, awk and curl X-Git-Url: http://git.rot13.org/?p=air-quality;a=commitdiff_plain;h=018f7c730b6cd7757531681e748431288da59382 simplify script to use only gattool, awk and curl --- 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