Live DHT11 and BMP280 Dashboard with ESP32 and MQTT
This project combines two sensors on an ESP32 and displays their measurements in Node-RED. The DHT11 supplies temperature and relative humidity. The BMP280 supplies barometric pressure and its own temperature reading; it does not measure humidity. Keeping the two temperature sources distinct prevents a misleading dashboard.
The data path is ESP32 firmware → MQTT broker → Node-RED validation and parsing → FlowFuse Dashboard widgets. Establish the broker connection first using Node-RED with MQTT, then add sensors and dashboard widgets. The code below uses commonly available Arduino libraries; record the actual library versions and test the sketch on your own wiring before treating its readings as validated measurements.
Hardware, wiring and libraries
You need an ESP32 development board, a DHT11 sensor/module, a BMP280 breakout, jumper wires, an MQTT broker and Node-RED with FlowFuse Dashboard installed.
For the example, the DHT11 DATA pin is connected to GPIO 4; the BMP280 uses I2C on SDA GPIO 21 and SCL GPIO 22. These are example assignments for a typical ESP32 DevKit, not universal board requirements. Check your board pinout and breakout documentation. Some modules have regulators or level shifting; do not infer a breakout's voltage tolerance solely from the sensor-chip name.
Install these Arduino libraries: DHTesp, Adafruit BMP280 Library, Adafruit Unified Sensor (if requested by the library manager), and PubSubClient. This example assumes an ESP32 Arduino core and the stated library APIs. The MQTT connection here uses plain MQTT for a trusted local lab; use a suitable secure transport for untrusted networks.
1. Upload the ESP32 firmware
Replace the Wi-Fi and broker placeholders locally. The broker hostname must be reachable from the ESP32; 127.0.0.1 refers to the ESP32 itself, not the Raspberry Pi broker. The sketch sends one JSON record every five seconds, which is slow enough for a beginner monitoring example and respects the DHT11's update interval.
The sample code illustrates the message path and failure handling; it has not been physically tested on your exact board. Review the API of the library versions installed on your machine before uploading. For a production device, add broker authentication/TLS appropriate to your network, exponential reconnect backoff, a unique ID per physical board, and better sensor retry logic. The sample intentionally skips publishing when a sensor returns invalid data instead of disguising a failed read as zero.
2. Build the Node-RED flow
Create a flow with these stages:
MQTT In → JSON → validation → Dashboard widgets
Configure MQTT In to subscribe to solderhub/lab/esp32-01/telemetry on the correct broker. Add a JSON node if incoming payload arrives as a string; inspect it in Debug because payload handling depends on node configuration and data type. Configure the dashboard and UI nodes using Node-RED Dashboard 2.0: Install Buttons, Switches and Gauges.
Before forwarding values to gauges, check that the payload is an object and each expected property is a finite number. If the incoming MQTT message is malformed or a field is missing, send it to an error path and keep the last valid reading marked with its timestamp rather than resetting the gauge to zero.
3. Build the dashboard
Use FlowFuse Dashboard, package @flowfuse/node-red-dashboard, for new dashboard work. The legacy node-red-dashboard package is deprecated. Create separate values for DHT11 temperature, DHT11 relative humidity, BMP280 pressure and BMP280 temperature. Label every widget with the sensor source and unit.
Use a gauge for the current value and a chart for trends. Set ranges to useful values for your test environment rather than implying sensor accuracy. Add a last-update timestamp or online/stale indicator: when MQTT stops, the old gauge value must not look live.
4. Keep units and sensor errors honest
DHT11 is a low-cost, relatively low-resolution sensor. Avoid displaying decimal places that imply precision it cannot deliver. BMP280 pressure readings depend on calibration, weather and altitude; do not present a simple pressure gauge as a weather forecast.
A device can stay online while one sensor fails. Track sensor read validity separately from MQTT connection status. If a value cannot be read, skip it or publish an explicit validity field in your schema. Never silently write 0 °C or 0% humidity to mean “no data.”
Troubleshooting
No MQTT messages: verify topic, broker host and connection; test a simple publication from a command-line client.
JSON parse error: inspect the raw payload and confirm valid JSON, and whether the JSON node expects a string.
DHT read fails: recheck DATA wiring, supply and supported sampling interval; review library diagnostics.
BMP280 not detected: check I2C wiring, address (commonly 0x76 or 0x77) and breakout supply requirements.
Dashboard looks frozen: check arrival timestamps and Node-RED node status. A blank or old gauge is not proof of a zero sensor reading.
Next steps
- Install Mosquitto on Raspberry Pi 5
- Node-RED Dashboard 2.0: Install Buttons, Switches and Gauges
- MQTT Troubleshooting: Connection Refused, rc=-2 and rc=5
Official references: FlowFuse Dashboard, Mosquitto documentation and the documentation for the installed DHTesp/BMP280 library versions.