Manage Data through MQTT

MQTT is a protocol that establishes communication between your Things. MQTT is an open protocol widely adopted by many devices within numerous companies worldwide for Data exchange with constrained devices or products out in the field. It keeps bandwidth at an absolute minimum and deals with unreliable networks not requiring any complex error handling nor huge implementation effort.

MQTT provides an efficient way to establish the communication between your devices over the internet. It makes it possible to send messages in near real time guaranteeing a successful delivery. MQTT's forte is being able to connect thousands of devices to your business, sending instant updates and broadcasting notifications. Connecting your Things through this low-cost communication protocol will add extra value to your business.

The processes involved in the MQTT communication are based on what is called the publish/subscribe paradigm (Pub/Sub) which enables the automatic messaging communication from a publisher (source of the message) to the different subscribers (receivers of the message). It is a different approach than the traditional client-server model, where a client communicated directly with a specific endpoint. Pub/Sub exchanges information from a publisher to one or more subscribers without knowing about each other´s existence. However, there is a third member that serves as the link between the publisher and the subscribers, the broker. The publisher and the subscribers know the broker because its function is to filter and distribute all incoming messages so that they are delivered properly. To receive or send messages the publisher and subscriber must first engage the MQTT broker.

It is important to acknowledge how the broker filters the messages depending on the client. It uses a topic (UTF-8 string) that consists of one or more topic levels, this way, depending on the topic, the broker can filter the information. Each topic level is separated by a forward slash, representing a similar concept as the common folder system to store data (such as a home/secondfloor/kitchen/lighting).

If a “+” is placed under one of the topic levels, it means that you are selecting every topic from that level. So, for instance, if you select “home/secondfloor/+/lighting”, you are choosing to select all of the lightings from every room in the second floor of the house. Moreover, if you set a “#” under one of the selected topic levels, not only all of the topics of that level, but also all of the topics of the levels beyond the one with the “#”. This would mean that, if you select ““home/secondfloor/#"”, you are selecting every thing that is on every room of the second floor of the house. These filtering methods ("#” and “+”) are known as wildcards.

To handle the communication publisher/subscriber properly, an agreement regarding the guarantees of the message delivery is established. This is called the Quality of Service (QoS), and there are three levels of agreement:
Level 0
“At most once”. The message sent will not be stored nor redelivered by the sender and will not be acknowledged by the receiver.
Level 1
“At least once”. The message will be delivered at least once to the subscriber, but it can be delivered more than once.
Level 2
“Exactly once”. The message will be delivered strictly one time accompanied by multiple acknowledgment messages confirming the delivery of the message.

To ensure correct communication, MQTT relies on TCP (transport protocol). However, this protocol does not use encrypted communication. To provide encryption to the communications, the MQTT broker allows the usage of a TLS protocol instead of a regular TCP.

Finally, in terms of authentication in MQTT the protocol itself provides username and password fields in the connection message (message that confirms the connection). Therefore, a client has the possibility to send a username and password when connecting to a MQTT broker.