Created
January 26, 2024 15:41
-
-
Save vimagick/5586bcfcd9328edd4f0c788c02adca1c to your computer and use it in GitHub Desktop.
π‘οΈπ§π
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
# sudo hcitool lescan | |
MAC="4C:65:A8:D?:??:??" | |
while :; do | |
HT=$(timeout 20 gatttool -b $MAC --char-write-req --handle=0x10 -n 0100 --listen | grep -m1 "Notification handle") | |
(($? == 0)) && break | |
sleep 5 | |
done | |
while :; do | |
B=$(gatttool -b $MAC --char-read --handle=0x18) | |
(($? == 0)) && break | |
sleep 5 | |
done | |
THB=($( | |
echo ${HT} | cut -d: -f2 | xxd -p -r | tr -c '[0-9.]' ' ' | |
printf "%d\n" 0x$(echo ${B} | cut -d: -f2 | tr -d ' ') | |
)) | |
if ((${#THB[@]} == 3)); then | |
# {"timestamp":1706283589,"temperature":5.6,"humidity":63.6,"battery":79} | |
jq -n -c --argjson temperature ${THB[0]} --argjson humidity ${THB[1]} --argjson battery ${THB[2]} '{timestamp: (now|floor), $temperature, $humidity, $battery}' | |
fi |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment