In the last installment I set about describing the MQTT messaging protocol. It has many interesting features and is well suited to a system which handles messages between multiple message producers (sensors etc.) and multiple message consumers (PCs, smartphones etc.). Best of all, the protocol is fully open source and has good support from the community.

For the developer there are two official web sites: Firstly http://mqtt.org, where, amongst other things, you can also download the protocol spec. There is also the Eclipse Paho projects website at www.eclipse.org/paho. This site is maintained by the Eclipse IOT Working Group whose members include companies such as Cisco, Huawei and Bosch. Here you can find versions of MQTT implemented in many different programming languages.

It certainly aroused my interest – I was keen to try it out for myself. As luck would have it there are some working MQTT brokers already implemented for testing in ‘The Cloud’. I chose to use the Mosquitto test server although other alternatives are also available. There is the usual warning in the text to be careful and don’t inadvertently publish anything sensitive; anybody could be reading it!
Subscribe
Tag alert: Subscribe to the tag Journey into the Cloud - Article series and you will receive an e-mail as soon as a new item about it is published on our website!

It didn’t really matter in our case, we are just intending to pass a few messages out from our (self programmed) Client and then to receive them again. To start off we will simply use a PC as the platform. There are open-source libraries for Java, Javascript, Python and others on the Paho site. I chose the M2Mqtt library for C#/.NET. You can find comprehensive and helpful documentation for newbies here:
www.eclipse.org/paho/clients/dotnet/
www.hivemq.com/blog/mqtt-client-library-encyclopedia-m2mqtt

Links from the official MQTT site often end up pointing out into the void so here is the direct web link to the source code at Github:
http://git.eclipse.org/c/paho/org.eclipse.paho.mqtt.m2mqtt.git/

The download is a Visual Studio Solution (Project folder) which should be opened in the (community edition) free Visual Studio 2015 IDE. First you will need to add the Solution from another project which takes the user interface and the application code of the self-programmed Client. Then this new Project is given a reference in the M2Mqtt-Library to allow the functions to be accessed in the code using

using uPLibrary.Networking.M2Mqtt;
using uPLibrary.Networking.M2Mqtt.Messages;


Following the guide, programming using the library proved to be really simple. You can download the resulting complete Solution below. I have also stored the executable application into a folder (here you need the .NET Framework 4.5 software framework, which is often already installed in Windows OS but can also be downloaded for free).

My test client is able to receive its own messages when the same subject title is entered into the Topic text boxes und then by choosing the ‘Subscribe’ option. Once a text entry is made in the field ‘Text to publish’ and the publish button is clicked, the message is sent out to the net and after a short delay appears in the ‘Received text’ box. With the same client opened on different PC platforms you can pass messages back and forth. There was no problem for me to send messages from our publishing office out to my office at home and also to chat with a colleague (here it’s convenient to use your forename as ‘Topic to publish’ and the recipient’s forename in ‘Topic to subscribe’).

So a Broker in the network certainly simplifies things compared with the more traditional solution using your own web server with a fixed IP address and all the necessary router configuration setup and associated stress involved.
There is nothing quite like the sweet smell of success to spur you on to the next challenge – more on that in the next installment!