@@ -40,33 +40,40 @@ def connected(client):
40
40
# Subscribe to changes on a feed named DemoFeed.
41
41
client .subscribe ("DemoFeed" )
42
42
43
+
43
44
def subscribe (client , userdata , topic , granted_qos ):
44
45
# This method is called when the client subscribes to a new feed.
45
- print ('Subscribed to {0} with QOS level {1}' .format (topic , granted_qos ))
46
+ print ("Subscribed to {0} with QOS level {1}" .format (topic , granted_qos ))
47
+
46
48
47
49
def unsubscribe (client , userdata , topic , pid ):
48
50
# This method is called when the client unsubscribes from a feed.
49
- print ('Unsubscribed from {0} with PID {1}' .format (topic , pid ))
51
+ print ("Unsubscribed from {0} with PID {1}" .format (topic , pid ))
52
+
50
53
51
54
# pylint: disable=unused-argument
52
55
def disconnected (client ):
53
56
# Disconnected function will be called when the client disconnects.
54
57
print ("Disconnected from Adafruit IO!" )
55
58
59
+
56
60
# pylint: disable=unused-argument
57
61
def message (client , feed_id , payload ):
58
62
# Message function will be called when a subscribed feed has a new value.
59
63
# The feed_id parameter identifies the feed, and the payload parameter has
60
64
# the new value.
61
65
print ("Feed {0} received new value: {1}" .format (feed_id , payload ))
62
66
67
+
63
68
# Initialize MQTT interface with the ethernet interface
64
69
MQTT .set_socket (socket , eth )
65
70
66
71
# Initialize a new MQTT Client object
67
- mqtt_client = MQTT .MQTT (broker = "http://io.adafruit.com" ,
68
- username = secrets ["aio_user" ],
69
- password = secrets ["aio_key" ])
72
+ mqtt_client = MQTT .MQTT (
73
+ broker = "http://io.adafruit.com" ,
74
+ username = secrets ["aio_user" ],
75
+ password = secrets ["aio_key" ],
76
+ )
70
77
71
78
# Initialize an Adafruit IO MQTT Client
72
79
io = IO_MQTT (mqtt_client )
0 commit comments