If you’re involved in the world of IoT, it’s likely you’ve already come across MQTT (Message Queue Telemetry Transmission). If not, let’s start off by defining what MQTT in IoT is. MQTT is used as a data connection IoT protocol. It features a publisher-subscriber messaging model and allows for simple data flow between different devices.
MQTT has a lot of support from within the IoT community. Working on top of TCP/IP protocol, MQTT’s simple iot architecture has been a game changer in an industry with an increasing number of small, cheap, and low-power objects entering the market.
However, MQTT is also not without its limitations. With that in mind, we’re going to look at the pros and cons of using MQTT in IoT, whether it’s the right IoT protocol for your IoT stack, and a potential alternative. Let’s get into it.
Pros of the MQTT Protocol in IoT
We’re first going to look at some of the pros of this data connection protocol to understand why the MQTT protocol is used in IoT.
Ensures message delivery
Some IoT devices are moveable objects and some are battery-powered devices. This can result in IoT connections becoming unstable in certain environments and for some purposes.
Sometimes this isn’t a huge deal. However, when it comes to industries like the industrial Internet of Things – reliability is crucial. In fact, any form of data loss or duplication can have huge ramifications and ultimately cause an IoT stack to fail. MQTT originated from the oil industry. Therefore, it needed to develop a way to provide impeccable reliability in the worst network conditions.
Moreover, MQTT adds further message delivering reliability by adding three distinct flags. This is referred to as QOS (Quality of Service). These are the 3 possible levels:
- QoS 0: At most once delivery – Suitable if data loss is acceptable. Requires the lowest amount of network traffic and is perfect for smart-home projects.
- QoS 1: At least once delivery – Ensures message is received by consumers at least once. Used if message delivery needs to be guaranteed, but duplicates are allowed.
- QoS 2: Exactly once delivery – Suitable for the aforementioned critical scenarios that require a message to be guaranteed and not duplicated.
As you can see, regardless of whether you’re using an MQTT for smart-home projects or within industrial industries, the QoS system ensures that you can tweak the message delivery to your unique specifications.
As we briefly touched on, MQTT has been able to support the increasing number of small, cheap, and low-powered IoT devices on the market. There are now millions of IoT devices out there and most of them have low memory and low processing power.
MQTT’s lightweight protocol is well-suited for these devices – much more so than the HTTP protocols. This is because a HTTP protocol header is typically about 8000 bytes, whereas the MQTT protocol is only 2 bytes and a few lines of code. And while HTTP protocols still have their uses in IoT – especially in areas such as 3D printing – it’s generally considered unsuitable for the majority of IoT devices.
However, MQTT may still be too resource heavy for some super-lightweight devices that have minimal processing power. This is explained in more detail below.
MQTT was developed by IBM for use in harsh conditions – the desert to be precise. Therefore, without access to electricity grids, it needed to have the lowest possible energy consumption. This has resulted in an extremely battery-friendly IoT protocol.
The power consumption of MQTT when compared to HTTP on battery-powered devices is striking.
MQTT consumes 170-times less energy on 3G networks and 47-times less energy on Wi-Fi networks. As a result, MQTT is considered a superior IoT protocol if developers are looking to build devices that can stay connected to a battery for years and years.
Cons of the MQTT IoT Platform
While it’s undeniable that the MQTT protocol has a lot of useful benefits – especially when stacked up alongside HTTP protocols – it has a few drawbacks. With that in mind, let’s take a look at the cons of using an MQTT in IoT:
MQTT Can’t Support Video Streaming
If you’re looking to build an IoT stack that supports video streaming, MQTT is not the answer. It’s unfortunately not a video streaming IoT protocol.
Therefore, if you’re looking to stream video, you should look elsewhere.
Not ‘Developer Friendly’
A downside of using MQTT as a remote control is that it’s not developer friendly. What do we mean by this? Well, a message sent from an app to your device is done so in an asynchronous way.
Let’s look at this issue in action. When using a MQTT as a remote control, pushing a button in a GUI (graphical user interface) will forward a message to the device. However, the code you’ve implemented will not receive an “OK” from the device.
As a developer, this is a significant drawback. For instance, say you’re sending an “arm alarm system” message. If you end the dialogue with “message sent”, you need to create a means of informing the user if – for whatever reason – the “arm alarm” message didn’t get to the device.
Issues with Latency
While no one is denying that MQTT is extremely reliable when it comes to message delivery, one criticism is that there are often issues with speed and latency.
This is because data has to go through the cloud. And while this isn’t too much of a big deal in certain scenarios and IoT functions, it can be troublesome in the wrong kind of setting.
For example, if you’re using MQTT as your data connection IoT protocol for a medical device, one or two seconds of latency can make controlling the device extremely difficult for the operator and potentially dangerous for the patient.
If speed and latency aren’t major factors in what you need from your IoT stack, then MQTT could still be a good option for you. However, if latency will affect your internet of thing connectivity, look for an alternative.
Security Not Built In
Another con of using an MQTT in IoT is the lack of security built into it. It doesn’t come ready to go out of the box and, as a result, is up to the end-user to manage. This requires you to build a security layer on top of the MQTT.
One positive of security not being built in is that it does allow users to change their security solution as devices and technology evolve. That being said, it’s still an added headache for many.
Super low-power devices may lack resources to run MQTT
While MQTT is extremely lightweight versus other mainstream alternatives, the minimal resources for running MQTT may still be too high for super-low-power devices, as you need a complete TLS stack.
It’s true that a TLS/DTLS stack can be tailored to fit the needs of a specific application. However, the more flexibility and more features you enable, the bigger the footprint. For this reason, it’s best to avoid MQTT as a protocol for lower-powered devices.
Nabto as an Alternative to MQTT
As you can see, while MQTT can be a very effective communication protocol for many IoT applications, it isn’t suitable for every type of application.
Here at Nabto, we’ve designed an IoT connectivity platform that uses P2P technology which bypasses the cloud and enables direct communication between end-user clients and IoT devices. The features of our platform include:
- Super low latency: P2P IoT provides a direct connection, enabling the data communication between the end user and IoT device to travel as fast as possible, with the lowest latency, enabling the most responsive IoT apps.
- Developer Friendly: With Nabto, the communication is synchronous. Therefore, the GUI will know if a message has been delivered (or failed) in milliseconds and can instantly inform the user.
- Security: Nabto provides a direct encrypted connection between the client and IoT device. Also, data is stored at the device level instead of the cloud, so you avoid the risk of bulk data theft or loss from a central server.
- Video streaming: The platform supports encrypted video streaming from IoT device to end user client.
- Extremely lightweight: Nabto requires less resources than MQTT, enabling a greater use of devices.
If you want to learn more about how Nabto can support your IoT connectivity, sign up for a free account.
Using an MQTT in the IoT has some significant benefits for specific use cases. However, the protocol has some significant limitations which can make it unsuitable for certain IoT projects.
Ultimately, the right protocol for your IoT project depends on the device requirements and the processing power available.
Read Our Other Resources
We’ve published a range of IoT resources for our community, including:
- A Guide to IoT Protocols & Standards, which provides a complete overview of all the major protocols and standards available.
- Buying versus building an IoT platform, which discusses how to choose the best option for you.
- Our guide on how to Develop IoT Apps and what platforms you can use.
- How to Choose the Best IoT Wi-Fi Module and what to consider when making your choice.
- A complete Guide to Microcontrollers for IoT, which explains all your options when it comes to choosing an MCU for your project.