0% found this document useful (0 votes)
300 views8 pages

MQTT Protocol

MQTT is a lightweight messaging protocol that is commonly used for IoT applications and machine-to-machine communication. It uses a publish/subscribe model where clients publish messages to topics and other clients subscribe to topics to receive messages. MQTT is efficient for constrained networks and devices because it has a small overhead and supports different quality of service levels. It uses a broker to facilitate communication between clients, which do not communicate directly with each other. MQTT is well-suited for home automation and IoT projects where devices can publish sensor data to topics and other devices like a Raspberry Pi running Node-RED can subscribe to display the data or control actuators based on the messages.

Uploaded by

rajzgopalz
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
300 views8 pages

MQTT Protocol

MQTT is a lightweight messaging protocol that is commonly used for IoT applications and machine-to-machine communication. It uses a publish/subscribe model where clients publish messages to topics and other clients subscribe to topics to receive messages. MQTT is efficient for constrained networks and devices because it has a small overhead and supports different quality of service levels. It uses a broker to facilitate communication between clients, which do not communicate directly with each other. MQTT is well-suited for home automation and IoT projects where devices can publish sensor data to topics and other devices like a Raspberry Pi running Node-RED can subscribe to display the data or control actuators based on the messages.

Uploaded by

rajzgopalz
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 8

MQTT protocol

MQTT stands for Message Queuing Telemetry Transport. MQTT is a standards-based


messaging protocol, or set of rules, used for machine-to-machine communication. Smart sensors,
wearables, and other Internet of Things (IoT) devices typically have to transmit and receive data
over a resource-constrained network with limited bandwidth. These IoT devices use MQTT for data
transmission, as it is easy to implement and can communicate IoT data efficiently. MQTT supports
messaging between devices to the cloud and the cloud to the device.

Characteristics of MQTT

Lightweight and efficient


MQTT implementation on the IoT device requires minimal resources, so it can even be used on
small microcontrollers. For example, a minimal MQTT control message can be as little as two data
bytes. MQTT message headers are also small so that you can optimize network bandwidth.

Scalable
MQTT implementation requires a minimal amount of code that consumes very little power in
operations. The protocol also has built-in features to support communication with a large number of
IoT devices. Hence, you can implement the MQTT protocol to connect with millions of these devices.

Reliable
Many IoT devices connect over unreliable cellular networks with low bandwidth and high latency.
MQTT has built-in features that reduce the time the IoT device takes to reconnect with the cloud. It
also defines three different quality-of-service levels to ensure reliability for IoT use cases— at most
once (0), at least once (1), and exactly once (2).

Secure
MQTT makes it easy for developers to encrypt messages and authenticate devices and users using
modern authentication protocols, such as OAuth, TLS1.3, Customer Managed Certificates, and
more.

Well-supported
Several languages like Python have extensive support for MQTT protocol implementation. Hence,
developers can quickly implement it with minimal coding in any type of application.
History of MQTT
The MQTT protocol was invented in 1999 for use in the oil and gas industry. Engineers needed a
protocol for minimal bandwidth and minimal battery loss to monitor oil pipelines via satellite. Initially,
the protocol was known as Message Queuing Telemetry Transport due to the IBM product MQ
Series that first supported its initial phase. In 2010, IBM released MQTT 3.1 as a free and open
protocol for anyone to implement, which was then submitted, in 2013, to Organization for the
Advancement of Structured Information Standards (OASIS) specification body for maintenance. In
2019, an upgraded MQTT version 5 was released by OASIS. Now MQTT is no longer an acronym
but is considered to be the official name of the protocol.

MQTT Architecture
MQTT runs on top of TCP/IP using a PUSH/SUBSCRIBE topology. In MQTT architecture,
there are two types of systems: clients and brokers. A broker is the server that the
clients communicate with. The broker receives communications from clients and sends
those communications on to other clients. Clients do not communicate directly with
each other, but rather connect to the broker. Each client may be either a publisher, a
subscriber, or both.

MQTT is an event-driven protocol. There is no periodic or ongoing data transmission.


This keeps transmission to a minimum. A client only publishes when there is
information to be sent, and a broker only sends out information to subscribers when
new data arrives.
The components of the MQTT.

○ Message

○ Client

○ Server or Broker

○ TOPIC

Message

The message is the data that is carried out by the protocol across the network for the
application. When the message is transmitted over the network, then the message
contains the following parameters:

1. Payload data

2. Quality of Service (QoS)

3. Collection of Properties
4. Topic Name

Client

In MQTT, the subscriber and publisher are the two roles of a client. The clients subscribe
to the topics to publish and receive messages. In simple words, we can say that if any
program or device uses an MQTT, then that device is referred to as a client. A device is a
client if it opens the network connection to the server, publishes messages that other
clients want to see, subscribes to the messages that it is interested in receiving,
unsubscribes to the messages that it is not interested in receiving, and closes the
network connection to the server.

In MQTT, the client performs two operations:

● Publish: When the client sends the data to the server, then we call this operation
as a publish.

● Subscribe: When the client receives the data from the server, then we call this
operation a subscription.

Server

The device or a program that allows the client to publish the messages and subscribe to
the messages.

A server

● accepts the network connection from the client,

● accepts the messages from the client,

● processes the subscribe and unsubscribe requests,

● forwards the application messages to the client,


● closes the network connection from the client.

TOPIC

The label provided to the message is checked against the subscription known by the
server is known as TOPIC.

An overview of how MQTT works is given below.

1. An MQTT client establishes a connection with the MQTT broker.

2. Once connected, the client can either publish messages, subscribe to specific messages, or
do both.

3. When the MQTT broker receives a message, it forwards it to subscribers who are interested.

To understand it more clearly, we will look at the example. Suppose a device has a
temperature sensor and wants to send the rating to the server or the broker. If the phone
or desktop application wishes to receive this temperature value on the other side, then
there will be two things that happened. The publisher first defines the topic; for example,
the temperature then publishes the message, i.e., the temperature's value. After
publishing the message, the phone or the desktop application on the other side will
subscribe to the topic, i.e., temperature and then receive the published message, i.e., the
value of the temperature. The server or the broker's role is to deliver the published
message to the phone or the desktop application.
How to Use MQTT in Home
Automation and IoT Projects
MQTT is great for home automation and internet of things projects. Here’s an
example of how it can be used in a Home Automation System built with
low-cost development boards like a Raspberry Pi, ESP32, ESP8266, and
Arduino.

■ A Raspberry Pi runs the Mosquitto broker, which is essential for


MQTT protocol.
■ The same Raspberry Pi runs Node-RED, which is a Home
Automation Platform with MQTT support—this means it can
subscribe to topics to receive messages from the other IoT
devices, and publish messages on specific topics to send
messages to other devices.
■ Node-RED also allows you to build an User Interface with buttons
to control outputs and charts to display sensor readings.
■ The Arduino, the ESP32 and ESP8266 can act as MQTT clients
that publish and subscribe to topics.
■ These boards are connected to actuators like LEDs or relays, and
sensors like temperature, humidity, smoke sensors, etc..
■ These boars can publish data about the sensor’s state on a specific
topic, that Node-RED is also subscribed to. This way, Node-RED receives
the sensor readings and can display them on the user interface.
■ On the other side, Node-RED can publish data on a specific topic to
control outputs when you use the buttons on the interface. The
other boards are also subscribed to that topic and control the
outputs accordingly.

You might also like