In this blog post, I will share my experience of setting up an inexpensive room sensor network using an ESP32 and a couple of Xiaomi devices, with the help of the open source project OpenMQTTGateway.
For a long time, I had been planning to build ESP32-based devices to measure the temperature in my apartment. In summer, visualizing the temperature helps in ventilating the apartment efficiently, while in winter, it helps to keep an eye on the humidity levels. However, more important projects kept taking precedence, and I never really got around to building the sensor network. That is until I discovered the OpenMQTTGateway project.
What is the OpenMQTTGateway?
The OpenMQTTGateway is an open source project that may not seem like much, but it is incredibly effective. An ESP32 flashed with this firmware will scan for devices and read their values if possible. The gateway ESP32 will then publish the discovered devices to specific topics on a MQTT broker. If the firmware recognizes a device type and can communicate with it, it will also publish additional information.
The published information includes a plethora of data to play with, with each device having its own topic, and a JSON structure containing the collected information.
Hardware: The Gateway
To run OpenMQTTGateway, any ESP32 device can be used. However, to travel in style and maintain the aesthetics of my apartment, I opted for the ThingPulse ESPGateway, which comes with a sleek enclosure and an external antenna that helps to communicate over a longer distance. For those who want to connect the gateway over Ethernet, the Ethernet the ESPGateway is also a good choice.
Hardware: The Sensors
For the room sensors, I used Xiaomi BLE sensors that are very affordable and measure temperature and humidity, communicating over Bluetooth LE. When purchased in bundles, these sensors can be found for less than USD $5 on Aliexpress.
By using a custom firmware that can be flashed using this GitHub project, additional features can be added to the sensors.
Apart from the Xiaomi BLE Room sensors, there are many other devices that can communicate with the OpenMQTTGateway in my home. For instance, the Xiaomi Flora Plant sensors work exceptionally well to report soil humidity, temperature, and light.
You can also use the OpenMQTTGateay to track the presence of devices in your apartment. For instance if you are wearing a Fit tracker like the Xiaomi Mi Band you can track the presence of the people wearing them.
Storing, Controlling and Visualizing
To store, control, and visualize the data, I have a Raspberry Pi 4 running the MQTT broker. A Node-Red instance takes the data and pushes it into an InfluxDB. Then, Grafana is used to visualize the data over time. And this is how it looks for the Xiaomi room sensors: