Created
July 22, 2020 02:44
-
-
Save kinneko/30f51ab42fce2f22ea369b8f388f60ea to your computer and use it in GitHub Desktop.
LYWSD03MMCの温度湿度バッテリ電圧をgattoolで取得するシェルスクリプト(0度以下は未対応) オリジナル:http://www.d0wn.com/using-bash-and-gatttool-to-get-readings-from-xiaomi-mijia-lywsd03mmc-temperature-humidity-sensor/
This file contains hidden or 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 | |
if [ -z "$1" ]; then | |
echo "Usage: $0 [Bluetooth MAC Addr]" | |
exit 1 | |
else | |
MAC=$1 | |
fi | |
#bt=$(timeout 15 gatttool -b A4:C1:38:8E:1D:8E --char-write-req --handle='0x0038' --value="0100" --listen) | |
bt=$(timeout 12 gatttool -b $MAC --char-write-req --handle='0x0038' --value="0100" --listen|awk -F 'value: ' '{print $2}') | |
if [ -z "$bt" ]; then | |
echo "The reading failed" | |
else | |
temphexa=$(echo $bt | awk -F ' ' '{print $2$1}'| tr [:lower:] [:upper:] ) | |
temperature100=$(echo "ibase=16; $temphexa" | bc) | |
temperature=`echo "scale=2;$temperature100/100"|bc` | |
echo "temperature=$temperature" | |
humhexa=$(echo $bt | awk -F ' ' '{print $3}'| tr [:lower:] [:upper:]) | |
humidity=$(echo "ibase=16; $humhexa" | bc) | |
echo "humidity=$humidity" | |
batteryhexa=$(echo $bt | awk -F ' ' '{print $5$4}'| tr [:lower:] [:upper:] ) | |
battery1000=$(echo "ibase=16; $batteryhexa" | bc) | |
battery=`echo "scale=3;$battery1000/1000"|bc` | |
echo "voltage=$battery" | |
fi |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment