0
0
Raspberry Piprogramming~10 mins

paho-mqtt library usage 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 from the paho-mqtt library.

Raspberry Pi
from paho.mqtt.client import [1]
Drag options to blanks, or click blank then click option'
Amqtt_client
Bmqtt
CClient
Dclient
Attempts:
3 left
💡 Hint
Common Mistakes
Using lowercase 'client' instead of 'Client'.
Trying to import 'mqtt_client' which does not exist.
2fill in blank
medium

Complete the code to create a new MQTT client instance named 'client'.

Raspberry Pi
client = [1]()
Drag options to blanks, or click blank then click option'
AClient
Bmqtt.Client
Cmqtt_client.Client
DClient()
Attempts:
3 left
💡 Hint
Common Mistakes
Using mqtt.Client without importing mqtt.
Calling Client() twice.
3fill in blank
hard

Fix the error in the code to connect the client to the broker at 'localhost' on port 1883.

Raspberry Pi
client.[1]('localhost', 1883)
Drag options to blanks, or click blank then click option'
Astart
Bconnect
CconnectBroker
Dconnect_to
Attempts:
3 left
💡 Hint
Common Mistakes
Using non-existent methods like connect_to or connectBroker.
Forgetting to call the method.
4fill in blank
hard

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

Raspberry Pi
client.[1]('home/temperature', [2])
Drag options to blanks, or click blank then click option'
Asubscribe
Bpublish
C1
D0
Attempts:
3 left
💡 Hint
Common Mistakes
Using publish instead of subscribe.
Setting QoS to 0 instead of 1.
5fill in blank
hard

Fill all three blanks to publish the message '23' to topic 'home/temperature' with QoS 0 and retain flag False.

Raspberry Pi
client.[1]('home/temperature', [2], qos=[3], retain=False)
Drag options to blanks, or click blank then click option'
Asubscribe
B'23'
C0
Dpublish
Attempts:
3 left
💡 Hint
Common Mistakes
Using subscribe instead of publish.
Passing message as a number instead of string.
Setting QoS to 1 or 2 instead of 0.