First install the following dependencies:
sudo apt install bluetooth libbluetooth-dev
sudo apt-get install libglib2.0-dev
sudo apt install python3-pip
pip3 install pybluez
pip3 install bluepy
pip3 install google-auth==1.27.0
pip3 install firebase-admin==4.5.2
Bluetooth LE Scanning needs root privileges, to run the script as normal user, execute:
sudo setcap cap_net_raw,cap_net_admin+eip $(eval readlink -f `which python3`)
Out of the box, the BLE interface doesn't work on Raspberry Pi with Ubuntu 20.04 server. (2021.01.28)
To fix this issue execute:
sudo ln -s /lib/firmware /etc/firmware
sudo hciattach /dev/ttyAMA0 bcm43xx 921600 -
Output should look like this:
ubuntu@ubuntu:~/git/XiaomiTemperatureSensor$ sudo hcitool dev
Devices:
ubuntu@ubuntu:~/git/XiaomiTemperatureSensor$ sudo ln -s /lib/firmware /etc/firmware
ubuntu@ubuntu:~/git/XiaomiTemperatureSensor$ sudo hciattach /dev/ttyAMA0 bcm43xx 921600 -
bcm43xx_init
Set Controller UART speed to 921600 bit/s
Flash firmware /etc/firmware/brcm/BCM4345C0.hcd
Set Controller UART speed to 921600 bit/s
Device setup complete
ubuntu@ubuntu:~/git/XiaomiTemperatureSensor$ sudo hcitool dev
Devices:
hci0 43:45:C0:00:1F:AC
sudo hcitool lescan --duplicate
or
sudo hcitool lescan
'58:2D:34:38:3C:E2'
- LYWSDCGQ
'A4:C1:38:EA:1D:CC'
- LYWSD03MMC kitchen
'A4:C1:38:5B:10:E2'
- LYWSD03MMC outside
'A4:C1:38:D2:7A:00'
- LYWSD03MMC filament
It can read data from LYWSDCGQ and LYWSD03MMC.
Setup your sensor MAC addresses in xiaomi_reader.py
.
Run:
python3 xiaomi_reader.py
or
bash run.bash
https://github.com/JsBergbau/MiTemperature2
https://github.com/ratcashdev/mitemp
https://github.com/erdose/xiaomi-mi-lywsd03mmc