Skip to content

Commit 4ce48a8

Browse files
authored
Merge pull request #153 from adafruit/paho-v1-compatibility
Paho v1 compatibility
2 parents 1d99632 + 2737781 commit 4ce48a8

File tree

5 files changed

+9
-16
lines changed

5 files changed

+9
-16
lines changed

Adafruit_IO/_version.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
__version__ = "2.7.1"
1+
__version__ = "2.7.2"

Adafruit_IO/errors.py

+2-9
Original file line numberDiff line numberDiff line change
@@ -20,14 +20,7 @@
2020
# SOFTWARE.
2121

2222
import json, requests
23-
24-
# MQTT RC Error Types
25-
MQTT_ERRORS = [ 'Connection successful',
26-
'Incorrect protocol version',
27-
'Invalid Client ID',
28-
'Server unavailable ',
29-
'Bad username or password',
30-
'Not authorized' ]
23+
from paho.mqtt.client import error_string
3124

3225
class AdafruitIOError(Exception):
3326
"""Base class for all Adafruit IO request failures."""
@@ -63,6 +56,6 @@ class MQTTError(Exception):
6356
"""Handles connection attempt failed errors.
6457
"""
6558
def __init__(self, response):
66-
error = MQTT_ERRORS[response]
59+
error = error_string(response)
6760
super(MQTTError, self).__init__(error)
6861
pass

Adafruit_IO/mqtt_client.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -59,8 +59,8 @@ def __init__(self, username, key, service_host='io.adafruit.com', secure=True):
5959
self.on_disconnect = None
6060
self.on_message = None
6161
self.on_subscribe = None
62-
# Initialize MQTT client.
63-
self._client = mqtt.Client()
62+
# Initialize v1 MQTT client.
63+
self._client = mqtt.Client(mqtt.CallbackAPIVersion.VERSION1)
6464
if secure:
6565
self._client.tls_set_context()
6666
self._secure = True

examples/mqtt/mqtt_shared_feeds.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -70,5 +70,5 @@ def message(client, feed_id, payload):
7070
while True:
7171
value = random.randint(0, 100)
7272
print('Publishing {0} to {1}.'.format(value, IO_FEED))
73-
client.publish(IO_FEED, value, IO_FEED_USERNAME)
73+
client.publish(IO_FEED, value, feed_user=IO_FEED_USERNAME)
7474
time.sleep(10)

examples/mqtt/mqtt_viewall.py

+3-3
Original file line numberDiff line numberDiff line change
@@ -50,12 +50,12 @@ def on_connect(client, userdata, flags, rc):
5050
def on_disconnect(client, userdata, rc):
5151
print('Disconnected!')
5252

53-
def on_message(client, userdata, msg, retain):
53+
def on_message(client, userdata, msg):
5454
print('Received on {0}: {1}'.format(msg.topic, msg.payload.decode('utf-8')))
5555

5656

57-
# Create MQTT client and connect to Adafruit IO.
58-
client = mqtt.Client()
57+
# Create Paho v1 MQTT client and connect to Adafruit IO.
58+
client = mqtt.Client(mqtt.CallbackAPIVersion.VERSION1)
5959
client.username_pw_set(USERNAME, KEY)
6060
client.on_connect = on_connect
6161
client.on_disconnect = on_disconnect

0 commit comments

Comments
 (0)