0
0
IOT Protocolsdevops~10 mins

MQTT client with Python (paho-mqtt) 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 import the MQTT client library.

IOT Protocols
import [1]
Drag options to blanks, or click blank then click option'
Apaho.mqtt.client as mqtt
Bmqtt
Cmqtt.client
Dpaho.mqtt
Attempts:
3 left
💡 Hint
Common Mistakes
Using just 'mqtt' or 'paho.mqtt' will cause import errors.
Misspelling the module path.
2fill in blank
medium

Complete the code to create a new MQTT client instance.

IOT Protocols
client = [1].Client()
Drag options to blanks, or click blank then click option'
Amqtt
Bpaho.mqtt.client
Cpaho.mqtt
Dclient
Attempts:
3 left
💡 Hint
Common Mistakes
Using the full import path instead of the alias.
Using 'client.Client()' which is undefined.
3fill in blank
hard

Fix 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'
Apublish
Bstart
Csubscribe
Dconnect
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'start' which is not a valid method.
Confusing 'subscribe' or 'publish' with connection.
4fill in blank
hard

Fill 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'
Asubscribe
Bconnect
Chome/temperature
Dpublish
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'publish' instead of 'subscribe'.
Using wrong topic string.
5fill in blank
hard

Fill 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'
Asubscribe
Bhome/temperature
C'22.5'
Dpublish
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'subscribe' instead of 'publish'.
Swapping topic and message values.