Winter Tickets Salel Aptitude Engineering Mathematics Discrete Mathematics Operating System DBMS Computer Networks Digital L
Introduction of Message Queue Telemetry Transport Protocol
(MQTT)
Last Updated: 26 Feb, 2024
Message Queuing Telemetry Transport, or MQTT, is a communications protocol designed for
Internet of Things devices with extremely high latency and restricted low bandwidth. Message
Queuing Telemetry Transport is a perfect protocol for machine-to-machine (M2M) communication
since it is designed specifically for low-bandwidth, high-latency settings.
What is Message Queue Telemetry Transport Protocol(MQTT)?
MQTT 0s a simple, lightweight messaging protocol used to establish communication between
multiple devices. It is a TCP-based protocol relying on the publish-subscribe model. This
communication protocol is suitable for transmitting data between resource-constrained devices
having low bandwidth and low power requirements. Hence this messaging protocol is widely used
for communication in the loT Framework.
Publish-Subscribe Model
This model involves multiple clients interacting with each other, without having any direct
connection established between them. All clients communicate with other clients only via a third
party known as a Broker.
MQTT Client and Broker
Clients publish messages on different topics to brokers. The broker is the central server that
receives these messages and filters them based on their topics. It then sends these messages to
respective clients that have subscribed to those different topics. The heart of any publish/subscribe
protocol is the MQTT broker. A broker can handle up to thousands of concurrently connected MQTT
customers, depending on how it is implemented. All communications must be received by the
broker, who will then sort them, ascertain who subscribed to each one, and deliver the messages to
the clients who have subscribed. All persistent customers' sessions, including missed messages
and subscriptions, are likewise kept by the Broker.
Subscriber
Publisher Publish Client
Publish
Client
Subscribe
Publish Publish
Publisher Subscriber
Client BROKER Client
Subscribe
Publist Publish
Subscribe
Publishet Subscriber
Client Client
Publish-Subscribe Model
Hence client that has subscribed to a specific topic receives all messages published on that topic.
Here the broker is central hub that receives messages, filters them, and distributes them to
appropriate clients, such that both message publishers, as well as subscribers, are clients.
Working of MQTT
MQTT'S publish/subscribe (pub/sub) communication style, which aims to maximise available
bandwidth, is an alternative to conventional client-server architecture that communicates directly
with an endpoint. In contrast, the client who transmits the message (the publisher) and the client or
clients who receive it (the subscribers) are not connected in the pub/sub paradigm. Third parties
the brokers-manage the relationships between the publishers and subscribers because they don't
communicate with one another directly.
Publishers and subscribers, which denote whether a client is publishing messages or has
subscribed to receive messages, are examples of MQTT clients. The same MQTT client can be used
to accomplish these two features. A publish occurs when a client or device want to submit data to a
server or broker.
The term "subscribe" refers to the reversal of the procedure. Several clients can connect to a broker
Open In App
Winter Tickets Salel Aptitude Engineering MathematicsDiscrete Mathematics Operating System DBMS Computer Networks Digital L
Publish-Subscribe Model
Hence client that has subscribed to a specific topic receives all messages published on that topic.
Here the broker is central hub that receives messages, filters them, and distributes them to
appropriate clients, such that both message publishers, as well as subscribers, are clients.
Working of MQTT
MQTT's publish/subscribe (pub/sub) communication style, which aims to maximise available
bandwidth, is an alternative to conventional client-server architecture that communicates directly
with an endpoint. In contrast, the client who transmits the message (the publisher) and the client or
clients who receive it (the subscribers) are not connected in the pub/sub paradigm. Third parties
the brokers-manage the relationships between the publishers and subscribers because they don't
communicate with one another directly.
Publishers and subscribers, which denote whether a client is publishing messages or has
subscribed to receive messages, are examples of MQTT clients. The same MQTT client can be used
to accomplish these tWo features. A publish occurs when a client or device want to submit data to a
server or broker.
The term "subscribe" refers to the reversal of the procedure. Several clients can connect to a broker
under the pub/sub paradigm and subscribe to subjects that interest them.
Connect
Connect Ace
MQTT
Subscribe
MQTT
Subscribe Ack
CLIENT BROKER
Publish
Publish Ack
introduction of Message Queue Tolematry Transport Protocol (MQTT)
MQTT
When a broker and a subscribing client lose contact, the broker will store messages in a buffer and
send them to the subscriber whenever the broker is back up and running. The broker has the right
to cut off communication with subscribers and send them a cached message containing publisher
instructions if the publishing client abruptly disconnects from the broker.
"Publishers send the messages, subscribers receive the messages they are interested in, and
brokers pass the messages from the publishers to the subscribers," reads an IBM write-up
describing the pub/sub paradigm. MQTT clients, such as publishers and subscribers, can only speak
with MQTT brokers. Any device or programme that runs a MQTT library can be a MQTT client,
ranging from microcontrollers like the Arduino to entire application servers housed in the cloud.
Apphaton
Topic
Sy
publche subscrton mattn
(t-at snc) Sivice.
mss ba5k
koap mg als
int
Tep|Ip
sobso-tion
TApplchat
MÌ TT
Iiternet Teplß
Iiterct in tp
X
Goggle applications of mgt in iot
Here are some applications of MQTT in loT:
Smart cities
MOTT is used in smart city applications like smart transportation, smart healthcare.
smart buildings. smart homes, and smart meters.
Connected cars
MOTT is used in connected car systems for real-time dataexchange, including vehicle
diagnostics. navigation,and infotainment. e
Medical devices
MOTT iS used in medical devices and health monitoring systems for real-time
transmission of patient data.
Industrial loT
MOTT is used for messaging and data exchange between loT and industrial loT (loT)
devices.
4. Smart Cities:
" Applications:
" Managing traffic lights, streetlights, and waste bins.
Example: Asmart streetlight sending energy consumption data to a centralized controller.
5. Agriculture:
" Applications:
" Monitoring soil moisture, temperature, and humidity.
Example: Sensors in afield publishing environmental data to optimize irrigation.
6. Connected Vehicles:
" Applications:
"Real-time updates about vehicle cunditions.
1. Simplicity and Readability:
Easy to Learn: Python's syntax is straightforward, making it accessible to
both beginners and experienced programmers.
Quick Development: Its concise nature allows for rapid prototyping and
development.
2. Extensive Libraries and Frameworks:
RPi.GPIO: Directly controls GPIO pins for interfacing with hardware.
" Adafruit_Blinka: Simplifies interaction with various sensors and actuators.
Requests: Facilitates communicationwith web services.
MQTT: Enables device-to-device communication using the MQTT protocol.
WebSockets: Supports real-time data exchange between devices and
servers.
3. Cross-Platform Compatibility:
Runs Anywhere: Python code can be executed on different operating
systems, including Raspberry Pi, making it highly versatile.
4.Strong Community and Support:
Active Community: A large and active community provides extensive
resources and assistance.
Numerous Tutorials and Documentation: A wealth of information is
available tohelp you learn and troubleshoot.
5. Efficient Resource Utilization:
Optimized Memory Management: Python is designed to use system
resources efficiently, making it suitable for resource-constrained devices like
Raspberry Pi.
6. High-Level Abstraction:
Simplified Hardware Interaction:Python libraries often provide high-level
abstractions,reducing the need for low-level programming.
" Focus on Core Logic: Developers can concentrate on the core functionality
of their loT applications.
In essence, Python's combination of simplicity, versatility, and a rich ecosystem
makes it an ideal choice for developing loT applications on Raspberry Pi. It
empowers developers to create innovative and efficient solutions for awide range
of loT use cases.
Why Python for loT?
Python is favored for loT due to its simplicity, readability, and a rich ecosystem of libraries. Python
is a popular choice for developing Internet of Things (loT) applications due to several compelling
advantages:
" Simplicity and Readability: Python's syntax is clear and concise, making it easy to learn and
use, especially for beginners.
" Extensive Libraries and Frameworks: Python has a vast ecosystem of libraries and frameworks
that can significantly accelerate loT development. Libraries like NumPy and Pandas facilitate
data analysis.
" Platform Independence: Python is a cross-platform language, meaning it can run on various
operating.systems including Windows, macOS, Linux, and even on smaller devices like
Raspberry Pi, which is popular for loT projects.
" Community Support: Python has one of the largest programming communities, providing
extensive support through forums, tutorials, and third-party software.
" Integration Capabilities: Python integrates well with other languages and technologies, which
is vital in the loT landscape where different types of technologies and protocols must work
together seamlessly.
" Prototyping Speed: Python enables rapid prototyping-crucial in loT development where
adjusting to new requirements and testing ideas quickly can significantly cut down development
time and cost.
" Data Handling and Analytics: loT devices generate massive amounts of data, and Python's
capabilities in handing and analyzing data are well-established. With libraries like Matplotlib
for data visualization and Scikit-Learn for machine learning.
Python Platforms for loT Development
1. Python on Raspberry Pi
2. Python on PyBoard
3. SP8266 and ESP32 with MicroPython
Pvthon Rasnherry P;
What is Message Queue Telemetry Transport Protocol(MQTT)?
MQTT is a simple, lightweight messaging protocol used to establish communication between
multiple devices. It is a TCP-based protocol relying on the publish-subscribe model. This
communication protocol is suitable for transmitting data between resource-constrained devices
having low bandwidth and low power requirements. Hence this messaging protocol is widely used
for communication in the loT Framework.
Exome:tetght
subscntho
MOTT
Mam Tepl mqTT
dalo dot
gdesiay Natok
ia t
dete
ublao
sata
doflito Sugpot 48pla
Lau Thansjt
Components in the Diagram:
1. Street Light Groups (Publisher):
The streetlights are organized into groups (e.g.. Street Light Group 1and Street Light
Group 2).
I to monitor and control the streetlights (e.g.,
These qroups have sensors or controlfers
turning them on/off, adjusting brightness).
These sensors publish data (such as light status or energy consumption) to the MQTT server
through a gateway.
2. loT/M2M Gateway:
" The loT/Machine-to-Machine (M2M) gateway serves as an intermediary between the
streetlight groups and the MQTT network.
" It collects data from the streetlight se1sors and forwards it to the TCP//P network.
Sodio ChatGPT
" It may also receive controlcommands from the server (via MQTT) to operate the streetlights
(e.g., turning on/off or dimming lights).
3. TCP/IP Network:
" The TCP/IP network provides the communication infrastructure for transmitting data
between the gateway, MQTT server (boker), and other devices.
" It ensures reliable delivery of both sensed data (from the streetlights) and control data
(from the centralized controller).
4. MQTT Server (Broker):
Acts as the central hub for communication in the MQTT protocol.
" Responsibilities:
Receives data published by the straetlight groups (via the gateway).
" Filters and forwards messages to MQTT clients that have subscribed to relevant topics.
SOdáo ChatGPT
" Sends control commands (from the centralized controller) to the streetlight groups.
5. MQTT Clients (Subscriber):
" These represent applications or devices that subscribe to specific topics to receive updates
about the streetlights.
" For example, a dashboard applicationfor monitoring the status of allstreetlights might
subscribe to topics like "streetlight/status".
6. Application Service Layer:
" This is the user interface or service layer where users(e.g., city administrators) can monitor
and control the streetlights.
" It integrates with the MQTT client to receive real-time updates and issue commands.
" Example functionality:
Displaying real-time streetlight sluus (on/off, brightness levels).
KOsáo ChatGPT
" Sending commands to turn specific streetlight groups on or off.
7. Application Centralized Controller (Cloud):
A
cloud-based system or centralized controller processes all incoming data and issues
commands to the streetlights.
" Itmay.
Analyze data (e.g., detect anomalies like failed lights or energy inefficiency).
Generate automated control commands based on pre-set rules (e.g., turn lights on at
sunset).
" Store historical data for future analysis.
Example Use Case:
ambient light levels.
1. Atsunset, sensors in Street Light Group 1 detect low
"streetlight/status".
2. The sensors publish this data to the topic
centralized controller and any subscribed clients
3. The MQTT broker forwards this data to the
(e.g. monitoring applications).
on the lights in Group 1 by publishing to
4. The centralized controller issues a command to turn
the topic "streetlight/control".
activates the lights in Group 1.
5. The gateway receives the command and
ARS fo MTT
|M9tt. onnect C )
mgtt. onnect # cl'ent
mqtt chest # Subecit be
mgt. clert t nsvbscaibe
mgtt.stee.
Winter TicKets Sate:
What is a Constrained Application Protocol?
The constrained application protocol is client-server-based. With this protocol, the COAP packet
can be shared between different client nodes which are commanded by the COAP server. The
server is responsible for sharing the information depending on its logic but has not acknowledged
it. This is used with the applications which support the state transfer model.
Characteristics of COAP
UDP-Based: CoAP uses UDP(User Datagram Protocol) instead of TCP, making it suitable for
limited resources and networks.
" HTTP-Like Semantics: COAP employs HTTP-like methods (GET, POST, PUT, DELETE) for
interactions.
" Multicast Support: CoAP includes UDP's multicast feature, which TCP lacks.
"Low Overhead: CoAP minimizes protocol overhead for efficient communication in constrained
environments
What is Message Queuing Telemetry Transport?
Message Queuing Telemetry Transport is a communication-based protocol used for loT devices.
MQTT is a simple, lightweight messaging protocol used to establish communication between
multiple devices. It is a TCP-based protocol relying on the publish-subscribe model. This
communication protocol is suitable for transmitting data between resource-constrained devices
having low bandwidth and low power requirements. Hence this messaging protocol is widely used
for communication in the loT Framework.
Characterstics of MQTT
" Publish-Subscribe Model: MQTT operates on a publish-subscribe model, where publishers send
messages to topics, and subscribers receive those messages.
" Lightweight: MQTT minimizes data packet size, making it ideal for bandwidth-constrained
environments.
" Retained Messages: MQTT allows retaining the most recent message for a topic.
" Last Will and Testament: If a client disconnects abruptly, a pre-defined "last will" message is
sent to subscribers.
" Session Management: MQTT Supports re-establishing sessions after connection loss
Difference between COAP and MQTT protocols
Basis of COAP MQTT
Abbreviation Message Queuing Telemetry
Constrained Application Protocol
Transport
Communication Type It uses Request-Response model. It uses Publish-Subscribe model
Messaging Mode This uses both Asynchronous and
This uses only Asynchronous
Synchronous.
Transport layer This mainly uses User Datagram This mainly uses Transmission
protocol protocol(UDP) Controlprotocol(TCP)
Header size It has 4 bytes sized header It has 2 bytes sized header
RESTful based No it does not uses REST
Yes it uses REST principles
principles
Persistence support It supports and best used for live
It does not has such support
data communication
Message Labelling It provides by adding labels to the It has no such feature.
messages.
Usability/Security It is used in Utility area networks and It is used in loT applications and is
has secured mechanism. secure
Effectiveness Effectiveness in LNN is excellent. Effectiveness in LNN is low.
Communication Communication model is many
Communication model is one-one.
Model many.
Conclusion