About MQTT…

I need to make a brief detour on our project to integrate X10 sensors into a larger home automation system. Normally, I try to avoid any side trips that may end up taking me down a rabbit hole, but I need to cover the communication method that I plan to use to connect the disparate components of the system together – MQTT.

MQTT is the abbreviation for MQ Telemetry Transport, a messaging system that uses TCP/IP to send and receive its messages. There are two components to an MQTT system – client and broker. Don’t think of it in terms of atraditional client and server. Insted, think in terms of “publishers” and “subscribers.” The client can both publish and subscribe to topics.

You can have multiple clients that plublish to a topic. You can have multiple clients that subscribe to a topic. Your client can subscribe to multiple topics or publish to multiple topics.

The broker handles the routing of messages from publishers of topics to subscribers of topics. There are three QoS options. First, there is “At most once,” the most commonly used level where the message is sent only once and the client and broker take no additional steps to acknowledge delivery ( also known as fire and forget). Second is “at least once,” where the message is re-submitted by the sender (client or broker) multiple times until acknowledgement is received indicating delivery is successful. Finally, there is “exactly once,” where the sender and receiver engage in a two-level handshake to ensure only one copy of the message is received (referred to as assured delivery). The first level has the least overhead, the second more, the third most.

Part of our project will be testing the three levels to determine what we actually need for reliable service in a home automation system, though that is farther down the line.

For now, we start with the basics. The configuartion is pretty simple – you have a broker and a client – or multiple clients, or multiple brokers with some number of clients. Setting up multiple brokers is a little more involved than what we’re going to do, but it is not significantly more work.

We’re going to set up a simple client and a broker, starting with Mosquitto, our MQTT broker. Mosquitto is written as a console app (it runs as a “DOS” window, basically). The install only has one wrinkle – you are prompted to install OpenSSL. This is required for Mosquitto to work and it is safe, so install when prompted – it’s not malware.

These apps will work in Windows, OSX, Linux, on your Pi, and other combinations. The install covered here is on a Windows 10 PC. I used the default install locations.

  • Navigate to https://mosquitto.org/download/ and select the version appropriate for your OS.
  • Launch the installer when download completes.
  • When the Dependencies page prompts you to install OpenSSL, do so. I have used both the light and the full version with equal success.
  • When OpenSSL completes, return to and complete the install of Mosquito – default options are fine.
  • Navigate to C:\Program Files\mosquitto and double click mosquitto.exe
  • Click Allow access when prompted by Windows Firewall

Mosquito is now running. Since it is just an empty window, you can test that the install is working with these steps:

  • Start
  • Type Command and press enter
  • Type Netstat -an and press enter.
  • Look for a TCP entry on port 1883.

If it is there, your broker is running!

Next, we want to install MQTT.fx for use as our client. I again used the default settings for install.

  • Navigate to https://mqttfx.jensd.de/index.php/download 
  • Select the most recent release. At this time, that is version 1.7.0.
  • Download and launch the version appropriate for your OS.
  • Launch MQTT.fx and install updates if available (the available update took us to 1.7.1)At the top of MQTT, you’ll notice it is already set for “local mosquito,” which will connect to the broker we’ve already installed. You can click the settings button (gear) to display the connection profile for local mosquito, which shows the IP address as 127.0.0.1 (local host) and port 1883.

When you click Connect, it will connect to your locally running instance of mosquito. Obviously, if you want to run your broker on a dedicated machine, you can just change the IP address to match that machine, or even to a domain if you’ve set up something appropriate with dynamic DNS or even a hosted server somewhere.

The client defaults to a home/garden/fountain topic, but you’re free to change that. For now, leave it as-is. On the subscribe tab, it also has home/garden/fountain as the default. Please click Subscribe. Switch back to the Publish tab and type “Automation” in the large text box, then click “Publish.” Tab back to the Subscribe tab and you’ll see the message appears. You can click and hold the Subscribe tab and then drag it off to create a new window. You’ll have to resize it, but that let’s you see messages pass in real time.

That’s how simple it is to send and receive messages. We will use both of these tools with our next installment, where we add an MQTT client class to our VB app and experiment with sending messages programatically.

 

SmarterHome.club is the website for our Facebook community, The Smarter Home Club – which is an umbrella for all kinds of smart home technologies – home automation, security, custom electronics, weather stations, alternative energy, you name it. DIY focused.

If you’re interested in joining the Smarter Home Club’s Facebook group, please follow this link:

The Smarter Home Club on Facebook

One Reply to “About MQTT…”

Comments are closed.