Mosquitto is a message broker that implements the MQ Telemetry Transport protocol version 3. MQTT provides a lightweight method of carrying out messaging using a publish/subscribe model. Probably the most famous example of this is all of the work that Andy Stanford-Clark (one of the originators of MQTT) has done in home monitoring and automation with his twittering house and twittering ferry (but it's not all about twitter!). Andy gave a talk on this at OggCamp that explains a bit about MQTT and how he uses it. The slides and audio are available online at slideshare. There's another short video on some of this available on youtube: IBM's Andy Stanford-Clark uses existing technology to solve every day problems.

See also related links.

MQTT with PHP

Using MQTT in PHP has been possible for a long time using the Simple Asynchronous Messaging (SAM) MQTT class. Unfortunately this is an imperfect solution due to unclear licensing, some slightly dubious design decisions and bugs.

Thankfully, Andrew Milstead has started creating an alternative implementation. It is MIT licensed and available on github. It’s very new, so if you have problems check back to see if there have been updates and then let Andrew know.

MQTT v3.1

The MQTT v3 spec has been updated to v3.1. The significant change is the inclusion of the option to send a username and password as part of the connect command. The new spec is available at http://www.ibm.com/developerworks/webservices/library/ws-mqtt/index.html and is a lot more readable and clear than the original.

Mosquitto will support the v3.1 spec in a future release, along with the ability to control both broker and topic access by username. In the meantime, if you need this functionality, the IBM proprietary RSMB broker may be suitable for testing purposes. The RSMB package now also includes an MQTT client library, a simple publish client and a simple subscribe client, just like mosquitto. Be sure to check the license terms before using it!

Version 0.8.2

This is a bugfix release.

  • Fix default loop() timeout value in mosquitto.py. Previous value was 0, causing high cpu load.
  • Fix message handling problem in client library when more than one message was in the client queue.
  • Fix the logic used to determine whether a QoS>0 message needs to be retried.
  • Fix the Python sub.py example so that it quits on error.

See the download page. Includes Windows 32-bit binaries for the broker compiled with Cygwin, and the client library and clients compiled natively with Visual Studio to allow developing native Windows MQTT clients.

Version 0.8.1 released

This is a minor release. The primary reason for it is the amount of interest in the Python interface to libmosquitto. This release tidies up the Python interface considerably (it is now more “Pythonic” and easier to use), and significantly, brings the promised packages.

This release also provides a few fixes, including to the packaging and installation scripts. Unfortunately, it does also include a known bug that was fixed prior to release, but accidentally left unmerged. This affects mosquitto_pub client when using the -l option (publish line by line input from stdin), causing it to exhibit high cpu load. I’ll make a new bug fix release in a few days with this and any other fixes that come up.

This release also provides improved packaging options. All of the available options are now packaged for Ubuntu, including the libmosquitto0-python package. Because there are now multiple packages, it is possible to provide some mosquitto functionality on distributions where the version of sqlite3 is too old. The packages available on these systems are listed as “clients only”:

  • Fedora 12, 13 (full support)
  • openSUSE 11.3 (full support)
  • openSUSE 11.1, 11.2 (clients only)
  • Redhat Enterprise Linux 5 (clients only)
  • CentOS 5 (clients only)

Details are available on the downloads page. Please note that some distributions have different naming schemes, so the Python module can be called both python-mosquitto and libmosquitto0-mosquitto for example.

Compiling mosquitto on Mac OS X

In a follow up to his screencast demoing mosquitto on Mac OS X , Andy Piper has written a blog post detailing how he got compiled mosquitto and, more importantly, the dependencies, on the Mac.

Take a look over at OS X mosquitto “bites”…

Version 0.8 released

This is the library release. There are a few bug fixes and changes of behaviour for the mosquitto and the clients, but the significant part of this release is the new mosquitto MQTT client library. The library comes in three flavours: the C library, which is the main library, and C++ and Python bindings. If you’re interested in helping add bindings for your favourite language, please get in touch.

The library interface (API) is to be considered experimental, although I believe the C and C++ APIs to be complete and sane. The Python bindings are a naïve attempt by a C programmer and will definitely be changing in the future to something more pythonic. I’d be extremely grateful for help from experienced python programmers to this end.

The documentation of the library is currently ongoing… There is an overview of most of the function calls and an example in the libmosquitto.3 man page, but complete coverage can be found in the mosquitto.h man page. This, combined with the class details in mosquittopp.h can be used to help use the C++ library. The python module isn’t documented due to it’s extremely changeable state, but there is an example in the python directory.

Other changes:

  • Topics starting with a / are treated as distinct to those not starting with a /. For example, /topic/path is different to topic/path. This matches the behaviour of rsmb.
  • Correctly calculate the will QoS on a new client connection (bug #597451).
  • Add “addresses” configuration file variable as an alias of “address”, for better rsmb compatibility.
  • Bridge clean_session setting is now false, to give more sensible behaviour and be more compatible with rsmb.
  • Add cleansession variable for configuring bridges.
  • Add keepalive_interval variable for bridges.
  • Remove default topic subscription for mosquitto_sub because the old behaviour was too confusing.
  • Added a C client library, which the pub and sub clients now use.
  • Added a C++ client library (bound to the C library).
  • Added a Python client library (bound to the C library).
  • Added CMake build scripts to allow the library and clients (not the broker) to be compiled natively on Windows.

Get it from the downloads page.

The change to using a library means that packaging mosquitto for distros is a lot more complex. This is stretching my packaging experience, so please bear with me on that front! Mosquitto will now likely consist of a number of different packages on Ubuntu at least:

  • mosquitto (the broker)
  • mosquitto-clients (mosquitto_sub, mosquitto_pub)
  • libmosquitto0 (C library)
  • libmosquitto0-dev (C library development files)
  • libmosquittopp0 (C++ library)
  • libmosquittopp0-dev (C++ library development files)
  • libmosquitto-python (Python binding)

Update

I’ve been getting a few questions about the python interface. This isn’t currently packaged for Ubuntu, but hopefully will be soon. There are basic python examples in the downloads at lib/python/sub.py and misc/currentcost/gnome-panel/CurrentCostMQTT.py

Andy Piper has put together a 2 minute screencast demoing mosquitto running on Mac OS X and showing publishing and subscribing using the mosquitto command line clients and the IBM java gui client.

View the screen cast here: http://www.youtube.com/watch?v=SP9Vv3Rksm8

Thanks Andy!

MQTT client library

I have been working on a client library for MQTT for the next release of Mosquitto. It is now at a stage where it is usable and ready for wider testing. There isn’t any documentation yet (!) so it’s only available in the source repository at http://bitbucket.org/oojah/mosquitto.Use the “get source” link in the top right corner of the page to download a snapshot. If you’re interested in developing your own open source MQTT clients, it’d be great if you could take a look to make sure the interface is sane before I make a release!

The library itself is written in C, with bindings for C++ and Python.

I plan to package it up in a more easy to access form in the not too distant future, hopefully with some documentation as well.

Update

I’ve put the start of a man page online, which shows an example of using libmosquitto to subscribe to a topic and print the results: libmosquitto.3

Mosquitto on openSUSE 11.3

The upcoming release of openSUSE, version 11.3, includes extension support for sqlite3 which means it now has everything required for mosquitto.

I’ve created packages for this new version of openSUSE and details can be found on the download page. You just need to wait three days until the release of 11.3!

Version 0.7 released

This is a new features release. Note that although the number of changes is relatively small, there is a fairly major change in the network socket handling (to allow >1024 clients) , which is one reason this has been treated as a separate release.

Changes:

  • Use poll() instead of select() to allow >1024 clients.
  • Implement max_connections.
  • Run VACUUM on in-memory database on receiving SIGUSR2.
  • mosquitto_pub can now send null (zero length) messages.
  • Add option to print debug messages in pub and sub clients.
  • hg revision is now exported via $SYS/broker/changeset
  • Add compile time option to disable heap memory tracking.

Bug fixes:

  • Don’t store QoS=0 messages for disconnected clients with subscriptions of QoS>0.
  • accept() all available sockets when new clients are connecting, rather than just one (performance advantage)
  • Send Will when client exceeds keepalive timer and is disconnected.
  • Check to see if a client has a will before sending it.
  • Correctly deal with clients connecting with the same id multiple times.
  • Fix bridge keepalive timeouts and reconnects.
  • Don’t attempt to drop root privileges when running on Windows as this isn’t well supported (bug #586231).

Source downloads are available at http://mosquitto.org/download. Links for binary packages on Ubuntu and Fedora can be found on the same page.