LAB 4 Controller
LAB 4 Controller
LAB 4 Controller
PROGRAMME : DTK
PRACTICAL WORK : 4
TITLE : MESSAGE QUEUING TELEMETRY TRANSPORT (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/12
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/12
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 with Node-Red dashboard.
Equipment
Theory
MQTT is one of the most used protocols in IoT projects. It stands for Message Queuing Telemetry Transport. In
addition, it is designed as a lightweight messaging protocol that uses publish/subscribe operations to exchange data
between clients and the server. Furthermore, its small size, low power usage, minimized data packets and ease of
implementation make the protocol ideal of the “machine-to-machine” or “Internet of Things” world.
Why MQTT?
MQTT has unique features you can hardly find in other protocols, like: It’s a lightweight protocol. So, it’s easy to
implement in software and fast in data transmission. It’s based on a messaging technique. Of course, you know
how fast your messenger/WhatsApp message delivery is. Likewise, the MQTT protocol.
Minimized data packets. Hence, low network usage.
Low power usage. As a result, it saves the connected device’s battery.
It’s real time! That’s is specifically what makes it perfect for IoT applications.
3/12
the broker, we call this operation a “publish”. When a device (a client) wants to receive data from the broker, we
call this operation a “subscribe”.
In addition, these clients are publishing and subscribing to topics. So, the broker here is the one that handles the
publishing/subscribing actions to the target topics.
Example: Let's say there is a device that has a temperature sensor. Certainly, it wants to send his readings to the
broker. On the other side, a phone/desktop application wants to receive this temperature value. Therefore, 2 things
will happen: The device defines the topic it wants to publish on, ex: "temp". Then, it publishes the message
"temperature value". The phone/desktop application subscribes to the topic "temp". Then, it receives the message
that the device has published, which is the temperature value. Again, the broker role here is to take the message
"temperature value and deliver it to phone/desktop application. subscribe 21.3 C 21.30 MOTT broker publish
subscribe Temperature sensor 21.30 Schematic data flow from sensor (machine) to devise machine) MQTT
Components: That takes us to the MQTT components, which are 5 as follows: Broker, which is the server that
handles the data transmission between the clients. A topic, which is the place a device wants to put or retrieve a
message to/from. The message, which is the data that a device receives "when subscribing" from a topic or send
"when publishing to a topic. Publish, is the process a device does to send its message to the broker. Subscribe,
where a device does to retrieve a message from the broker.
Procedure
PART A - Installing Node.js
4/12
2. Run the Node.js installer and follow the steps below:
5/12
4. Verify the installation via this command: C:\Users\Admin> node -v, in command prompt or PowerShell.
5. The final step in node.js installed is to update your local npm version (if required) - the package manager that
comes bundled with Node.js. You can run the following command: npm install npm –global
1. Start your command prompt by clicking Start, typing “cmd” and click the icon.
2. Now we can begin to install Node-RED, navigate to command prompt and input this command:
Please note if the module does not install and throws up error messages regarding permissions, you will need to
run CMD in Administrator mode.
3. Once this command is running Node-RED will begin to install. Please note this can take some time to complete.
6/12
4. Once complete, the output should look like this:
2. Once everything has been successfully installed you can now begin to run your Node-RED webserver. You can
do this by navigating to a command prompt and typing in the following command: Node-RED.
3. Once the server has booted up successfully the command prompt will let us know that the server is now
running, and what IP address it is on:
4. Take note of the Node-RED webserver’s IP address and input it into your web browser:
7/12
5. You have now successfully installed, booted up, and accessed your Node-RED webserver.
6. You need to Install node-red dashboard before you can use certain required functions.
7. Click Install tab, search for “dashboard”, select “node-red-dashboard”, and click Install.
1. Start Node-RED using Step 2 - 4 in Part C. Paste the server IP in your browser.
2. Scroll down to network node, click “mqtt in” and drag it into the grid.
8/12
3. Double-click on mqtt-in node and change the setting as shown below:
i. Add mqtt-broker by clicking the pencil icon. Set the broker with these settings and click Update:
4. Scroll down to dashboard node, pick, and drag gauge to grid. Edit the settings.
9/12
5. Connect the two nodes.
6. Click Deploy.
2. Set MQTT Client Name to dec50132_lab4, Protocol to mqtt / tcp and Host to broker.hivemq.com. Leave other
setting as default. Save your settings.
10/12
3. Create a publisher by clicking the Add publisher. Do the same for Add subscriber.
7. Observe and record the results in both MQTTBox and your Node-RED dashboard.
8. Change and publish the payload values in MQTTBox client. Record the results.
Build an interface like the example below in your node-red dashboard. Submit a video to show your system
operations. Please include the MQTT dashboard configuration, MQTTBox settings, and the output.
Result
Observations and Results:
11/12
NODE-RED:
MQTTBOX:
SUBCRIBER OUTPUT :
DASHBOARD:
12/12
Discussion
Write your discussion on observed result.
We learned from the discussion of the observed result that one of the most popular protocols in Internet
of Things applications is MQTT. Message Queuing Telemetry Transport is what it stands for.
Furthermore, it is intended to be a lightweight messaging protocol that facilitates data interchange
between clients and the server via publish or subscribe operations. Furthermore, the protocol is perfect
for the "machine-to-machine" or "Internet of Things" environment due to its compact size, low power
consumption, minimal data packets, and simplicity of implementation.
13/12
Conclusion
Write your conclusion on this practical work.
In the conclusion, we learn how to use the MQTT at the end. MQTT operates on a client-server
architecture, just like any other internet protocol. Similarly, the server is the one in charge of responding
to requests from clients to exchange data with one another. The linked devices are referred to as clients,
and the MQTT server is called a broker. For this reason, we refer to an action as a "publish" when a
device (a client) wishes to submit data to the broker. We refer to an action as a "subscribe" when a
device (a client) requests data from the broker. We also show the exactly result for this lab.
14/12