MQTT is an internet of things messaging protocol, it is built upon TCP/IP, it has minimal overhead, it’s simple and it’s designed for reliable communication over unreliable channels.
If we think about it, many internets of things scenarios have bad connectivity. For example, wi-fi or a mobile network where communication is sometimes pretty hard and you have a lot of interruptions. For example, if you’re building a car that if you drive through tunnels that your user and your device will lose connectivity frequently and MQTT is really built for this kind of scenario and it’s super simple to implement, it’s super simple to use and it uses the best technologies the internet is also built upon like TCP/IP.
Characteristics of MQTT
- Binary
Binary is extremely important because the internet of humans is built upon text HTML. For example, http these are text-based protocols very good for humans but for a machine text-based protocols are not as suitable. Binary protocols like mqtt are built for machines and are super efficient. - Efficient
It was built around maximum efficiency. The smallest mqtt packet actually has two bytes. so, it’s really efficient. - Bi-directional
It’s bi-directional, so as soon as you have a connection from your device to the cloud. You can send data from device to cloud but you can also send data back from cloud to device. - Data agnostic
Data agnosticity means the protocol does not care what you’re sending over it. You can send like xml files, json files, you can send your own custom data format you need for your application or you can just use things like google protocol buffers and even users are using this for sending pictures or sometimes even video fragments over mqtt. - Scalable
It’s really scalable, at hivemq connect more than 10 million devices over the same installation. It’s built upon push communication which means you really have the lowest latency. - Built for constrained devices
If you have not a lot of computing power and you’re very restricted with memory. You can still use mqtt and in fact there are libraries out there, even for arduino and but of course also libraries out there for python, for java, for c, for c sharp and also newer languages like go and rust.
So, this is really great because all of the characteristics make it so suitable for IoT.
MQTT on top of TCP
- MQTT requires TCP/IP
let us look into this a bit more closely mqtt requires tcp and this is great most of the internet protocols we have today run on top of tcp and for mqtt the usual stack is we have ip we have tcp and then mqtt on top of it. - Persistent tcp connections
MQTT uses persistent tcp connections so as soon as a connection is established from device to cloud the connection will be there and will be used here. - Heartbeat mechanism
MQTT has also built in a heartbeat mechanism on top of tcp. So, even if a tcp connection breaks for some reason and you have a so-called half open socket problem, where either the server or the device doesn’t recognize that the tcp connection isn’t available anymore. MQTT has a detection mechanism called heartbeat. - Security transport layer
TLS which is the security transport layer on top on of mqtt. So, you can use TCP, TLS and then MQTT. So, you also get an encrypted connection.
You can reuse all the state-of-the-art libraries like OpenSSL together with MQTT and people are wondering why do we require TCP it’s pretty simple because tcp already guarantees a lot of things MQTT builds upon and so it can be super-efficient on the wire MQTT builds up on TCP because tcp guarantees that packets over the internet are transferred reliable ordered and error-checked and MQTT leverages this fact and so it’s super-efficient and super tiny.
Also Read: Introduction of MQTT
Be the first to comment