MQTT Explained

Eren Akbulut
3 min readJan 18, 2021

--

Hello everyone today I’ll try to cover what is MQTT and why it’s almost involved with all IoT applications.

Let’s get started with the definition right away.

What is MQTT?

MQTT is a standard messaging protocol for IoT systems. MQTT is a super lightweight protocol and that’s one of the main features that makes MQTT one of the most important in the field. MQTT stands for Message Queue Telemetry Transport and actually developed in the late 90s.

There are a few main terms in MQTT that everyone who is interested in MQTT needs to know about.

In an MQTT system, all communication between all devices goes over Broker devices. Brokers act like the middle man that can receive and transfer messages to all devices that can reach out to them. The transfer communication events described above are leading us to another point in a minute.

There are a few open-source MQTT brokers out there and most of them are quite awesome but the most used one is the Mosquitto. MQTT brokers are usually so lightweight they can work on literally any environment your pc, Linux computer, mac, or even most of the Linux based single board computers.

Publish and Subscribe is the words defining the bidirectional data transfer background of MQTT, no clients stay in direct contact with another client all the traffic works on Brokers with those roles. You a client can publish a message on a specific topic and all the subscribers of the topic will receive that message instantly. All sorts of devices from microcontrollers to normal personal computers can act as a client.

As we briefly used above, a topic is a way to categorize information in MQTT communication. Clients send or receive data by publishing to a topic or subscribing to a topic. There are other specifications about topics but this level of explaining is enough for the purposes of this guide.

QoS stands for the quality of service in MQTT systems basically there are 3 modes we can select for our communication.

Mode 0 is a mode that the publisher just sends and never checks for the answers.

Mode 1 is a mode that the publisher sends over and over until it gets a confirmation.

Mode 2 however works like a total handshake, each data only gets published one this way and no message duplication happens like how might happen in Mode 1.

A basic MQTT example is visualized below:

Now let’s talk about some other topics that make MQTT so special.

  • I don’t want to dive deeper into details but the thing you need to know is MQTT can scale up to millions “easily”.( I mean that kind of a scale is never easy but relatively let’s say.)
  • Different QoS levels allow you to define reliability/performance trade-offs for your system.
  • MQTT encrypts all the messages with TLS and ensures secure data transformation.
  • MQTT allows bidirectional data transfer and this is basically where all the magic happens.
  • I already mentioned it a couple of times, I don’t think that was enough so let’s repeat it one more time. MQTT is Super LIGHTWEIGHT. It requires so little memory that you can use even the weakest Arduinos as clients or the lowest end single board computers like Raspi Zero as a Broker.

That’s it everyone I tried to cover MQTT as clear as possible while giving as few details as I can to not to bore you. I hope you all enjoyed it. Until next time, take care :)

Originally published at https://blog.akbuluteren.com.

--

--

No responses yet