Dec50132 Internet Based Controller Pw6
Dec50132 Internet Based Controller Pw6
Dec50132 Internet Based Controller Pw6
PROGRAMME :
PRACTICAL WORK NO : 6
TITLE : SIMPLE IOT APPLICATION FOR MONITORING
SENSOR READING WITH NODE-RED DASHBOARD
DATE :
LECTURER NAME :
JKE PSP
PRACTICAL SKILL RUBRIC
Results Professional looking Accurate Accurate Incomplete result, Data are not
and accurate representation representations of the major mistakes. shown OR are
• Results in the form representation of the of the data in data in written form, inaccurate.
of data, data in tables and/or tables and/or but no graphs or
calculation, graphs. Graphs and graphs. tables are presented.
waveform, graph tables are labelled and
etc. titled.
Analysis/ Discussion All point of discussion Most points of Some points of Some points of Very few points
on the results obtained discussion on discussion on results discussion on of discussion, not
• Ability to present, covered and results obtained covered and results obtained properly
interpret and elaborated. obtained elaborated. covered and but elaborated.
analyse result. covered and not properly
elaborated. elaborated.
Conclusion Conclusion includes The closing The closing paragraph The closing No conclusion
• Provide answers to whether the findings paragraph attempts to paragraph do not was included in
supported the summarizes summarize but draws attempts to the report.
objectives stated hypothesis, possible and draws a a weak conclusion. summarize the
sources of error, and sufficient experiment OR
earlier. what was learned from conclusion. shows little effort
• Ability to learn the experiment. and reflection.
something from the
experiment.
JKE PSP
Practical Work 6
Title: SIMPLE IOT APPLICATION FOR MONITORING SENSOR READING WITH NODE-RED
DASHBOARD
THEORY
Node-Red provides both an MQTT subscribe (input) and publish (output) node.
The configuration for these nodes are almost Identical as the main part of the configuration
concerns the actual client connection.
Because of this it is useful to think of the publish and subscribe nodes as consisting of two
components as shown in the schematic below:
Before we look a the actual configuration we will look at MQTT client connections in general.
To connect to an MQTT broker or server you need to know the Broker IP address or name, and the
port that it is using (default 1883).
JKE PSP
In addition a client needs to provide a client name to identify itself. Each client connection requires a
unique client name.
An MQTT broker can enforce encryption and username/password authentication in which case the
connecting client must comply
Procedure:
JKE PSP
debug node
MQTT in node
Gauge node
Graph node
JKE PSP
6. Edit debug node as below:
JKE PSP
7. Edit Gauge node as below:
JKE PSP
10. Launch the node-red dashboard, and the interface will be shown below:
JKE PSP
// Uncomment depending on your sensor type:
#define DHTTYPE DHT11 // DHT 11
//#define DHTTYPE DHT22 // DHT 22 (AM2302)
// Create objects
DHT dht(DHTPIN, DHTTYPE);
WiFiClient espClient;
PubSubClient client(espClient);
void setup() {
Serial.begin(115200);
setup_wifi(); //Connect to Wifi network
if (!client.connected()) {
reconnect();
}
dht.begin();
// Nothing to send. Warn on MQTT debug_topic and then go to sleep for longer period.
if ( isnan(t) || isnan(h)) {
Serial.println("[ERROR] Please check the DHT sensor !");
client.publish(debug_topic, "[ERROR] Please check the DHT sensor !", true); // Publish humidity on topic/humidity
if ( debug ) {
Serial.print("Temperature : ");
Serial.print(t);
Serial.print(" | Humidity : ");
Serial.println(h);
}
// Publish values to MQTT topics
client.publish(temperature_topic, String(t).c_str(), true); // Publish temperature on topic/temperature
if ( debug ) {
Serial.println("Temperature sent to MQTT.");
}
delay(100); //some delay is needed for the mqtt server to accept the message
client.publish(humidity_topic, String(h).c_str(), true); // Publish humidity on topic/humidity
if ( debug ) {
Serial.println("Humidity sent to MQTT.");
}
JKE PSP
void setup_wifi() {
delay(20);
Serial.println();
Serial.print("Connecting to ");
Serial.println(wifi_ssid);
WiFi.begin(wifi_ssid, wifi_password);
Serial.println("");
Serial.println("WiFi is OK ");
Serial.print("=> ESP32 new IP address is: ");
Serial.print(WiFi.localIP());
Serial.println("");
}
while (!client.connected()) {
Serial.print("Connecting to MQTT broker ...");
if (client.connect("ESP32Client", mqtt_user, mqtt_password)) {
Serial.println("OK");
} else {
Serial.print("[Error] Not connected: ");
Serial.print(client.state());
Serial.println("Wait 5 seconds before retry.");
delay(5000);
}
}
}
void loop() {
}
JKE PSP
Problem Based Learning
Based on all the steps above and the previous Practical Work 5, use your understanding to get the
output in your node-red dashboard and Android or IOS IOT MQTT Panel to control lamp and fan in
your house. The interface in Node-red dashboard and IOS IOT MQTT Panel is shown below:
JKE PSP
Result:
Discussion:
JKE PSP
Write your discussion on observed result.
Conclusion:
References
https://iotdesignpro.com/projects/interface-arduino-with-node-red-to-send-sensor-data-on-
webpage
https://randomnerdtutorials.com/esp8266-and-node-red-with-mqtt/ DHT11 and MQTT
http://pdacontrolen.com/esp8266-public-mqtt-broker-hivemq-node-red/ (PW5 example)
http://www.steves-internet-guide.com/node-red-admin-basics/
http://www.steves-internet-guide.com/configuring-the-mqtt-publish-node/
http://noderedguide.com/node-red-lecture-4-a-tour-of-the-core-nodes/
https://github.com/hobbyquaker/awesome-mqtt (list of MQTT)
https://randomnerdtutorials.com/esp8266-and-node-red-with-mqtt/
https://iotbyhvm.ooo/how-to-connect-esp32-to-mqtt-broker-using-cloudmqtt/
https://dustcloud.atlassian.net/wiki/spaces/ALLDOC/pages/110305930/HiveMQ+integration
https://dustcloud.atlassian.net/wiki/spaces/ALLDOC/pages/110305930/HiveMQ+integration#HiveM
Qintegration!-PublishTemperaturetoHiveMQ
http://www.internetoflego.com/weather-station-dht11-mqtt-node-red-google-chart-oh-my/ (dht11)
JKE PSP