Introduction on MQTT and Mosquitto

After having a stable version of Home Assistant, a new update came out. Mosquitto had to be updated. Then I thought; Hey, this might be a good moment to give an introduction on Mqtt and Mosquitto. In case you are new to smart home and internet of things, I will shortly explain what Mosquitto is. Mosquitto is a mqtt broker. Broker? Now you might ask, what the hell is a broker? And what is MQTT?

MQTT can be explained as a protocol that enables devices to work together. MQTT, or Message Queuing Telemetry transport, is a push-subscribe based protocol. What you basically do is connecting a device to a topic that you set. The other device listens to this topic. This way, it is possible to send data. So if the state or message changes, you can receive it on the other device.  

 

Okay, give me a less abstract example!

 

Example: you subscribe to a youtube channel. If a new video is uploaded to the channel you are subscribed to, you will watch the video. The information you get from the video is the information. Well, subscribing to a MQTT topic is indeed that simple. The topic can be considered the Youtube channel and the video the MQTT message a certain device is interested in. In case of publishing, imagine the following: you are the youtuber and you have a youtube channel (okay quite obvious), and your subscribers are subscribed to your topic.

 

For an internet of things project, it might be a better choice to go for a different protocol. In 2019 there are a ton of protocols that are more efficient (energy wise). However, MQTT is a system that requires just the internet/wifi and is quite fast. Though, what you should keep in mind is the energy consumption of wifi enabled devices, as they can be way less efficient than other messaging protocols. More on these protocols soon.

 

Now back to what a broker exactly is. A broker is a piece of software that facilitates the routing of these messages. Mosquitto in particular is an open source-software Mqtt broker. Home Assistant is an open-source smart home enabling piece of software that is able to run on different platforms, such as the 35 euro pc; Raspberry Pi. (if you know Dutch, see my tutorial on how to set up Home Assistant on the Raspberry Pi). The website of Mosquitto can be found here: https://mosquitto.org/

Later, I will discuss how to install Mosquitto. Why is MQTT a nice protocol? It is relatively lightweight and easy to use. You can just run a small script on an ESP32, ESP8266 or Arduino connected to a cloud and start sending data. The possibilities are endless.

Leave a Reply

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