An Example Arduino Application for BLE Advertisement Scanning and Xiaomi Sensor Decoding
This Arduino application was created to experiment with the ESP32 and BLE support. Specifically, I wanted to create a more full featured application to gather environmental data (Temperature and Humidity) from the inexpensive XIAOMI Mijia Model LYWSD03MMC sensor that I had bought on Ali Express from here: https://www.aliexpress.com/item/3256803316317463.html
When investigating this support, I came across several tutorials that referred me to two repos here on Github that had extended and enhanced the firmware for these devices:
https://github.com/atc1441/ATC_MiThermometer which referred me to: https://github.com/pvvx/ATC_MiThermometer
The latter site is what I've used to upgrade the firmware in my Xiaomi sensors, and seems to provide some very nice enhancements.
The first step is to power up your Xiaomi sensors, and then update the firmware. From the site above, you can access the Web-based Telink Flasher for Mi Thermostat:
https://pvvx.github.io/ATC_MiThermometer/TelinkMiFlasher.html
NOTE: I've only used the Chrome browser to do this, and your browser must support the Bluetooth extensions that allow BLE communications.
When you open this page there are a few steps to follow:
This is all that is required. By default, when this new firmware is installed the device will now have a BLE name of ATC_{mac address}
NOTE: You can also edit the name through the web interface to add your own name or name prefix. This can make it easy to pick your devices out of all of the visible sensors. The code supports setting a namePrefix to look for, and defaults this to 'ATC_'.
You will need to have the ESP32 Board support installed. Create a new Arduino application and open this application file. When you run it on your device, it should immediately begin to loop, performing BLE Advertisement Scans, and displaying the Xiaomi detected advertisements in the serial monitor.