From ed6d744c82e51910bfb9bb4cb8e2fa2c8bd677e6 Mon Sep 17 00:00:00 2001 From: David Parker Date: Wed, 24 Sep 2014 15:45:42 +0100 Subject: [PATCH] Updates to support paho-mqtt 1.0 Fix for change in on_connect() callback parameters between paho-mqtt 0.9 and 1.0 --- setup.py | 4 ++-- src/ibmiotc/__init__.py | 8 ++++---- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/setup.py b/setup.py index ec995b37..1b9f907e 100644 --- a/setup.py +++ b/setup.py @@ -19,7 +19,7 @@ description='IBM Internet of Things Cloud for Python', long_description=open('README.txt').read(), install_requires=[ - "paho-mqtt >= 0.9", - "iso8601 == 0.1.10", + "paho-mqtt >= 1.0", + "iso8601 >= 0.1.10", ] ) \ No newline at end of file diff --git a/src/ibmiotc/__init__.py b/src/ibmiotc/__init__.py index f878a7ed..b55057a8 100644 --- a/src/ibmiotc/__init__.py +++ b/src/ibmiotc/__init__.py @@ -21,7 +21,7 @@ import iso8601 from datetime import datetime -__version__ = "0.0.5" +__version__ = "0.0.6" class Message: def __init__(self, message): @@ -105,9 +105,9 @@ def __logAndRaiseException(self, e): def connect(self): self.logger.debug("Connecting... (address = %s, port = %s, clientId = %s, username = %s, password = %s)" % (self.address, self.port, self.clientId, self.username, self.password)) try: - self.client.loop_start() self.connectEvent.clear() self.client.connect(self.address, port=self.port, keepalive=self.keepAlive) + self.client.loop_start() if not self.connectEvent.wait(timeout=10): self.__logAndRaiseException(ConnectionException("Operation timed out connecting to the IBM Internet of Things service: %s" % (self.address))) @@ -143,12 +143,12 @@ def on_log(self, mqttc, obj, level, string): 4: Refused - bad user name or password (MQTT v3.1 broker only) 5: Refused - not authorised (MQTT v3.1 broker only) ''' - def on_connect(self, mosq, obj, rc): + def on_connect(self, client, userdata, flags, rc): if rc == 0: self.connectEvent.set() self.logger.info("Connected successfully") elif rc == 5: - self.__logAndRaiseException(ConnectionException("Not authorized: s (%s, %s)" % (self.clientId, self.username, self.password))) + self.__logAndRaiseException(ConnectionException("Not authorized: s (%s, %s, %s)" % (self.clientId, self.username, self.password))) else: self.__logAndRaiseException(ConnectionException("Connection failed: RC= %s" % (rc)))