MQTT

MQTT is a low level messaging protocol which can be used to bind services together. It is typically used in a sensor network to send sensor data from a device such as an Arduino or a Raspberry Pi which has been configured to send out this data, there are many tutorials on the setup of either of these devices which can be found here for Arduino: http://knolleary.net/arduino-client-for-mqtt/ and here for Raspberry Pi: http://rasspberrypi. wordpress.com/2012/09/16/mosquitto-mqtt-on-raspberry-pi-broker-publish-and-subscribe-client/.

Before we can use the MQTT server on the disk image we must first install what is called an MQTT client. This is a program which can either publish messages or subscribe to topics. Think of a topic as a postbox for your messages. To get a client we have to follow some different instructions depending upon what operating system you are using.

For more information on MQTT please visit:

http://mqtt.org

Installing Clients

Windows

Windows is unfortunately the hardest of the 3 systems to configure, you will first need to grab the 2010 Visual C++ redistribute and install that from Microsoft. You may already have it installed but chances are you won’t. Head on over to: http://www.microsoft.com/download/en/details.aspx?id=26999 to download the necessary files and install them.

Once the Redistribute is installed you have to install the Mosquitto Windows Client from the downloads page http: //mosquitto.org/download/. The direct link is: http://mosquitto.org/files/binary/win32/mosquitto-1. 2.3-install-win32.exe however chances are this will change with time. Once installed you’re all set.

To run the program you will have to open a command prompt. Click Start and type cmd then enter. A black box will pop up and you need to type this to get to the program:


or

This is slightly different to the other systems as you have to write the whole command not just the end bit, remember this when you follow the usage instruction.

Mac

On Mac it is a pain to install mosquitto. If you already have apple developer tools installed it’s pretty easy but the need for the dev-tools is a real pain. To test if you need the developer toolchain open your terminal (Type terminal into spotlight) and type gcc and press enter. if it gives a bash error then you will need the dev-toolchain, if not then you probably already know what to do from here.

To install the dev-toolchain you will need an Apple account (free) and be signed up as a developer. Login (or Register) here:

https://developer.apple.com/downloads/index.action

Once you are logged in you need to download and install the command line tools for your platform. 

When this is ready you can move on to homebrew. You will first have to install homebrew with this command in the Terminal. To open terminal type Terminal into Spotlight and hit enter. Once there enter:

Once homebrew is installed you just have to install mosquitto like this:

Linux

Linux users have by far the easiest install here, to install mosquitto simply type:

BOOM, Done.

Usage of MQTT Client

Now we have the clients installed we can finally get round to sending and receiving some messages. First things first, open 2 terminal windows on your computer, one will be a publisher and one will be a subscriber.

In the first window type:

In the second window type:

mosquitto

With any luck (Assuming you connected to the correct server), you should now have Test Message written on your second terminal. You have now sent a message via the internet between two machines. This is a simple concept but is very powerful. You could make your own chat client with this or link it with Node-Red later to have the machine send a text message everytime you send a message. The full power of MQTT comes however from linking it up to a platform such as Arduino or Raspberry Pi which would automate the sending of these messages. You can get the Arduino to send sensor values every 2 minutes and then code a flow where for example if a sensor was triggered a text could be sent alerting you to the presence of a burglar in your house. Now you can begin to understand the power of this technology in releasing Open Data from systems which previously were not accessible.