What is MQTT? The role of MQTT in IoT

Tram Ho

Introduce

Internet of Things (abbreviated as IoT) is a scenario of the world, where each object, person is passed through a single network without the need for direct interaction between people, or people with computers. . The IoT has grown from the convergence of wireless technology, micro-mechatronic technology, and the Internet. Simply put, it is a set of devices capable of connecting to each other, to the Internet and to the outside world to do a certain job.

The IoT era requires a new connection protocol to ensure full support for real physical devices. To solve this problem, Message Queuing Telemetry Transport (MQTT) is gradually becoming popular.

What is MQTT?

Define

  • MQTT (Message Queuing Telemetry Transport) is a publish / subscribe model message communication protocol, used for IoT devices with low bandwidth, high reliability and ability used in unstable networks. It is based on a “lightweight” Broker (rather less processing) and is designed to be open (ie not specific to any specific application), simple and easy. Setting.
  • MQTT is ideal in environments like:
    • Places where telecommunications network prices are expensive or bandwidth is low or unreliable.
    • When running on an embedded device is limited in speed and memory resources.
    • Because this protocol uses low bandwidth in high latency environments, it is an ideal protocol for M2M (Machine to Machine) applications.

      MQTT is also the protocol used in Facebook Messenger

History begin

  • MQTT was invented by Andy Stanford – Clark (IBM) and Arlen Nipper (EUROTECH) in late 1999 when their mission was to create a protocol so that the energy and bandwidth wasted was the lowest to connect to the Oil pipeline through the connection of satellites.
  • In 2011, IBM and Eurotech handed over MQTT to an Eclipse project called Paho.
  • In 2013 MQTT was submitted to OASIS (Organization for the Advancement of Structured Information Standards) for standardization.

H1

The position of MQTT in the IoT model

Some outstanding advantages of MQTT such as: low bandwidth, high reliability and can be used even when the network is unstable, it takes very few bytes to connect to the server and the connection can keep state. open throughout, can connect multiple devices (MQTT client) through an MQTT server (broker). Because this protocol uses low bandwidth in high latency environments, it is an ideal protocol for IoT applications.

H2

Features, outstanding features

  • Pub / Sub model messaging provides one-way distributed messaging, separate from the application part.
  • The transmission of the message is immediate, regardless of the transmitted content.
  • Use TCP / IP as the underlying protocol.
  • There are three levels of reliability for data transmission (QoS: Quality of service).
    • QoS 0: Broker / client will send the data exactly once, the sending is confirmed by only TCP / IP protocol.
    • QoS 1: Broker / client sends data with at least one acknowledgment from the other end, which means there can be more than 1 acknowledgment of data received.
    • QoS 2: Broker / client ensures that when sending data, the receiver only receives it once, this process has to go through 4 handshake steps.
  • The transmission data encapsulation is small and minimized to reduce the load on the transmission line.

Advantages of MQTT

With the above features and outstanding features, MQTT brings many benefits, especially in SCADA (Supervisory Control And Data Acquisition) system when accessing IoT data.

  • Communication is more efficient.
  • Increased scalability.
  • Significantly reduces network bandwidth consumption.
  • Very suitable for control and spying.
  • Maximize available bandwidth.
  • Low cost.
  • Very safe, secure.
  • Used in oil and gas industries, large companies like Amazon, Facebook, …
  • Save development time.
  • The publish / subscribe protocol collects more data and consumes less bandwidth than the old protocol.

Pub / Sub model and Operation Mechanism of MQTT

Pub / Sub model

1. Ingredients

  • Client
    • Publisher – Where to send messages
    • Subscriber – Where to receive messages
  • Broker – Broker server

In which Broker is considered as the center, it is the intersection point of all incoming connections from the Client (Publisher / Subscriber). Broker’s main task is to receive messages (messages) from Publisher, queue up and then move to a specific location. Broker’s side task is that it can take on a few additional communication-related features such as message security, message storage, logs, …

Clients are divided into two groups, Publisher and Subscriber. Client only does at least one of two things is to publish messages on one / more specific topics or subscribe to one / more topics to receive messages from this topic.

H3

MQTT Clients are compatible with most operating systems available: MAC OS, Windows, Linux, Android, iOS, ….

2. Advantages

  • Separate, independent connection.
  • Ability of extension.
  • Time decoupling.
  • Synchronization decoupling.

3. Disadvantages

  • Broker server does not need to notify the status of sending messages. Hence there is no way to detect whether the message was sent correctly or not.
  • Publisher knows nothing of the status of subscriptions and vice versa. So how can we make sure everything is fine.
  • Malicious Publisher can send bad messages, and subscribers get access to things they should not receive.

The working mechanism of MQTT follows the Pub / Sub model

1. Properties and specific characteristics

  • Nature:
    • Space decoupling
    • Time decoupling
    • Synchronization decoupling (separate synchronization)
  • Specific characteristics:
    • MQTT uses a subject-based message filtering mechanism.
    • MQTT has a layer called Quality of Services (QoS). It makes it easy to see if the message has been delivered successfully or not.

2. General mechanism

H4

  • MQTT works by client / server mechanism, where each sensor is a client (client) and connects to a server, which can be understood as a broker, through TCP (Transmission Control Protocol). Broker is responsible for coordinating all messages between sending to the correct receiver.
  • MQTT is message oriented protocol. Each message is a discrete piece of the signal and the broker cannot see. Each bulletin is published an address, can be understood as a channel (Topic). Clients subscribe to several channels to receive / send data, called subscriptions. Clients can subscribe to multiple channels. Each client receives data when any other station sends data to the registered channel. When a client sends a message to a certain channel, it is called publish.

3. Component Architecture

H5

  • The main components of MQTT are Client (Publisher / Subscriber), Server (Broker), Sessions (roughly translated as Session), Subscriptions and Topics.
  • MQTT Client (Publisher / Subscriber): Clients will subscribe to one or more topics to send and receive messages from their respective topics.
  • MQTT Server (Broker): Broker receives subscription information (Subscriptions) from client, receives messages, delivers messages to respective Subscribers based on Subscriptions from clients.
  • Topic: Topic can be considered as a queue of messages, and there are templates for Subscriber or Publisher. Logically, topics allow the client to exchange information with predefined semantics. Example: Temperature sensor data for a building.
  • Session: A session is defined as a connection from client to server. All communication between client and server is part of the session.
  • Subscription: Unlike sessions, subscription is logically a connection from client to topic. When subscribed to a topic, the client can receive / send messages (messages) with that topic.

summary

MQTT is a lightweight protocol designed primarily for connecting power-restricted devices on low-bandwidth networks. Although it has been around for more than a decade, it was only when the advent of M2M (machine for machine communication) and Internet of Things (IoT) that made it a ubiquitous protocol.

Share the news now

Source : Viblo