MQTT Joggler


Spurred on by the success of getting Mosquitto working on a Raspberry Pi, I recently had a play with MQTT on the Joggler. The O2 Joggler is still a great device for hacking and I currently have SqeezePlay OS running on it.

The reason I wanted to try and get MQTT on the Joggler was to make use of its light sensor, and publish light levels over MQTT. It all turned out to be pretty simple since most of the work has already been done by other people!

First thing to do was read the light sensor and get that working with an MQTT client. I had to skip some of Andy’s instructions and just built the client code rather than attempting to get doxygen working. Once I’d mashed up the light sensor code and publish example I could compile the worlds most pointless MQTT publisher:

gcc -Wall publightsensor.c -L../bin/linux_ia32 -I../src -lmqttv3c -lpthread -o publightsensor

Next it was time to check the results. This too was quick and easy thanks to the MQTT sandbox server, which has a handy HTTP bridge. And the final result… was a completely unscientific and slightly dingy light level 4! Now I’ll be able to turn on a lamp using an unreliable RF controlled socket and see whether it worked or not!

Update: the code really is all in the existing examples but I’ve created a Github Gist in case it’s any help: mqttjogglermashup.c (11 February 2013)

Advertisement

Building Mosquitto on a Raspberry Pi


Just a few notes in case anyone wants to build the latest version of Mosquitto on a Raspberry Pi before Roger makes it even easier. Luckily there were already a couple of articles describing how to build Mosquitto, and the comments definitely saved some head scratching:

Hopefully the following steps should get MQTT on your Raspberry Pi in double quick time…

Firstly install a few packages. The unscientific list I went with were these, since Python was definitely installed already:

$ sudo aptitude update
$ sudo aptitude install build-essential quilt libwrap0-dev libssl-dev devscripts python-setuptools

Next the sneaky tweak to avoid Python 2.6 errors while building. You can edit /usr/share/python/debian_defaults by hand to move the python2.6 entry from the list of supported versions, or the following should do the trick:

$ sudo cp /usr/share/python/debian_defaults /usr/share/python/debian_defaults.orig
$ sudo sed -E -e '/^old-versions|^unsupported-versions/ s/$/, python2.6/' -e '/^supported-versions/ s/python2\.6,+ +//' /usr/share/python/debian_defaults.orig | sudo tee /usr/share/python/debian_defaults

Now it’s time to grab all the Mosquitto source and packaging files needed to run the build. These were the latest at the time of writing:

$ mkdir mosquitto-build
$ cd mosquitto-build/
$ wget http://mosquitto.org/files/source/mosquitto-1.1.tar.gz -O mosquitto_1.1.orig.tar.gz
$ tar -xvf mosquitto_1.1.orig.tar.gz
$ wget http://mentors.debian.net/debian/pool/main/m/mosquitto/mosquitto_1.1-1.debian.tar.gz
$ tar -zxf mosquitto_1.1-1.debian.tar.gz -C mosquitto-1.1/

Hopefully everything should be ready to go, so kick off the build:

$ cd mosquitto-1.1/
$ debuild -us -uc

That’s all there is to it. Assuming everything worked, just install the packages:

$ sudo dpkg -i ../*mosquitto*.deb

Update: Alternatively, you could just use the new, experimental, debian repository for mosquitto. (13 January 2013)