As a part of understanding how to share information between a heterogeneous set of devices, I started looking into MQTT (MQ Telemetry Transport), which was invented by Dr Andy Stanford-Clark of IBM, and Arlen Nipper of Arcom (now Eurotech), in 1999. MQTT has become an OASIS (Organization for the Advancement of Structured Information Standards) standard in November 2014. There has been a lot of interest in it, and hence it is quite rich in terms of implementations (both clients and brokers). It is also part of the Eclipse PAHO project. (See more here: https://github.com/mqtt/mqtt.github.io/wiki/software?id=software)
This richness is the main reason I started looking at it. Other options do exist with COAP, XMPP, etc as reported here. The operating system I use for some of the sensors is Contiki, which also has a COAP (Constrained Application Protocol) implementation. There are two implementations for Contiki, one for MQTT and the other for MQTT-SN (MQTT for Sensor Networks) are published in: https://github.com/esar/contiki-mqtt https://github.com/adamrenner/mqtt-sn-tools-contiki
So, naturally I went with MQTT as a first step (but will also take a look at COAP later) and this blog entry documents our experience trying to run MQTT-SN clients with MQTT-Gateways.
A bit more information about MQTT. It is a publish-subscribe messaging transport protocol and it runs over TCP-IP (the latest specification is here). MQTT-SN, formerly known as MQTT-S is aimed at embedded devices on non-TCP/IP networks, such as Zigbee. It follows the same publish-subscribe method but works on UDP, rather than requiring a TCP connection. The specification is available here.
Even all the tools seemed available, this is the point where we needed to do a bit more digging. Although we could find evidence that the contiki-mqtt worked well with Zolertia nodes, and the nodes were able to connect to the Mosquitto broker (http://mosquitto.org/, a widely-used MQTT broker), we had errors due to code being too large for TelosB motes (Contiki has support for 6LowPan so our first try was MQTT over TCP/IP). Then, we found MQTT-SN tools, however, we lacked a UDP-TCP gateway that would connect our MQTT-SN speaking motes to MQTT speaking Mosquitto broker. (Another broker we also tried is RSMB (Real Small Message Broker, which can be started with MQTT-S, but listens on a TCP port).
The first useful find was MQTT-SN apps in the paho project: http://git.eclipse.org/c/paho/org.eclipse.paho.mqtt-sn.apps.git/
If you follow this link and clone the git repository, you end up having three directories containing, an MQTT-SN C client, an MQTT-SN Java client, and an MQTT-SN Gateway. I only tested the Gateway so far.
To compile the gateway, I skipped the IDE environments (maybe because the native installation of Eclipse of Ubuntu did not come with Java support somehow). And although I had eventually got a Java-Eclipse, I ended up doing everything in the command line.
To compile, open a terminal and go into to the directory where the source of the gateway is: org.eclipse.paho.mqtt-sn.apps/apps/MQTTSN-Gateway/src/org/eclipse/paho/mqttsn/gateway
Here run: > javac $(find ./* | grep .java)
This will find all the java files in the subdirectories and compile them into class files.
Then: Create a manifest.txt file, with one line: Main-Class: Gateway
To create the jar file: > jar cfm Gateway.jar manifest.txt $(find ./* | grep .class)
This will create your executable.
To run the Gateway, go back to org.eclipse.paho.mqtt-sn.apps/apps/MQTTSN-Gateway and run:
> java -cp src org.eclipse.paho.mqttsn.gateway.Gateway
You will see that your Gateway will start and then terminate.
For things to work, you should have started an MQTT broker (in my case a Mosquitto broker), which the MQTT-SN gateway connects to when it starts. (They all by default use the ports, e.g., 1883 for MQTT – so things should work out). The MQTT-SN gateway listens on the UDP port 20000.
So, to test whether I can subscribe and publish, I used the https://github.com/njh/mqtt-sn-tools
To subscribe, ./mqtt-sn-sub -p 20000 -t test
To publish, ./mqtt-sn-pub -p 20000 -t test -m “using mqtt-sn”
The next step is to get motes using Contiki MQTT-SN tools to publish to the Mosquitto broker.