Message Queuing Telemetry Transport – MQTT
Already in the late 1990s, IBM was developing a very lean and simple communication protocol for monitoring oil pipelines. From this endeavor, MQTT (Message Queue Telemetry Transport) arose, which is now enjoying growing popularity in the wake of the Internet of Things. In 2014 MQTT was in version 3.1.1. when being adopted as an official standard by the standardization organization OASIS.
Message Queuing Telemetry Transport is a message protocol for restricted networks (low bandwidth) and IoT devices with extremely high latency. Since Message Queuing Telemetry Transport specializes in low-bandwidth, high-latency environments, it is an ideal protocol for machine-to-machine communication (M2M). In IoT, MQTT is used for connections into cloud environments. Find out everything you need to know about the use of MQTT in our practical explanation with an industrial focus.
The MQTT high-level architecture
Message Queuing Telemetry Transport sends data from a large number of machines to a single destination – the cloud – where the data can be analyzed, interpreted and forwarded. The cloud houses an MQTT broker – an intermediary between machines and other machines and / or people. And this is an important distinction, as the machines do not communicate with each other directly, but rather through the broker.
MQTT uses the concept of „topics“ to organize its data and a publish / subscribe model to communicate the topics to other parties via the cloud.
For example: An air conditioning system sends (or publishes) data on the “health status” of its compressors to the cloud. Any interested party with approved credentials – machine or human – can subscribe to this topic to receive the information. Subscribers can be maintenance technicians (people), parts procurement systems (software / machine) or maintenance planning systems (software / machine).
Suddenly every aspect of a machine’s lifecycle is available for scrutiny, and this is an exciting and in-depth opportunity to connect with that information to find bugs, cut costs, improve efficiency, and plan for the Internet of the world to do things.
The MQTT Protocol
It stands for Message Queuing Telemetry Transport. It’s an extremely simple and lightweight subscribe and publish messaging protocol designed for limited devices and networks with high latency, low bandwidth, or unreliable networks. The design principles serve to reduce the requirements for the network bandwidth and the resources of devices and to be able to guarantee the security of the supply. In addition, these principles are advantageous for M2M (machine-to-machine) or IoT devices, since battery performance and bandwidth are very important.
MQ Telemetry Transport enables resource constrained IoT devices to send or publish information on a specific topic to a server that acts as an MQTT message broker. The broker then transmits the information to those clients who have previously subscribed to the client’s topic. To a human, a subject looks like a hierarchical file path. Clients can subscribe to a specific hierarchy level of a topic or use a wildcard character to subscribe to multiple levels. The MQTT protocol is a good choice for wireless networks that have variable latency times due to occasional bandwidth constraints or unreliable connections. If the connection from a subscribing client to a broker is interrupted, the broker buffers the messages and sends them to the subscriber when he is back online. If the publishing client disconnects from the broker without notification, the broker can disconnect and send a cached message to the subscriber with instructions from the publisher.
MQTT topic
The word Topic refers to a UTF-8 string that the broker uses to filter messages for each connected client. The topic consists of one or more topic levels. Each topic level is separated by a slash (topic level separator). Compared to a message queue, MQTT topics are very simple. The client does not need to create the desired topic before posting or subscribing to it. The broker accepts any valid topic without prior initialization. Note that each topic must contain at least one character and that the topic string allows spaces. The topics are case-sensitive. For example, _myhome/temperature and _MyHome/Temperature are two different topics. Also, the slash on its own is a valid topic.
The MQTT Broker
The MQTT broker is at the heart of the MQTT publish/subscribe protocol. Depending on the implementation, a broker can manage up to thousands of simultaneously connected MQTT clients. The broker is responsible for receiving all messages, filtering the messages, determining who has subscribed to each message, and delivering the message to those subscribed clients. The broker also holds the sessions of all persistent clients including subscriptions and missed messages. Another task of the broker is the authentication and authorization of clients. Usually the broker is extensible, which facilitates custom authentication, authorization and integration with backend systems. The integration is particularly important because the broker is often the component directly exposed on the Internet, serves many clients and has to forward messages to downstream analysis and processing systems. In short, the broker is the central hub through which every message must be routed.