Breaking

Saturday, October 6, 2018

What is MQTT and How It Works

In this article, we’re going to introduce you to the MQTT protocol. MQTT stands for Message Queuing Telemetry Transport.
It is a lightweight publish and subscribe system where you can publish and receive messages as a client.

MQTT is a simple messaging protocol, designed for constrained devices with low-bandwidth. So, it’s the perfect solution for Internet of Things applications. MQTT allows you to send commands to control outputs, read and publish data from sensor nodes and much more.
Therefore, it makes it really easy to establish a communication between multiple devices.

MQTT Basic Concepts

In MQTT there are a few basic concepts that you need to understand:
  • Publish/Subscribe
  • Messages
  • Topics
  • Broker

MQTT – Publish/Subscribe

The first concept is the publish and subscribe system. In a publish and subscribe system, a device can publish a message on a topic, or it can be subscribed to a particular topic to receive messages.

  • For example Device 1 publishes on a topic.
  • Device 2 is subscribed to the same topic as device 1 is publishing in.
  • So, device 2 receives the message.

MQTT – Messages

Messages are the information that you want to exchange between your devices. Whether it’s a command or data.

MQTT – Topics

Another important concept are the topics. Topics are the way you register interest for incoming messages or how you specify where you want to publish the message.
Topics are represented with strings separated by a forward slash. Each forward slash indicates a topic level. 

MQTT – Broker

At last, you also need to be aware of the term broker.
The broker is primarily responsible for receiving all messages, filtering the messages, decide who is interested in them and then publishing the message to all subscribed clients.



There are several brokers you can use. In our home automation projects we use the Mosquitto broker which can be installed in the Raspberry Pi. Alternatively, you can use a cloud MQTT broker.



No comments:

Adbox