DEC50132 PW5 New
DEC50132 PW5 New
DEC50132 PW5 New
PROGRAMME : DTK
PRACTICAL WORK : 5
TITLE : DHT11 MONITORING VIA MQTT
LECTURER NAME : MOHD. ZAKI DOI
DATE :
SCORE
PRACTICAL SKILL (CLO2, PLO5, P4) ATTAINMENT LAB REPORT ATTAINMENT
S1 Results
1) Able to connect the circuit S2 Discussion
independently. S3 Conclusion
S4
S1
2) Able to identify relevant pin and S2
suitable identifier/ variable
independently. S3
S4
S1
S2
3) Able to code independently.
S3
S4
1/9
Score Description
5 Student can complete all tasks assigned WITHOUT errors
4 Student can complete all tasks assigned with A FEW errors
3 Student can complete all tasks assigned with MORE errors
2 Student can complete partial tasks assigned WITHOUT errors
1 Student can complete partial tasks assigned with A FEW errors
Conclusion
includes
Conclusion The closing
whether the
Provide answers The closing The closing paragraph do
findings
to objectives paragraph paragraph not attempt to
supported the No conclusion
stated summarizes and attempts to summarize the
hypothesis, was included in
earlier. draws a summarize but experiment OR
possible sources the report.
Ability to learn sufficient draws a weak shows little
of error, and
something from conclusion. conclusion. effort and
what was
the experiment. reflection.
learned from
the experiment.
2/9
Objectives
Upon completion of this practical work, students should be able to:
1. Write code to established internet connection (MQTT Client).
2. Write code to publish and subscribe MQTT.
3. Apply writing simple IoT application for monitoring sensor reading.
Equipment
1. Computer with Node-RED installed.
2. Android phone with IoT MQTT Panel app.
3. Internet connection (access point dedicated to the laboratory).
Procedure
Part A - ESP32 and DHT11 Circuit.
Circuit
3/9
1. Open Arduino IDE and click on Library Manager.
2. Search for “asyncmqtt” and install AsyncMQTT_Generic.
1. Start Node-RED.
4/9
Node-RED
#include "DHT.h"
#include <WiFi.h>
#include <AsyncMqttClient.h>
//MQTT broker
#define MQTT_HOST "broker.hivemq.com"
#define MQTT_PORT 1883
5/9
//MQTT Topics
#define MQTT_PUB_TEMP_DHT "lab5/esp32/dht/temperature"
#define MQTT_PUB_HUM_DHT "lab5/esp32/dht/humidity"
#define DHTPIN 4
#define DHTTYPE DHT11
DHT dht(DHTPIN, DHTTYPE);
AsyncMqttClient mqttClient;
TimerHandle_t mqttReconnectTimer;
TimerHandle_t wifiReconnectTimer;
void connectToWifi() {
Serial.println("Connecting to Wi-Fi...");
WiFi.begin(WIFI_SSID, WIFI_PASSWORD);
}
void connectToMqtt() {
Serial.println("Connecting to MQTT...");
mqttClient.connect();
}
6/9
}
void setup() {
Serial.begin(115200);
Serial.println();
dht.begin();
delay(1000);
WiFi.onEvent(WiFiEvent);
mqttClient.onConnect(onMqttConnect);
mqttClient.onDisconnect(onMqttDisconnect);
mqttClient.onPublish(onMqttPublish);
mqttClient.setServer(MQTT_HOST, MQTT_PORT);
connectToWifi();
}
void loop() {
unsigned long currentMillis = millis();
if (currentMillis - previousMillis >= interval) {
previousMillis = currentMillis;
if (isnan(temperature_DHT) || isnan(humidity_DHT)) {
Serial.println(F("Failed to read from DHT sensor!"));
return;
}
7/9
Part E - Monitoring Temperature Readings via IoT MQTT Panel app.
1. Go the Google Play Store to download and install IoT MQTT Panel app.
2. Launch the app. Tap on “Setup a Connection” set the new connection for first time use.
8/9
Port number and network protocol should already be set as 1883 and TCP.
3. Tap on “+” on the right side of “Add Dashboard” to add a new MQT Panel dashboard.
4. Name the dashboard and tap “Save”. Tap “Create” to finish this step. Record your result.
5. Tap on your newly created connection to open it. Tap “Add Panel” and select “Gauge”. Set the following as:
“Panel Name” as DHT11 - Temperature and “Topic” as lab5/esp32/dht/temperature.
“Payload min” = 0 and “Payload max” = 100.
“Unit” as Celsius.
NOTE: You can also use any other app for this procedure, depending on the operating system of your smartphones.
The equivalent settings are applicable.
9/9
10/9
PART F - Problem Based Learning
Build an interface to monitor DHT11 output using IoT MQTT Panel app on your smartphone to resemble the display
of your Node-RED dashboard. You are free to choose any type of dashboard components if they are reasonable.
Line Graph
11/9
Text Input
Text Log
12/9
Result
Result
13/9
Already shown above.
Discussion
Write your discussion on observed result.
The most practical and effective way to gather and send temperature and humidity data from the
DHT11 sensor is to use MQTTBox for DHT11 monitoring. The multipurpose MQTT client
MQTTBox facilitates smooth connection between the MQTT broker and the sensor. By setting
up the DHT11 sensor to broadcast data to a particular topic allows MQTTBox to receive that
data.
subject and obtain the real-time sensor measurements. This configuration makes monitoring
simple and viewing of the DHT11 data, given that MQTTBox offers a number of display and
studying the MQTT messages that were received. MQTTBox allows users to easily track patterns
in temperature and humidity, and use the information into their chosen Internet of Things
applications, systems.
Conclusion
Write your conclusion on this practical work.
As a conclusion, we now know how to install the DHT sensor and other sensor libraries in the
Arduino IDE so that they may be used in code and operate. Here, we've implemented the
knowledge we learned in the previous two experiments utilizing the MQTTbox application. We
now know that we can publish and subscribe using MQTTbox. In order to link the esp32 and the
MQTT panel to the internet, we have additionally utilized the information from lab 2.
14/9