You are on page 1of 14

DEPARTMENT OF ELECTRICAL ENGINEERING

DEC50132 - INTERNET BASED CONTROLLER

PROGRAMME : DTK
PRACTICAL WORK : 4
TITLE : MESSAGE QUEUING TELEMETRY TRANSPORT (MQTT)
LECTURER NAME : MOHD. ZAKI DOI
DATE :

# GROUP MEMBERS REGISTRATION NO.


S1 SADARAHTUL NAJWA BINTI SHAMSOL 16DTK21F2003
S2 NUR IMAN BATRISYIA BINTI MOHAMAD KHAIRY 16DTK21F2007
S3 SYUHAIBA AMNI BINTI SAIFUL ANUAR 16DTK21F2005
S4 SWETHA A/P CHANDREW 16DTK21F2997

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 

ASSESSMENT SCORE WEIGHTAGE


Practical Skill (PS) @ 70% Lab Report (LR) @ 30% Total (100%)
S1 S1
S2 S2
PS = Score / 15 * 70 LR = Score / 15 * 30
S3 S3
S4 S4

PRACTICAL SKILL RUBRIC (PLO2, LD2)

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

LAB REPORT RUBRIC

Report Component Excellent Very Good Good Fair Unsatisfactory


(PLO2, LD2) 5 4 3 2 1
Professional
looking and
Accurate
Results accurate
Accurate representations
 Results in the representation
representation of the data in Incomplete Data are not
form of data, of the data in
of the data in written form, result, major shown OR are
calculation, tables and/or
tables and/or but no graphs mistakes. inaccurate.
waveform, graphs. Graphs
graphs. or tables are
graph etc. and tables are
presented.
labelled and
titled.
Analysis / All point of Some points of
Most points of Some points of
Discussion discussion on discussion on Very few points
discussion on discussion on
 Ability to the results results obtained of discussion,
results obtained results obtained
present, obtained covered and but not properly
covered and covered and
interpret and covered and not properly elaborated.
elaborated. elaborated.
analyse result. elaborated. elaborated.

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.

MESSAGE QUEUING TELEMETRY TRANSPORT (MQTT)

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

1. PC installed with Node.js, MQTTbox.


2. Internet connection (access point dedicated to the laboratory).

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.

How do these devices communicate with each other?


Certainly, web browsers use HTTP protocol to communicate with the servers on the internet. Likewise, IoT devices
use specific protocols to communicate (send and receive data) over the internet to each other.
And here are some of the most known IoT protocols:
 CoAP (Constrained Application Protocol)
 AMQP (Advanced Message Queuing Protocol)
 DDS (Data Distribution Service)
 STOMP (Simple Text Oriented Messaging Protocol)
 MQTT (Message Queue Telemetry Transport)
The last one is the most used protocol in IoT projects. That’s due to its fast, lightweight and easy to implement.

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.

How MQTT works?


Like any other internet protocol, MQTT is based on clients and a server. Likewise, the server is the guy who is
responsible for handling the client’s requests of receiving or sending data between each other. MQTT server is
called a broker, and the clients are simply the connected devices. So, when a device (a client) wants to send data to

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.

How many devices you can connect to a broker?


The number of connected devices “clients” to the broker depends on the broker service provider. In fact, it can
reach a massive number of clients those are publishing and subscribing all the time. but the amazing part of this
isn’t only the huge number of these connected devices but also any the fact that any device can get any other
device’s data at any time. As a result, the applications based on these quickly shared data are limitless.

Procedure
PART A - Installing Node.js

1. Download the Node.js ‘.msi’ installer at https://nodejs.org/en/download/.

4/12
2. Run the Node.js installer and follow the steps below:

3. Make sure enable the installation of the necessary tools.

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

Part B - MQTTBox Installation

1. Open Microsoft Store app in Windows.


2. Search the store using “mqttbox” keyword.
3. Download and install the MQTTBox app.

PART C - Installing Node-RED

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:

npm install -g --unsafe-perm node-red

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.

Part D - Starting a Flow

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:

ii. Modify the Name and Topic. Click Done to finish.

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.

7. Click “open dashboard” as shown. What can you see?

Part E - Create MQTT Client

1. Start MQTTBox app and click “Create MQTT Client”.

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.

4. Use these lines in the Topic to publish field:


 lab4/esp32/room1/temperature for the publisher and subscriber.

5. Click Subscribe button on both subscribers.

6. Go to Payload field in both publishers, insert a value, and click Publish.

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.

PART E - Problem Based Learning

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

You might also like