@@ -34,34 +34,40 @@ def connect(mqtt_client, userdata, flags, rc):
34
34
print ("Connected to MQTT Broker!" )
35
35
print ("Flags: {0}\n RC: {1}" .format (flags , rc ))
36
36
37
+
37
38
def disconnect (mqtt_client , userdata , rc ):
38
39
# This method is called when the mqtt_client disconnects
39
40
# from the broker.
40
41
print ("Disconnected from MQTT Broker!" )
41
42
43
+
42
44
def subscribe (mqtt_client , userdata , topic , granted_qos ):
43
45
# This method is called when the mqtt_client subscribes to a new feed.
44
46
print ("Subscribed to {0} with QOS level {1}" .format (topic , granted_qos ))
45
47
48
+
46
49
def unsubscribe (mqtt_client , userdata , topic , pid ):
47
50
# This method is called when the mqtt_client unsubscribes from a feed.
48
51
print ("Unsubscribed from {0} with PID {1}" .format (topic , pid ))
49
52
53
+
50
54
def publish (mqtt_client , userdata , topic , pid ):
51
55
# This method is called when the mqtt_client publishes data to a feed.
52
56
print ("Published to {0} with PID {1}" .format (topic , pid ))
53
57
58
+
54
59
def message (client , topic , message ):
55
60
# Method callled when a client's subscribed feed has a new value.
56
61
print ("New message on topic {0}: {1}" .format (topic , message ))
57
62
63
+
58
64
# Set up a MiniMQTT Client
59
65
mqtt_client = MQTT .MQTT (
60
66
broker = secrets ["broker" ],
61
67
username = secrets ["aio_username" ],
62
68
password = secrets ["aio_key" ],
63
69
socket_pool = socket ,
64
- ssl_context = ssl .create_default_context ()
70
+ ssl_context = ssl .create_default_context (),
65
71
)
66
72
67
73
# Connect callback handlers to mqtt_client
0 commit comments