Professional Documents
Culture Documents
20BCP299 - Charmi Shah - Exp-3 - Iot Lab
20BCP299 - Charmi Shah - Exp-3 - Iot Lab
Aim: Aim: Designing the Publish Subscribe system using MQTT and Paho on
Mosquitto Broker
Theory:
MQTT:
MOSQUITTO BROKER:
PAHO:
Steps:
1. Open terminal and install paho mqtt client with this command
• pip3 install paho-mqtt
2. To run mosquitto broker run this command in terminal
• Mosquito -v
3. To test if the mosquitto runs or not type this command in terminal
1
• Mosquitto_sub -t test/status
4. Then navigate to location where the python file is present in terminal and
run the python file
• Python3 pythonfilename.py
Python code
import sys
client = paho.Client()
client.on_message = onMessage
sys.exit(-1)
client.subscribe("test/status")
try:
print("Sweta,Siwani,Tarang,Ckewyn,Chaitanya")
client.loop_forever()
except:
2
print("Disconnectedfrom Broker")
client.disconnect()
Output:
3
Observation and Learning:
Observation:
1. Efficient Communication: MQTT (Message Queuing Telemetry Transport) proved
to be a robust and efficient protocol for implementing the Publish-Subscribe
architecture. It enabled seamless communication between devices while minimizing
network overhead.
2. Paho Library Ease: The Paho MQTT library, which provides client implementations
in various programming languages, demonstrated user-friendly APIs. This simplified
the process of connecting devices to the MQTT broker and handling publish-
subscribe interactions.
Learning:
1. Topic Design Significance: Thoughtful topic design is crucial. Clear and organized
topic structures ensure that messages are appropriately categorized and reach their
intended audience. It's essential to plan topics that reflect the system's architecture and
the types of data being exchanged.
2. QoS Levels Impact: Quality of Service (QoS) levels affect message delivery
guarantees. QoS 0 offers no assurance of delivery, QoS 1 ensures at least one
delivery, and QoS 2 guarantees exactly-once delivery. Selecting the appropriate QoS
level depends on the application's needs and potential network constraints.
4
Conclusion:
In conclusion combination of MQTT's efficiency, Paho's user-friendly interfaces, and the
reliability of the Mosquitto Broker showcased the strength of this architecture for IoT and
other distributed applications. Thoughtful topic design, understanding QoS levels, managing
client lifecycles, and implementing appropriate security measures are all essential aspects for
creating a robust and successful system.