Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Adafruit_IO/_version.py
Original file line number Diff line number Diff line change
@@ -1 +1 @@
__version__ = "2.7.1"
__version__ = "2.7.2"
11 changes: 2 additions & 9 deletions Adafruit_IO/errors.py
Original file line number Diff line number Diff line change
Expand Up @@ -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."""
Expand Down Expand Up @@ -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
4 changes: 2 additions & 2 deletions Adafruit_IO/mqtt_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion examples/mqtt/mqtt_shared_feeds.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
6 changes: 3 additions & 3 deletions examples/mqtt/mqtt_viewall.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down