ESP32 Xiaomi Hack [UPDATED Oct. 2020]

Dear friends welcome to another video! Today we are going to learn how to get the data that this Xiaomi Temperature and Humidity monitor transmits using the Bluetooth functionality of the ESP32 board. There is a lot to cover so, let’s get started!

Intro to the ESP32 Xiaomi Hack

Hello, guys, I am Nick and welcome to educ8s.tv a channel that is all about DIY electronics projects. In this channel, I share everything about the projects I build to help you develop similar projects or inspire you to start making things because it is easy, fun and creative. Subscribe to the channel now if you do not want to miss any future video.

Let’s see what we are going to build today. As you can see, I am using an ESP32 board and a 2.8” color TFT display I reviewed a few weeks ago. On the display, we display the temperature and the humidity. The cool thing is that I haven’t connected any sensors to the ESP32 board. I get the temperature and the humidity wirelessly from this commercial Xiaomi Temperature and Humidity monitor. How cool is that! The display on the Xiaomi device is updated every second but I update the display that is connected to the ESP32 board every 10 seconds to conserve power on the Xiaomi device.

This cool Xiaomi temperature and humidity sensor displays the temperature and the humidity on its LCD display and it can also transmit the data to other Xiaomi Devices or apps using the Bluetooth protocol. The devices uses a single AAA battery and since it is a commercial product, the battery life of the device is excellent. It can last on a single AAA battery for months, something we can’t achieve on our DIY projects. A few weeks ago, I discovered that some clever guys managed to reverse engineer the protocol that Xiaomi uses to transmit the data from the sensor and managed to get that data using an ESP32 board. So I tried it, and as you can see it works!

——————–
WHERE TO BUY
——————–

ESP32: https://educ8s.tv/part/ESP32

2.8″ Display: https://educ8s.tv/part/28ILI9341

Xiaomi Sensor: https://educ8s.tv/part/XiaomiThermometer

Breadboard: https://educ8s.tv/part/LargeBreadboard

Wires: https://educ8s.tv/part/Wires

USB Meter: https://educ8s.tv/part/UsbDoctorOLED

Powerbank: https://educ8s.tv/part/Powerbank

Full disclosure: All of the links above are affiliate links. I get a small percentage of each sale they generate. Thank you for your support!

[adsense]

The Electronics

First, we have to connect the ESP32 Board to the 2.8” display according to this schematic diagram.

I am using this DOIT ESP32 board which was released about two years ago. This version of the board is no longer available since there is now a newer version of it available which offers more pins, this one. The only reason I am using the old version of the board is that the GND pin of the board placed next to the SPI pins, at the same side of the board, which makes it breadboard friendly.

After connecting the display to the board we can power up the project. After a few seconds, we receive live data from the nearby Xiaomi Device. Since the device uses Bluetooth 4 the range of it is pretty good. We can easily get the data this device transmits from distances up to 10 meters or more! We can also receive the battery level of the Xiaomi Device but I don’t display this value on the screen.

If we use this USB meter, we can see that the current draw of this project is around 120-150 mA using this big display. If we use an e-paper display, put the ESP32 board in deep sleep mode, and get data from the sensor every few minutes we can make this project battery friendly. I will try this in a future video. This project is just a demonstration that we can get data from this device wirelessly.

The code of the ESP32 Xiaomi Hack

Let’s now see the software side of the project.

The code of the project is based on this project: https://github.com/turlvo/KuKuMi

I used the code which gets that data from the Xiaomi device and built a standalone project with it. In this variable, we declare that we need to get fresh data every 10 seconds. Here, we declare that we want to display the temperature in degrees Celsius. If you want to use the Imperial system just set this variable to false. At the setup function we initialize the display and the Bluetooth module of the ESP32 board and then we draw the user interface on the screen. Next, we search for Bluetooth devices nearby every 10 seconds. We don’t make a connection to the Xiaomi Device since it is not needed. We only scan for nearby Bluetooth low energy peripherals and check the broadcast advertisement packets. The humidity and temperature values are stored in those packets, so we only need to read them. After we read the values we display them on the screen. As always you can find a link to the code of this project in the description of the video below.

Now that we know how to get data wirelessly from this sensor we can build a complete battery-powered weather station. Since this Xiaomi Device is a commercial product, it offers great battery life. Unfortunately, we can’t achieve similar battery consumption on our projects yet. So, I plan to use this sensor as an outdoors sensor for a weather station project which will use a big e-paper display. It will be cool. Also, I am going to search for other Xiaomi Bluetooth enabled devices that we can hack in a similar way. Stay tuned.

——————–
CODE
——————–

 

 

 

——————–

SUBSCRIBE ON YOUTUBE

——————–

Never miss a video: Subscribe to educ8s.tv