Practice - 5 Tasks
Answer the questions below
1fill in blank
easyComplete the code to import the MQTT client library.
IOT Protocols
import [1]
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using just 'mqtt' or 'paho.mqtt' will cause import errors.
Misspelling the module path.
✗ Incorrect
The correct import for the MQTT client from the paho library is paho.mqtt.client as mqtt.
2fill in blank
mediumComplete the code to create a new MQTT client instance.
IOT Protocols
client = [1].Client() Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using the full import path instead of the alias.
Using 'client.Client()' which is undefined.
✗ Incorrect
After importing paho.mqtt.client as mqtt, you create a client with mqtt.Client().
3fill in blank
hardFix the error in the code to connect the client to the broker at 'localhost' on port 1883.
IOT Protocols
client.[1]('localhost', 1883, 60)
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'start' which is not a valid method.
Confusing 'subscribe' or 'publish' with connection.
✗ Incorrect
The method to connect the client to the MQTT broker is connect.
4fill in blank
hardFill both blanks to subscribe to the topic 'home/temperature' with QoS level 1.
IOT Protocols
client.[1]('[2]', 1)
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'publish' instead of 'subscribe'.
Using wrong topic string.
✗ Incorrect
Use subscribe method with the topic string to listen for messages.
5fill in blank
hardFill all three blanks to publish the message '22.5' to topic 'home/temperature' with QoS 0.
IOT Protocols
client.[1]('[2]', [3], 0)
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'subscribe' instead of 'publish'.
Swapping topic and message values.
✗ Incorrect
Use publish method with topic and message to send data.