Complete the code to subscribe to the control topic using MQTT.
client.subscribe('[1]')
The control commands are sent on the control/commands topic, so subscribing to this topic allows the device to receive control messages.
Complete the code to set the callback function for incoming control messages.
client.on_message = [1]The callback function handle_control is designed to process incoming control commands.
Fix the error in the subscription quality of service (QoS) level to ensure reliable delivery.
client.subscribe('control/commands', qos=[1])
QoS level 1 ensures that the message is delivered at least once, which is suitable for control commands.
Fill both blanks to correctly initialize the MQTT client and connect to the broker.
client = mqtt.Client([1]) client.connect([2], 1883, 60)
The client ID should be a unique identifier like 'device123'. The broker address is the server to connect to, here 'broker.example.com'.
Fill all three blanks to create a subscription with a callback that prints the received control command payload.
def [1](client, userdata, message): print('Received command:', message.[2].decode()) client.subscribe('control/commands', qos=1) client.on_message = [3]
The function handle_control processes messages. The payload contains the message data, which must be decoded. The callback is assigned to handle_control.