spot_img

A Messaging Protocol for IoT Devices: MQTT

KENAN ŞAHİN
R&D AND TECHNICAL SUPPORT ENGINEER

MQTT, a messaging protocol for IoT devices with limited networks (low bandwidth) and high latency, uses the “publish and subscribe” communication model. MQTT, which is usually preferred as “machine-to-machine” (M2M), plays a major role for Internet of things (IoT).

Created as a low-cost protocol to adapt to bandwidth and CPU limitations, MQTT is designed to run in an embedded environment where it can provide a reliable and efficient way for communication. MQTT is a good choice for wireless networks that occasionally experience varying levels of latency due to bandwidth restrictions or unreliable connections. This protocol is applied in many sectors, from automotive to energy and telecommunications.

The publish/subscribe (pub/sub) communication model of MQTT, which aims to maximize the available bandwidth, is an alternative to the traditional client-server architecture that communicates directly with an endpoint. In contrast, in the pub/sub model, the client (publisher) sending a message is separated from the client(s) (or subscribers) receiving the messages. Since neither publishers nor subscribers communicate directly with each other, the third parties (agents) take care of the connections between them. When a device (client) wants to send data to a server (agent), this is called “publishing”. When the transaction is reversed, it is called “subscriber”. Under the pub/sub model, multiple clients can connect to an agent and subscribe to their subjects of interest. If the connection from a subscribed client to an agent breaks, the agent caches the messages and sends them to the subscriber when the connection is recovered. If the connection from the publishing client to the agent is interrupted without any notice, the agent can close the connection and send the “cached” message to subscribers with instructions from the publisher.

MQTT

An MQTT broker acts as an agent for clients sending messages and subscribers receiving these messages. In a post-office analogy, the broker is the post office itself. All messages must pass through the broker before being delivered to the subscriber. Agents may need to handle millions of simultaneously connected MQTT clients. Therefore, when choosing an MQTT agent, the companies should do this based on their scalability, integration, monitoring, and fault tolerance capabilities. Advantages and Disadvantages of MQTT:
MQTT offers both advantages and disadvantages compared to other protocols.

  • Fast due to efficient data transmission and a lightweight protocol,
  • Low network usage due to minimized data packets,
  • Efficient data distribution,
  • Successful implementation of remote sensing and control,
  • Fast and efficient message delivery,
  • Low power consumption for the connected devices,
  • Optimized network width.
  • MQTT has slower transmission cycles compared to Constrained Application Protocol (CoAP).
  • While MQTT’s resource discovery works based on flexible subject subscription, CoAP uses a fixed resource discovery system.
  • MQTT is not encrypted. Instead, it uses TLS/SSL (Transport Layer Security/Secure Sockets Layer) for security encryption.
  • It is difficult to create a globally scalable MQTT network.

Due to its lightweight features, MQTT works well for applications involving many types of remote monitoring, including the following.

  • Synchronization of sensors, such as fire detectors to determine whether a hazard is present or motion sensors for theft detection.
  • Monitoring the health parameters using sensors for patients leaving the hospital,
  • Sensors that warn people of the dangers.

As another application example, it is a text-based messaging application for real-time communication that takes advantage of MQTT’s low data and energy usage. For instance, Facebook uses MQTT for its Messenger application, since this protocol not only saves battery power during mobile-to-mobile messaging but also allows messages to be delivered efficiently in milliseconds, despite inconsistent internet connections around the world.

Most major cloud service providers support MQTT, including Amazon Web Services (AWS), Google Cloud, IBM Cloud, and Microsoft Azure.

MQTT is very suitable for applications that use M2M and IoT devices for purposes such as real-time analytics, preventive maintenance and monitoring in environments such as smart homes, healthcare, logistics, industry and manufacturing.

MQTT