Why you should have a MQTT server

Back when I was researching on how to automate my home I found a couple of companies that were selling high-dollar automation systems. These systems, on top of being expensive, were also typically clunky and had a closed ecosystem. You had to use their system with there devices which you purchased at their costs.

Thanks to the Maker / DIY community, we have seen a huge search in the area of making your own IOT and home automation devices. For just a couple of dollars you can now make a sensor capable of detecting both temperature and light levels and then reporting that back to your own home automation hub (check out mysensors.org for a ton of tutorials on how to build your own sensors using cheap arduinos).

One of the issues though is how to make all these devices talk to one another whether. MQTT is one of the more well known and arguably most used messaging protocols for device-to-device communications.

Just what is MQTT and why do I need it?

MQTT is very light publish-subscribe based messaging protocol. You generally have what is known as a message broker whose’s job is to deliver messages to interested clients (basically clients who are subscribed to a particular channel). Each time a message is published, it is sent out over a specific channel that and client who is subscribed to that particular channel will receive. Let me give you an example:

Lets say you have a temperature sensor in your house that can communicate via MQTT to your home automation hub. This sensor reports the temperature in the room by asking the broker to publish a message on channel “sensors\01\temperature”. The message can by in any format your hub understands (JSON, XML, etc), but it this case we will simply make the message be “82” – or the sensor is reporting that it is 82 degrees in the room. Now your hub can also be connected to the same MQTT broker that your sensor is connected to, but listen to all sensor channels. This is done via a wildcard entry like so “sensors\#” which tells the broker the the client is interested in any and all messages from any channel with the parent of “sensors\”. The hub can determine the message is from sensor 01 and is about the temperature by looking at the channel. The message lets the hub know that it is 82 degrees where the sensor is located. Because your hub most likely already knows where “Sensor 01” is located, it can then take appropriate actions (close the blinds, turn on the A\C, send a message, ect.).

Now you are probably thinking “But why do I need MQTT for that? Don’t other messaging protocols exist?”. MQTT is simple, small, and can deliver messages even if the client is off-line at the time (well, deliver them once the client comes back on-line). Also because MQTT is small, it has libraries for a ton of different languages and can exist on small micro-controllers such as the Arduino and RaspberryPi. All this coupled with the ability to retain messages and client authentication it makes it one of the top choices when setting up a communications network between all your devices regardless of their OS and programming language specifics.

Learn more about MQTT  at:

https://en.wikipedia.org/wiki/MQTT

http://mqtt.org/

https://mosquitto.org/

https://www.rabbitmq.com/

Leave a Reply

Your email address will not be published. Required fields are marked *