@@ -34,34 +34,40 @@ def connect(mqtt_client, userdata, flags, rc):
3434 print ("Connected to MQTT Broker!" )
3535 print ("Flags: {0}\n RC: {1}" .format (flags , rc ))
3636
37+
3738def disconnect (mqtt_client , userdata , rc ):
3839 # This method is called when the mqtt_client disconnects
3940 # from the broker.
4041 print ("Disconnected from MQTT Broker!" )
4142
43+
4244def subscribe (mqtt_client , userdata , topic , granted_qos ):
4345 # This method is called when the mqtt_client subscribes to a new feed.
4446 print ("Subscribed to {0} with QOS level {1}" .format (topic , granted_qos ))
4547
48+
4649def unsubscribe (mqtt_client , userdata , topic , pid ):
4750 # This method is called when the mqtt_client unsubscribes from a feed.
4851 print ("Unsubscribed from {0} with PID {1}" .format (topic , pid ))
4952
53+
5054def publish (mqtt_client , userdata , topic , pid ):
5155 # This method is called when the mqtt_client publishes data to a feed.
5256 print ("Published to {0} with PID {1}" .format (topic , pid ))
5357
58+
5459def message (client , topic , message ):
5560 # Method callled when a client's subscribed feed has a new value.
5661 print ("New message on topic {0}: {1}" .format (topic , message ))
5762
63+
5864# Set up a MiniMQTT Client
5965mqtt_client = MQTT .MQTT (
6066 broker = secrets ["broker" ],
6167 username = secrets ["aio_username" ],
6268 password = secrets ["aio_key" ],
6369 socket_pool = socket ,
64- ssl_context = ssl .create_default_context ()
70+ ssl_context = ssl .create_default_context (),
6571)
6672
6773# Connect callback handlers to mqtt_client
0 commit comments