A QuickStart guide to PubSub with IBM Internet of Things Foundation (sample C client)

At work, I’ve been working with IBM’s recently launched Internet of Things Foundation (IoTF), both on MessageSight (the underlying MQTT server) and other odds and ends. IoTF allows you to quickly start doing simple pub/sub via the MQTT protocol without even having to register yourself or the apps/devices doing the publishing or the subscribing, you configure apps to connect and messages can immediately start to flow for free.

As MQTT is used as the protocol you can use pretty much any programming language (including but definitely not limited to: Javascript, python, Go, C or Java). As an old-skool C hacker I often default to C and I forget the format for the id the publishers and subscribers need to use. To get started with a sample C app you:

  1. Download the Paho MQTT C client
  2. Extract the libraries (or “make” if you used the source, Luke)
  3. Build the samples (Unless you built the libraries and got it to build the samples at the same time (see README.md))
    1. gcc stdinpub.c -o stdinpub -I../include -L ../lib -lpaho-mqtt3c -Wl,-rpath,../lib
    2. gcc stdoutsub.c -o stdoutsub -I../include -L ../lib -lpaho-mqtt3c -Wl,-rpath,../lib
  4. Setup a subscriber:

    ./stdoutsub 'iot-2/type/jonexampletype/id/device1/evt/+/fmt/+' --host quickstart.messaging.internetofthings.ibmcloud.com --clientid 'a:quickstart:jonexamplesubber' --verbose
  5. In another terminal start a publishing app:

    ./stdinpub iot-2/evt/status/fmt/json --host quickstart.messaging.internetofthings.ibmcloud.com --clientid 'd:quickstart:jonexampletype:device1' --verbose
  6. Send some messages by typing them into your publisher (as we are publishing on a topic that claims to be JSON a simple example message might be:

In this example, the samples are linked to the classic, simpler, synchronous C library, in the same Paho bundle you get other (more powerful) variants, see the README.me for more details

A key to the colours used above:

  • Device Type: The type of device publishing, you can make it up and use it to group your devices
  • Device Id: The id of the device publishing, you can make it up. You need the combination of devicetype:deviceid to be unique across all devices connecting to quickstart… when a “duplicate” device connects, any existing devices with the same type:id will be disconnected
  • Event Type: The category of messages being published, again you can make it up. In this case, the subscriber used ‘+’ which means any event type.
  • Message Format: The format of the messaged published. You can make it up but JSON is special, in quickstart you can visualise data from devices published in JSON format and for registered devices, JSON messages can be recorded by the IoTF for future use
  • Application Identifier: Identifies the application, needs to be unique as duplicates are disconnected in the same way as mentioned in the Device Id: above.
  • Organisation:See below

In this example we were using the quickstart organisation which allows you to get going quickly. You know you that won’t be charged (or contacted by a sales person) as you haven’t given any contact details. After the initial thrill of getting going quickly, there are downsides – the device/application client identifiers have to unique across everyone using quickstart and there is no security for your data. Once you’ve taken your first steps you probably want to register – depending on your needs it can be as cheap as free, but it gives you e.g. access controls, security and the ability to log published messages in the cloud.

I plan to eventually do equivalents of this posts for other languages (and possibly with a registered account), let me know in the comments if there’s something you want covered.

Problems with Qt Creator installed in /opt

I’ve been doing a bit of fiddling with using Qt for developing mobile apps. When I installed the Qt SDK I installed it to /opt. This means the user running the IDE does not have write access to the IDE which has caused a number of problems.

  • Updating the SDK: If you run the SDK as the normal user, the “Help > Start Updater” menu option still exists and appears to work. It seemed to detect that I had sudo access and asked for my password but then hung using 100% CPU. Instead of using that menu option, I ran /opt/QtSDK/SDKMaintenanceTool as root which works.
  • Running the QEMU phone emulator: This failed with “Qemu finished with error: Exit code was 1”. To fix this, I ran QEMU manually:
    /opt/QtSDK/Madde/bin/mad remote -r dfl61-harmattan_2.2011.39-5 poweron -fg
    This showed I needed write access to the qemu disk images. As I’m the only user on the system*, I gave all users access:
    chmod a+w /opt/QtSDK/Madde/runtimes/dfl61-harmattan_2.2011.39-5/arm-qemu-rm680-*

Hope this helps someone stumbling across this via Google

* = Yeah. There was no need to install Qt into /opt – it just seemed tidier than putting it in my home directory

Logitech C300 webcam on Linux

The Logitech C300 webcam worked fine with Fedora 15 as it shipped but a kernel update caused the audio to come out really squeaky/high-pitched/”chipmunk”ed.

I’m not the only one having issues with similar webcams:

  • https://bugs.launchpad.net/ubuntu/+source/linux/+bug/858412
  • https://bugzilla.redhat.com/show_bug.cgi?id=729269
  • https://bbs.archlinux.org/viewtopic.php?id=121607&p=3

Based on the patch in the third link in that list (for a few different webcams), I’ve found that the following trivial patch fixed the problem:

diff -uNrp kernel-2.6.40.fc15.orig/drivers/usb/core/quirks.c kernel-2.6.40.fc15.new/drivers/usb/core/quirks.c
--- kernel-2.6.40.fc15.orig/drivers/usb/core/quirks.c 2011-09-27 21:23:58.801051233 +0100
+++ kernel-2.6.40.fc15.new/drivers/usb/core/quirks.c 2011-09-27 21:30:35.184686232 +0100
@@ -44,6 +44,9 @@ static const struct usb_device_id usb_qu
/* Logitech Webcam C250 */
{ USB_DEVICE(0x046d, 0x0804), .driver_info = USB_QUIRK_RESET_RESUME },

+ /* Logitech Webcam C300 */
+ { USB_DEVICE(0x046d, 0x0805), .driver_info = USB_QUIRK_RESET_RESUME },
/* Logitech Webcam C310 */
{ USB_DEVICE(0x046d, 0x081b), .driver_info = USB_QUIRK_RESET_RESUME },

If you want to try that before Fedora make a fix available, it’s easy enough to build your own kernel

Simple graphical Javascript Timer

A while ago, for a friend’s party I wrote a very simple Javascript Timer.

The other day, my daughter (too young to understand a numeric countdown at the moment) was messing around at dinner (not unusual). I wanted a simple graphical way to explain that after a set amount of time I would take her dinner away to encourage her to eat up.

Slightly to my surprise I couldn’t find anything with Google (my Google-fu is obviously weak). So I extended my little timer so that it shows a green ball for each second remaining. As the time ticks down, the balls turn red.

I was originally going to use a progress bar but this way shows, at a glance, how much total time there was…

I think it’s working pretty well

My “YES to AV” masterpiece

The opinion-polls that show AV and first-past-the-post neck and neck make me sad. AV isn’t perfect but all its drawbacks (e.g. gerrymandering) apply to FPTP too. AV has the big advantage that tactical voting isn’t necessary – a huge drawback in the current system. The main argument against AV “people who vote for smaller parties get to vote twice” seems confused or intellectually dishonest.

I drew a beautiful masterpiece that sums up the situation to post to the b3ta AV image challenge but as a new member it turns out I’m not eligible to post until Tuesday.

Oh well, it reduces the number of people who will doubt my mental age to the readership of this blog entry…