diff --git a/Adafruit_IO/_version.py b/Adafruit_IO/_version.py index 7a38ae0..7f90850 100644 --- a/Adafruit_IO/_version.py +++ b/Adafruit_IO/_version.py @@ -1 +1 @@ -__version__ = "2.7.1" +__version__ = "2.7.2" diff --git a/Adafruit_IO/errors.py b/Adafruit_IO/errors.py index ba6d88f..52b3fd7 100644 --- a/Adafruit_IO/errors.py +++ b/Adafruit_IO/errors.py @@ -20,14 +20,7 @@ # SOFTWARE. import json, requests - -# MQTT RC Error Types -MQTT_ERRORS = [ 'Connection successful', - 'Incorrect protocol version', - 'Invalid Client ID', - 'Server unavailable ', - 'Bad username or password', - 'Not authorized' ] +from paho.mqtt.client import error_string class AdafruitIOError(Exception): """Base class for all Adafruit IO request failures.""" @@ -63,6 +56,6 @@ class MQTTError(Exception): """Handles connection attempt failed errors. """ def __init__(self, response): - error = MQTT_ERRORS[response] + error = error_string(response) super(MQTTError, self).__init__(error) pass \ No newline at end of file diff --git a/Adafruit_IO/mqtt_client.py b/Adafruit_IO/mqtt_client.py index b6af726..198b4d6 100644 --- a/Adafruit_IO/mqtt_client.py +++ b/Adafruit_IO/mqtt_client.py @@ -59,8 +59,8 @@ def __init__(self, username, key, service_host='io.adafruit.com', secure=True): self.on_disconnect = None self.on_message = None self.on_subscribe = None - # Initialize MQTT client. - self._client = mqtt.Client() + # Initialize v1 MQTT client. + self._client = mqtt.Client(mqtt.CallbackAPIVersion.VERSION1) if secure: self._client.tls_set_context() self._secure = True diff --git a/examples/mqtt/mqtt_shared_feeds.py b/examples/mqtt/mqtt_shared_feeds.py index 38b6667..23b2f16 100644 --- a/examples/mqtt/mqtt_shared_feeds.py +++ b/examples/mqtt/mqtt_shared_feeds.py @@ -70,5 +70,5 @@ def message(client, feed_id, payload): while True: value = random.randint(0, 100) print('Publishing {0} to {1}.'.format(value, IO_FEED)) - client.publish(IO_FEED, value, IO_FEED_USERNAME) + client.publish(IO_FEED, value, feed_user=IO_FEED_USERNAME) time.sleep(10) diff --git a/examples/mqtt/mqtt_viewall.py b/examples/mqtt/mqtt_viewall.py index 64392be..31c3a9e 100644 --- a/examples/mqtt/mqtt_viewall.py +++ b/examples/mqtt/mqtt_viewall.py @@ -50,12 +50,12 @@ def on_connect(client, userdata, flags, rc): def on_disconnect(client, userdata, rc): print('Disconnected!') -def on_message(client, userdata, msg, retain): +def on_message(client, userdata, msg): print('Received on {0}: {1}'.format(msg.topic, msg.payload.decode('utf-8'))) -# Create MQTT client and connect to Adafruit IO. -client = mqtt.Client() +# Create Paho v1 MQTT client and connect to Adafruit IO. +client = mqtt.Client(mqtt.CallbackAPIVersion.VERSION1) client.username_pw_set(USERNAME, KEY) client.on_connect = on_connect client.on_disconnect = on_disconnect