MQTT Docs
MQTT Docs
MQTT Docs
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.
Space decoupling
The publisher and subscriber are not aware of each other’s network location and do not exchange
information such as IP addresses or port numbers.
Time decoupling
The publisher and subscriber don’t run or have network connectivity at the same time.
Synchronization decoupling
Both publishers and subscribers can send or receive messages without interrupting each other. For
example, the subscriber does not have to wait for the publisher to send a message.
MQTT client
An MQTT client is any device from a server to a microcontroller that runs an MQTT library. If the client is
sending messages, it acts as a publisher, and if it is receiving messages, it acts as a receiver. Basically,
any device that communicates using MQTT over a network can be called an MQTT client device.
MQTT broker
The MQTT broker is the backend system which coordinates messages between the different clients.
Responsibilities of the broker include receiving and filtering messages, identifying clients subscribed to
each message, and sending them the messages. It is also responsible for other tasks such as:
MQTT connection
Clients and brokers begin communicating by using an MQTT connection. Clients initiate the connection by
sending a CONNECT message to the MQTT broker. The broker confirms that a connection has been
established by responding with a CONNACK message. Both the MQTT client and the broker require a
TCP/IP stack to communicate. Clients never connect with each other, only with the broker.
MQTT topic
The term ‘topic’ refers to keywords the MQTT broker uses to filter messages for the MQTT clients. Topics
are organized hierarchically, similar to a file or folder directory. For example, consider a smart home
system operating in a multilevel house that has different smart devices on each floor. In that case, the
MQTT broker may organize topics as:
ourhome/groundfloor/livingroom/light
ourhome/firstfloor/kitchen/temperature
MQTT publish
MQTT clients publish messages that contain the topic and data in byte format. The client determines the
data format such as text data, binary data, XML, or JSON files. For example, a lamp in the smart home
system may publish a message on for the topic livingroom/light.
MQTT subscribe
MQTT clients send a SUBSCRIBE message to the MQTT broker, to receive messages on topics of interest.
This message contains a unique identifier and a list of subscriptions. For example, the smart home app on
your phone wants to display how many lights are on in your house. It will subscribe to the topic light and
increase the counter for all on messages.
Is MQTT secure?
MQTT communication uses SSL protocol to protect sensitive data transmitted by IoT devices. You can
implement identity, authentication, and authorization between clients and the broker using SSL
certificates and/or passwords. The MQTT broker typically authenticates clients using their passwords as
well as unique client identifiers it allocates to each client. In most implementations, the client
authenticates the server with certificates or DNS lookups. You can also implement encryption protocols
with MQTT.