MQTT 101, Why use MQTT?

MQTT (MQ Telemetry Transport) is a lightweight publish/subscribe messaging protocol. It is based on the existing widely used TCP/IP and connect various IoT and IIoT devices with servers and consumers. MQTT is an open and standardized protocol and widely used for machine-to-machine (M2M) and the Internet of Things (IoT) application because it is easy to adopt for the wide variety of IoT devices, platforms, and operating systems.

    1. Security. MQTT relies on TCP as transport protocol. In order to keep the MQTT as lightweight as possible, the MQTT use TCP transport layer security (TLS) for data communication encryption.
    2. Quality of Service (QoS). The MQTT offers 3 different levels of QoS. The highest level is designed for critical application to receive all the message.
        • QoS 0: For a complete or almost stable connection network environment. One of the example is connecting a client to MQTT broker over a wired network.
        • QoS 1: This level guarantees the message delivered at least once. The application must be tolerate duplicate messages and process the accordingly. QoS 1 is much faster in delivering message with the guarantee of QoS 2.
        • QoS 2: Ideal for mission critical application. The receiver will receive all messages exactly once. However, it takes a longer time than QoS 1 to complete the QoS 2 flow. This is the most secure level of publishing messages.
    3. Central Broker: Millions or even billions devices will be connected in the next few years, and the data transmission will be even much much more. With all the data on the network, the MQTT broker can act as a server to reduce the number of data packets which can’t be handle by most of the devices due to the process power, memory, or other resources. The broker is primarily responsible for receiving all messages, filtering the message, decide who is interested in it and then sending it to all subscribed clients. When a client gets new data, it publishes it to the topic and send to the broker. Since only the devices interesting in the data will receive the data, it reduces the unnecessary data transmission on the network.
    4. Last Will & Testament: Devices may disconnected for lots of reasons. The Last Will & Testament (LWT) messages are about what happens after the clients has gone offline. For example, if a device disconnect due to the lack of KeepAlives message, the LWT trigger an urgent topic which is to sending a SMS message with sensor ID to the user.
    5. Flexible Subscription pattern: A particular client can subscribe to all the topics published based on a pattern. For example, a monitor for the house can subscribe to all the temperature level of the house, or listen to all the topics related to the kitchen.