Nowadays as more Internet of Things (IoT) devices and sensors become available, and user-level clickstream analytics tracking is added to mobile applications and websites, there is an increasing desire to understand and share what is happening in near real-time. As well as providing instant feedback on the activities that are monitored, allowing the user to react more quickly as events are happening rather than the next day when the reporting data is refreshed. Additionally, predictions and forecasts will be more accurate with fresh data. Here user can publish temperature and humidity readings from a DHT22 sensor via MQTT with the ESP32 to any platform that supports MQTT or any MQTT client. As an example, I will publish sensor readings to the Node-RED Dashboard and the ESP32 will be programmed using Arduino IDE.
MQTT (Message Queuing Telemetry Transport)
MQTT is a simple messaging protocol that helps simple communication between multiple devices. Also, it allows users to send commands to control output, read and publish data from sensor nodes.
Few basic concepts in MQTT
Messages are the information that we want to exchange between our devices. Whether it is a command or data.
In a publish and subscribe system, a device can publish a message on a topic, or it can be subscribed to a particular topic to receive messages.
Topics are the way we register interest for incoming messages or how we specify where we want to publish the message.
The broker is primarily responsible for receiving all messages, filtering the messages, decide who is interested in them, and then publishing the message to all subscribed clients.
I used the Mosquitto broker installed on the Raspberry Pi. The broker is responsible for receiving all messages, filtering the messages, decide who is interested in them, and publishing the messages to all subscribed clients. The following figure shows an overview of which devices publish and subscribe to the broker.
Developing dashboard use Node-Red
Node-RED helps developers wire up input, output, and processing nodes to create flows to process data, control things, or send alerts. It works by allowing users to wire up web services or custom “nodes” to each other, or to things. The node-red dashboard is an add-on module that lets me create live dashboards. For using Node-red needs to download and install the required packages in Raspberry pi
The next step is to create the dashboard layout, so I created a button to control an ESP32 (microcontroller) output; a chart, and a gauge to display temperature and humidity readings from the DHT22 sensor. Nodes are small, packaged functions that display a specific task. They take input and generate an output. All nodes are connected in a chain and they generate a flow.
I published sensor readings to the Node-RED Dashboard. For seeing the dashboard needs use the Raspberry Pi IP address followed by :1880/ui. The figure below displays the dashboard in my local browser. Here my ESP32 board publishing DHT22 temperature and humidity readings to Node-Red via MQTT which is a great communication protocol to exchange small amounts of data between devices.