0
0
IOT Protocolsdevops~10 mins

Subscribing to control commands in IOT Protocols - Interactive Code Practice

Choose your learning style9 modes available
Practice - 5 Tasks
Answer the questions below
1fill in blank
easy

Complete the code to subscribe to the control topic using MQTT.

IOT Protocols
client.subscribe('[1]')
Drag options to blanks, or click blank then click option'
Acontrol/commands
Bdata/updates
Csensor/readings
Dalerts/warnings
Attempts:
3 left
💡 Hint
Common Mistakes
Subscribing to a data or sensor topic instead of the control topic.
Using an incorrect topic string with typos.
2fill in blank
medium

Complete the code to set the callback function for incoming control messages.

IOT Protocols
client.on_message = [1]
Drag options to blanks, or click blank then click option'
Ahandle_data
Bprocess_sensor
Chandle_control
Don_connect
Attempts:
3 left
💡 Hint
Common Mistakes
Assigning the wrong callback function that does not handle control commands.
Confusing the on_connect callback with on_message.
3fill in blank
hard

Fix the error in the subscription quality of service (QoS) level to ensure reliable delivery.

IOT Protocols
client.subscribe('control/commands', qos=[1])
Drag options to blanks, or click blank then click option'
A1
B3
C-1
D0
Attempts:
3 left
💡 Hint
Common Mistakes
Using an invalid QoS value like 3 or -1.
Using QoS 0 which may lose messages.
4fill in blank
hard

Fill both blanks to correctly initialize the MQTT client and connect to the broker.

IOT Protocols
client = mqtt.Client([1])
client.connect([2], 1883, 60)
Drag options to blanks, or click blank then click option'
A'device123'
B'broker.example.com'
C'control/commands'
D'user1'
Attempts:
3 left
💡 Hint
Common Mistakes
Using a topic name as client ID or broker address.
Using username instead of client ID.
5fill in blank
hard

Fill all three blanks to create a subscription with a callback that prints the received control command payload.

IOT Protocols
def [1](client, userdata, message):
    print('Received command:', message.[2].decode())

client.subscribe('control/commands', qos=1)
client.on_message = [3]
Drag options to blanks, or click blank then click option'
Ahandle_control
Bpayload
Dtopic
Attempts:
3 left
💡 Hint
Common Mistakes
Using different names for the function and callback assignment.
Accessing message.topic instead of message.payload for the command data.