0
0
Raspberry Piprogramming~10 mins

Multi-device MQTT network in Raspberry Pi - 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.

Raspberry Pi
import [1]
Drag options to blanks, or click blank then click option'
Amqtt
Bmqtt.client
Cpaho.mqtt.client
Dpaho.mqtt
Attempts:
3 left
💡 Hint
Common Mistakes
Using just 'mqtt' or 'mqtt.client' which are not valid imports.
Importing 'paho.mqtt' without '.client' which does not provide the client class.
2fill in blank
medium

Complete the code to create an MQTT client instance named 'client'.

Raspberry Pi
client = [1]()
Drag options to blanks, or click blank then click option'
Amqtt.client.Client
Bpaho.Client
Cmqtt.Client
Dpaho.mqtt.client.Client
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'mqtt.Client' which is not imported directly.
Using 'paho.Client' which is incomplete.
3fill in blank
hard

Fix the error in the code to connect the client to the MQTT broker at 'broker.hivemq.com' on port 1883.

Raspberry Pi
client.[1]('broker.hivemq.com', 1883)
Drag options to blanks, or click blank then click option'
Aconnect
Bconnect_to
Cstart_connect
Dopen_connection
Attempts:
3 left
💡 Hint
Common Mistakes
Using non-existent methods like 'connect_to' or 'start_connect'.
Trying to use 'open_connection' which is not part of the MQTT client.
4fill in blank
hard

Fill both blanks to subscribe the client to the topic 'home/room1/temperature' with QoS level 1.

Raspberry Pi
client.[1]('[2]', 1)
Drag options to blanks, or click blank then click option'
Asubscribe
Bpublish
Chome/room1/temperature
Dhome/room1/humidity
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'publish' instead of 'subscribe' to listen to messages.
Subscribing to the wrong topic like humidity.
5fill in blank
hard

Fill all three blanks to publish the message '22.5' to the topic 'home/room2/humidity' with QoS 0.

Raspberry Pi
client.[1]('[2]', [3], qos=0)
Drag options to blanks, or click blank then click option'
Asubscribe
B'22.5'
Chome/room2/humidity
Dpublish
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'subscribe' instead of 'publish' to send messages.
Swapping topic and message arguments.