Advancedesp32

MQTT Sensor Network with ESP32

Build a distributed IoT sensor network using multiple ESP32 nodes communicating via MQTT protocol.

6-8 hours
$40-60
Sarah Mitchell
MQTT Sensor Network with ESP32

Parts List

  • ESP32 DevKit (x3)
  • DHT22 Temperature Sensors (x3)
  • BMP280 Pressure Sensors (x2)
  • MQTT Broker (Raspberry Pi or cloud)
  • Breadboards

Step-by-Step Instructions

1

Set Up MQTT Broker

Install the Mosquitto MQTT broker on a Raspberry Pi or a cloud server by running sudo apt install mosquitto mosquitto-clients on a Debian-based system. Configure the broker to listen on port 1883 for unencrypted connections and set up authentication with a username and password for security. Create topic namespaces such as home/sensors/temperature and home/sensors/pressure for organized data routing.

2

Build Sensor Nodes

Program each ESP32 with a sketch that connects to WiFi and then to the MQTT broker using the PubSubClient library. Wire the DHT22 sensor data pin to GPIO 4 and the BMP280 sensor to the I2C bus on GPIO 21 (SDA) and GPIO 22 (SCL). Each node should read its sensors every 30 seconds and publish the readings as JSON payloads to its assigned MQTT topic.

3

Configure MQTT Topics

Design a hierarchical topic structure that includes the location, sensor type, and node ID, such as home/livingroom/temperature/node1. Subscribe to a command topic on each node so you can remotely adjust reading intervals or trigger calibration from a central dashboard. Test the message flow by subscribing to all topics with the mosquitto_sub command-line tool and verifying data arrives correctly.

4

Create Dashboard

Install Node-RED on your Raspberry Pi and access the flow editor at http://localhost:1880. Add MQTT input nodes configured to subscribe to your sensor topics, then connect them to chart and gauge nodes for real-time visualization. Arrange the dashboard widgets in logical groups by room or sensor type and deploy the flow to create a live monitoring dashboard accessible from any browser on your network.