MQTT protocol

The MQTT communication protocol is based on the publication and subscription pattern. Its main advantage is lightness, so it can be implemented in very small microprocessor systems, and at low data transmission. MQTT was created by Andy Stanford-Clark and Mihaelaanca Nippera in 1999 year. The MQTT protocol is a special application in the IoT industry.

The structure of the activity is based on a single central server, called a broker, and many clients. Each customer can publish and/or subscribe to data within each topic. The big advantage is that customers don’t have to know each other so their software can be very simple and require little resources. It is all loaded with a broker that receives published data and distributes it to all subscribers of a topic. The most popular brokers can be used: Mosquitto, RabbitMQ, HiveMQ, IBM MessageSight, VerneMQ.

Topics

An interesting solution are topics that perform a channel function to transmit specific information. They are characterized by the fact that they do not have specific names. And what’s more interesting is that you don’t have to assume them in any way. Just start to publish or subscribe a topic.

Although the names of a topic can be anything, such a good practice is to use a certain hierarchical structure. For example, assume this template for topic names:

MyHome/[device]/[parametr]

So the names of the topics sounded to:

MyHome/Sensor1/temperature
MyHome/sensor1/humidity
MyHome/Sensor1/presure
MyHome/Sensor2/temperature
MyHome/sensor2/humidity
MyHome/Sensor3/temperature

In addition to the visual advantages of such a solution, we also gain the ability to subscribe to several topics. To do this, we use two characters: “+” and “#”.

The “#” character causes we are subscribe all topics that contain a phrase before. For example:

MyHome/Sensor1/#

You will be subscribed to the following topics:

MyHome/Sensor1/temperature
MyHome/Sensor1/temperature/Celsius
MyHome/Sensor1/temperature/Fahrenheit
MyHome/sensor1/humidity
MyHome/Sensor1/presure

The action of the “+” character is similar, but it replaces one level in the hierarchy using all possible phrases at that level, for example:

MyHome/+/temperature

Lets you subscribe to topics:

MyHome/Sensor1/temperature
MyHome/Sensor2/temperature
MyHome/Sensor3/temperature

QoS-Quality of Service

The MQTT protocol allows you to specify how our message is to be sent. There are three QoS levels:

  1. The message is sent without any waiting for confirmation.
  2. The message will be sent to at least one recipient (subscriber), a receipt confirmation is required.
  3. The message will be sent to only one recipient, confirmation is required.

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.