Codementor Events

Publishing DHT11 sensor readings to MQTT

Published Jan 05, 2022Last updated Jan 06, 2022

In this project, an ESP32 takes readings from a DHT11 temperature and humidity sensor and publishes those to EMQX. This project is adapted from Rui Santos's excellent tutorial, using the DHT11 in place of the BME680, and broker.emqx.io in place of a local MQTT broker. You'll need to download the MQTT library umqttsimple.py from that tutorial.

I also used tayfunulu's WiFi Manager instead of hard-coding the WLAN credentials. All you need do is download the .py from his repository. In the “near future”, I'll add code to WiFi Manager to allow the user to change the default password.

The other libraries should come with the standard ESP Micropython distribution.

In addition to Node-RED, I also used the Linux desktop client MQTT X and the Android app MQTT Dash. In the “near future”, I'll try out the iOS version. Below are their respective screenshots.

NODE-Red

The best way to learn to get this output is by following Rui's instructions in his tutorial, omitting the steps for pressure and gas, and changing the broker if needed. You can also take the easy way out and import Rui's or my github repository's flows.json, depending on whether you stick with Rui's BME+local MQTT broker or my DHT11+emqx broker, respectively.

MQTTX
MQTT Dash
MQTT Dash

As an aside, those screenshots are more-or-less to scale. Yes, I have a big-screen phone — 6.44".

And another aside — the README.md on my github repository is slightly different because of the differences in github's and codementor's Markdown.

ACKNOWLEDGEMENTS

Thanks to Michael Polla for his gist on resizing image files in, among others, a github README.md

I also got the idea of using tables to insert an image caption from a post in towardsdev.com

Discover and read more posts from Daniel Escasa
get started
post commentsBe the first to share your opinion
Show more replies