9-16-2017

MQTT

I keep hearing about MQTT in connection with IoT type projects. I have always just "rolled my own" protocol for this kind of thing, but there probably are advantages to using a standard like this.

MQTT stands for MQ Telemetry Transport. It is a publish/subscribe protocol that requires clients to work with a broker (i.e. a server). It is designed for use on low bandwidth networks. It is also designed to have a small footprint on devices that utilize it. A "broker" can handle thousands of clients.

MQTT was invented by Andy Stanford-Clark (IBM) and Arlen Nipper (Arcom, now Cirrus Link) back in 1999, when their use case was to create a protocol for minimal battery loss and minimal bandwidth connecting oil pipelines over satellite connection.

The Hackaday tutorials use a MQTT broker called "mosquitto". This is available under Fedora via the package system, making this a piece of cake for me to install.
mosquitto.i686                           1.4.10-2.fc25                  updates
mosquitto.x86_64                         1.4.10-2.fc25                  updates
mosquitto-devel.i686                     1.4.10-2.fc25                  updates
mosquitto-devel.x86_64                   1.4.10-2.fc25                  updates
Doing the install on my fedora system also pulls in the websockets library.
(1/2): libwebsockets-2.1.1-1.fc25.x86_64.rpm    196 kB/s |  94 kB     00:00
(2/2): mosquitto-1.4.14-1.fc25.x86_64.rpm       371 kB/s | 190 kB     00:00
This also provides some clients:
[root@trona tom]# ls /usr/sbin/mosquitto*
/usr/sbin/mosquitto

[root@trona tom]# ls /usr/bin/mosquitto*
/usr/bin/mosquitto_passwd  /usr/bin/mosquitto_pub  /usr/bin/mosquitto_sub
Mosquitto listens on a default port of 1883, which is the IANA reserved port for MQTT. This can easily be changed. There does not seem to be an RFC describing MQTT.

There is a ruby gem for mqtt, also python modules and a perl module on CPAN. The mosquitto distribution includes C++ client libraries. If C++ is not your game (it is not mine), take a look at the Paho C library.

Fedora also includes some Paho packages:

eclipse-paho-mqtt-java.noarch            1.0.2-1.fc25                   fedora
eclipse-paho-mqtt-java-javadoc.noarch    1.0.2-1.fc25                   fedora
eclipse-paho-mqtt-java-tests.noarch      1.0.2-1.fc25                   fedora
python2-paho-mqtt.noarch                 1.2-2.fc25                     fedora
python3-paho-mqtt.noarch                 1.2-2.fc25                     fedora

The protocol is supposedly simple and lightweight, so why not roll your own?

Take a look at the third of the Hackaday series "control and clients" for some tips on Android clients that talk MQTT. The MQTT.js library and websockets hint that it should be straightforward to work up some web based clients (but now we start thinking about security and authentication). The last of the Hackaday article talks about security and "bridging" to an MQTT server that is more generally accessible than one you run inside your home wifi network.

What about iPhone clients?

Due to Apples boneheaded attitude about putting your own apps on your own phone (the main reason I own an android rather than an iPhone), this is difficult. There seem to be a variety of ready built clients. MQTT Buddy, MQTT inspector, etc.
Feedback? Questions? Drop me a line!

Tom's Computer Info / [email protected]