@@ -34,12 +34,15 @@ class MQTTClient(object):
3434 using the MQTT protocol.
3535 """
3636
37- def __init__ (self , key , service_host = 'io.adafruit.com' , service_port = 1883 ):
37+ def __init__ (self , username , key , service_host = 'io.adafruit.com' , service_port = 1883 ):
3838 """Create instance of MQTT client.
3939
4040 Required parameters:
41+ - username: The Adafruit.IO username for your account (found on the
42+ accounts site https://accounts.adafruit.com/).
4143 - key: The Adafruit.IO access key for your account.
4244 """
45+ self ._username = username
4346 self ._service_host = service_host
4447 self ._service_port = service_port
4548 # Initialize event callbacks to be None so they don't fire.
@@ -48,7 +51,7 @@ def __init__(self, key, service_host='io.adafruit.com', service_port=1883):
4851 self .on_message = None
4952 # Initialize MQTT client.
5053 self ._client = mqtt .Client ()
51- self ._client .username_pw_set (key )
54+ self ._client .username_pw_set (username , key )
5255 self ._client .on_connect = self ._mqtt_connect
5356 self ._client .on_disconnect = self ._mqtt_disconnect
5457 self ._client .on_message = self ._mqtt_message
@@ -146,7 +149,7 @@ def subscribe(self, feed_id):
146149 """Subscribe to changes on the specified feed. When the feed is updated
147150 the on_message function will be called with the feed_id and new value.
148151 """
149- self ._client .subscribe ('api/feeds/ {0}/data/receive.json ' .format (feed_id ))
152+ self ._client .subscribe ('{0}/feeds/{1} ' .format (self . _username , feed_id ))
150153
151154 def publish (self , feed_id , value ):
152155 """Publish a value to a specified feed.
@@ -155,5 +158,5 @@ def publish(self, feed_id, value):
155158 - feed_id: The id of the feed to update.
156159 - value: The new value to publish to the feed.
157160 """
158- self ._client .publish ('api/feeds/ {0}/data/send.json ' .format (feed_id ),
161+ self ._client .publish ('{0}/feeds/{1} ' .format (self . _username , feed_id ),
159162 payload = value )
0 commit comments