What is MQTT you ask?

Simply put, MQTT is like Twitter. You subscribe to a topic and whenever information is published to that topic you will receive it. And Twitter uses MQTT.

If you don’t know what Twitter is, you might be in over your head but we’ll give it our best shot here.
Disclaimer: This is a very simplified but technical explanation.

Let me break it down for you:

MQTT uses a tcp connection to send small packets of information fast and without the leg-work required by other methods of communication (eg: GET/POST).

This is useful but you need to setup an MQTT broker first. A broker is merely a server/pc/laptop/rasberry pi that has an MQTT broker installed on it. Mosquitto (yes with two t’s) is a good bet for an MQTT broker.

A topic is literally just a string (name) header that the broker uses to sort the information it receives.

So if you have a computer at your disposal (of course you do), then download Mosquitto, install it and… then what? Well you can test it out by using your cmd (command line/terminal/whatever you want to call it). You could write a program in C, C#, .Net or whatever language you want and utilise Mosquitto’s pub and sub functions (with any and all the libraries you may need) to test out your broker. You could do pretty much whatever you wanted with it but here is a place to start if you want to dive in: InternetOfHomeThings. You could even use a currently publicly available server broker, there are tons but here is one: Mosquitto Test.

So what do you know now:

  • MQTT needs a broker. It can be installed anywhere.
  • You need to talk to the broker with 1 of many methods. Pick one and go!
  • MQTT uses TCP so you’ll need to be able to access the broker via your local network and/or the internet with a dedicated IP address (yes I just snuck this part in here)

MQTT will usually happen on port 1883. If you are accessing it via a local network then the broker machine will need a dedicated IP and if you are accessing an online broker server you will need that server to have a fixed IP (recommend a VPS). You’ll be able to set the listening port and many other settings when you install your broker. When dealing with these settings, note:

  • You will start out changing just a few.
  • There are so many: mosquitto.conf Eclipse
  • You thought this would just be simple all the way did you?

You can integrate SSL, you can have three levels of QoS, you can do A LOT! But this is not the purpose of this article so let’s stop there and present a genuine and simple recap on MQTT and what it is:

  • Sends small packets of data fast over a TCP connection.
  • Uses a centralised MQTT broker software on a machine with a dedicated IP.
  • A topic is a header used by the broker to sort information.
  • You subscribe to a topic with a sub function.
  • You publish to a topic with a pub function.
  • When you are subscribed to a topic, you will see whatever information is published to that topic (and can use it!).
  • Mosquitto is spelt with two t’s and is a good broker to start with.