The Mosquitto Python client was donated to the Eclipse Paho project in June of this year. As mosquitto.py has been very popular, I have been maintaining both code bases together.
With the Mosquitto project also moving to Eclipse it is now even more redundant to keep maintaining mosquitto.py so I would like to recommend that everybody currently using mosquitto.py move over to using the Paho Python client.
The current state of the Paho client is now available on pypi and can be installed using “pip install paho-mqtt”.
To port code from mosquitto.py, you should change:
mqttc = mosquitto.Mosquitto()
import paho.mqtt.client as paho
mqttc = paho.Client()
All error codes e.g. MOSQ_ERR_SUCCESS change to MQTT_ERR_SUCCESS.
The Paho module has a compatibility Mosquitto class that means a very simple (but not recommended for the long term) port can be achieved with the following line, assuming none of the error codes are used:
import paho.mqtt.client as mosquitto
I will keep applying updates to mosquitto.py until the Paho 1.0 release.
In time for the second day of Thingmonk, which I regret not being able to go to, version 1.2.3 of mosquitto is released. This is a bugfix release.
- Don’t always attempt to call read() for SSL clients, irrespective of whether they were ready to read or not. Reduces syscalls significantly.
- Possible memory leak fixes.
- Further fix for bug #1226040: multiple retained messages being delivered for subscriptions ending in #.
- Fix bridge reconnections when using multiple bridge addresses.
- Fix possible memory leak in C/C++ library when communicating with a broker that doesn’t follow the spec.
- Block in Python loop_stop() until all messages are sent, as the documentation states should happen.
- Fix for asynchronous connections on Windows. Closes bug #1249202.
- Module version is now available in mosquitto.py.
- mosquitto_sub now uses fwrite() instead of printf() to output messages, so messages with NULL characters aren’t truncated.
This is a bugfix release:
- Fix compliance with max_inflight_messages when a non-clean session client reconnects. Closes one of the issues on bug #1237389.
- Fix incorrect inflight message accounting, which caused messages to go unsent. Partial fix for bug #1237351.
- Fix potential memory corruption when sending QoS>0 messages at a high rate using the threaded interface. Further fix for #1237351.
- Fix incorrect delay scaling when exponential_backoff=true in mosquitto_reconnect_delay_set().
- Some pep8 fixes for Python.
This is a bugfix release.
- The broker no longer ignores the auth_plugin_init() return value. Closes bug #1215084.
- Use RTLD_GLOBAL when opening authentication plugins on posix systems. Fixes resolving of symbols in libraries used by authentication plugins.
- Add/fix some config documentation.
- Fix ACLs for topics with $SYS.
- Clients loaded from the persistence file on startup were not being added to the client hash, causing subtle problems when the client reconnected, including ACLs failing. This has been fixed.
- Add note to mosquitto-tls man page stating that certificates need to be unique. Closes bug #1221285.
- Fix incorrect retained message delivery when using wildcard subs in some circumstances. Fixes bug #1226040.
- Fix support for Python 2.6, 3.0, 3.1.
- Fix TLS subjectAltName verification and segfaults.
- Handle EAGAIN in Python on Windows. Closes bug #1220004.
- Fix compilation when using WITH_TLS=no.
- Don’t fail reconnecting in Python when broker is temporarily unavailable.
Recursively watch a directory for modifications and publish file content to an MQTT broker
mqtt-watchdir is a Python program by Jan-Piet Mens to watch a directory and publish new or modified files in that directory hierarchy to an MQTT broker, using a matching topic. Source and instructions are available at https://github.com/jpmens/mqtt-watchdir and it is also available via pypi.
It is a similar idea to my mqttfs fuse filesystem, but ultimately implemented in a better (and portable) manner.
Mosquitto has been packaged for Fedora thanks to Rich Mattes. Fedora 19 users will be able to install with “yum install mosquitto”.
This is a (long overdue) feature release.
There is a potential gotcha when upgrading to this release because the default version of TLS used has changed from 1.0 to 1.2. Python does not yet have support for TLS>1.0 so Python clients will be unable to communicate with brokers using the default TLS settings.
The source is available for download at http://mosquitto.org/download and binaries will become available in the near future.
- Replace O(n) username lookup on CONNECT with a roughly O(1) hashtable version.
- It is now possible to disable $SYS at compile time.
- Add dropped publish messages to load tree in $SYS. Closes bug #1183318.
- Add support for logging SUBSCRIBE/UNSUBSCRIBE events.
- Add “log_dest file” logging support.
- Auth plugin ACL check function now passes the client id as well as username and password.
- The queue_qos0_messages option wasn’t working correctly, this has now been fixed. Closes bug #1125200.
- Don’t drop all messages for disconnected durable clients when max_queued_messages=0.
- Add support for “log_type all”.
- Add support for “-v” option on the command line to provide the equivalent of”log_type all” without needing a config file.
- Add the “upgrade_outgoing_qos” option, a non-standard feature.
- Persistence data is now written to a temporary file which is atomically renamed on completion, so a crash during writing will not produce a corrupt file.
- mosquitto.conf is now installed as mosquitto.conf.example
- Configuration file errors are now reported with filename and line number.
- The broker now uses a monotonic clock if available, to avoid changes in time causing client disconnections or message retries.
- Clean session and keepalive status are now display the log when a client connects.
- Add support for TLSv1.2 and TLSv1.1.
- Clients that connect with zero length will topics are now rejected.
- Add the ability to set a maximum allowed PUBLISH payload size.
- Fix an ACL with topic “#” incorrectly granting access to $SYS.
- Fix retained messages incorrectly being set on wildcard topics, leading to duplicate retained messages being sent on subscription. Closes bug #1116233.
- Don’t discard listener values when no “port” option given. Closes bug #1131406.
- Client password check was always failing when security was being reapplied after a config reload. This meant that all clients were being disconnected. This has been fixed.
- Fix build when WITH_TLS=no. Closes bug #1174971.
- Fix single outgoing packets not being sent in a timely fashion if they were not sent in one call to write(). Closes bug #1176796.
- Fix remapping of messages for clients connected to a listener with mount_point set. Closes bug #1180765.
- Fix duplicate retained messages being sent for some wildcard patterns.
- If a client connects with a will topic to which they do not have write access, they are now disconnected with CONNACK “not authorised”.
- Fix retained messages on topic foo being incorrectly delivered to subscriptions of /#
- Fix handling of SSL errors on SSL_accept().
- Fix handling of QoS 2 messages on client reconnect.
- Drop privileges now sets supplementary groups correctly.
- Fix load reporting interval (is now 60s).
- Be strict with malformed PUBLISH packets – clients are now disconnected rather than the packet discarded. This goes inline with future OASIS spec changes and makes other changes more straightforward.
- Process incoming messages denied by ACL properly so that clients don’t keep resending them.
- Add support for round_robin bridge option.
- Add bridge support for verifying remote server certificate subject against the remote hostname.
- Fix problem with out of order calls to free() when restarting a lazy bridge.
- The broker now attempts to resolve bind_address and bridge addresses immediately when parsing the config file in order to detect invalid hosts.
- Bridges now set their notification state before attempting to connect, so if they fail to connect the state can still be seen.
- Fix bridge notification payload length – no need to send a null byte.
- mosquitto_passwd utility now reports errors more clearly.
- Fix “mosquitto_passwd -U”.
- Add support for TLSv1.2 and TLSv1.1, except for on the Python module.
- Add support for verifying remote server certificate subject against the remote hostname.
- Add mosquitto_reconnect_async() support and make asynchronous connections truely asynchronous rather than simply deferred. DNS lookups are still blocking, so asynchronous connections require an IP address instead of hostname.
- Allow control of reconnection timeouts in mosquitto_loop_forever() and after mosquitto_loop_start() by using mosquitto_reconnect_delay_set().
- Fix building on Android NDK.
- Re-raise unhandled errors in Python so as not to provide confusing error messages later on.
- Python module supports IPv6 connections.
- mosquitto_sub_topic_tokenise() was behaving incorrectly if the last topic hierarchy had only a single character. This has been fixed. Closes bug #1163348.
- Fix possible crash after disconnects when using the threaded interface with TLS.
- Allow build/install without Python. Closes bug #1174972.
- Add support for binding connection to a local interface.
- Implement maximum inflight messages handling.
- Fix Python client not handling will_payload==None.
- Fix potential memory leak when setting username/password.
- Fix handling of QoS 2 messages on reconnect.
- Improve handling of mosquitto_disconnect() with threaded mode.
- Add support for TLSv1.2 and TLSv1.1.
- Sub client can now suppress printing of messages with the retain bit set.
- Add support for binding connection to a local interface.
- Implement maximum inflight messages handling for the pub client.
With the most recent commit, “Implement TLSv1.2 and TLSv1.1 support,” everything that is planned for version 1.2 has been completed. If you haven’t tried it out yet, now would be a good time to take a look.
Before the release is finalised, there still needs to be more testing done, particularly on Windows. If you use another platform than Windows or Linux, I’d be interested to hear if you have any problems with the 1.2 code. I will also be updating the packaging for all of the binaries that I build or contribute to directly, so there is still time for bug reports.
You can get a copy of the source at one of the links below, or through the mercurial repository directly on the 1.2 branch.
There has been some interest in authentication plugins for mosquitto recently. Some examples have appeared:
Authentication based on md5 hashes: https://github.com/sskaje/mosquitto_auth_plugin_md5
Authentication based on md5 hashed passwords in postgresql: https://github.com/sebaroesch/mosquitto_auth_plugin_pg_md5
Authentication and topic ACL with redis and a PBKDF2 hash: https://github.com/jpmens/mosquitto-redis-auth
I particularly like the redis based plugin for the interesting additions like the “superuser” that is exempt from ACL checks.
If you’ve written an auth plugin and think it might be useful to others, let me know.
There are no plans to remove the existing files.