Tap to Read ➤

Internet of Things - Message Queue Telemetry Transport (MQTT) protocol

Nilesh Parakh Jul 15, 2019

Message Queue Telemetry Transport (MQTT) Protocol

MQTT is a data centric publish/subscribe model based lightweight messaging protocol for M2M communication. Data transfer in byte array format, higher reliability, high delivery guarantee, model that allows clients to exist independent from one another and its usability in resource constrained environment makes MQTT one of the best suited protocol for IoT.

Versions and Variants

MQTT protocol has following main versions:
  • MQTT v3.1
  • MQTT v3.1.1
  • MQTT v5
v3.1.1 can be termed as most widely and successfully used version.
MQTTv5 was approved in January 2018 and has not yet been adopted as much as v3.1.1
MQTT-SN is a variant of MQTT protocol that was developed for embedded devices on non-TCP/IP networks such as ZigBee, UDP and others.

Some MQTT Terminologies

  • Topic - A topic is a subject of interest for which information is being sent by a publisher
  • Session - interaction between client and server with both or one of them maintaining state of the previous interactions
  • Subscription - A subscription is a subject of interest, the information of which is requested by a subscriber.

Some MQTT Terminologies...

  • Publish - A declaration of information availability by a client and act of sending it to a broker for other clients is called publish.
  • Client - A client is an entity/IoT device or program that use MQTT protocol to publish or subscribe application message. The client communicates with server to indicate its willingness to communicate with other clients.

Some MQTT Terminologies...

  • Server - A server is an entity/IoT device or a program that accepts network connection requests, application messages, subscription requests, network disconnection and subscription closure requests from clients and processes them. A server is often called as a “Broker”.

How MQTT Works?

An MQTT session between publisher and subscriber consists of following 4 stages:

1) Connect - Client creates TCP/IP based connection to the server/broker through port 1883 for non-encrypted and port 8883 for encrypted communication.

2) Authenticate - Once connection is established, broker-client handshake takes place. If client provides a client certificate to the broker, broker can use it to authenticate the client.

...

3) Communicate - Messages are sent and received between publisher and subscribers in the form of packets. Each message consists a fixed header, an optional variable header, a payload (BLOBS of up to 256 MB) and QoS level.

4) Terminate - Publisher or subscriber can terminate the session by sending request to the broker through DISCONNECT message.

There are some drawbacks of MQTT protocol:

1) It heavily depends on SSL/TLS for secure communication.
2) Not highly interoperable
3) It is meant to work in secure environment and is used for specific purposes.
4) Increasing complexity in topic structures poses challenge for implementation of globally scalable MQTT network.
5) There is no way a receiver can come to know who sent the information.

Thank you!

Stay tuned for in-depth video tutorials on IoT, AI and ML.