0
0
Raspberry Piprogramming~10 mins

Why MQTT is the IoT standard in Raspberry Pi - Test Your Understanding

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'
Apaho.client
Bmqtt.client
Cpaho.mqtt.client
Dmqtt
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'mqtt.client' which does not exist.
Importing just 'mqtt' without the full path.
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'
Apaho.mqtt.client.Client
Bpaho.Client
Cpaho.mqtt.Client
Dmqtt.Client
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'mqtt.Client' which is incomplete.
Using 'paho.Client' which is incorrect.
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.connect([1], 1883)
Drag options to blanks, or click blank then click option'
Abroker.hivemq.com
B'mqtt.eclipse.org'
C'localhost'
D'broker.hivemq.com'
Attempts:
3 left
💡 Hint
Common Mistakes
Passing the broker address without quotes causing a NameError.
Using a wrong broker address.
4fill in blank
hard

Fill both blanks to publish the message 'Hello IoT' to the topic 'home/temperature'.

Raspberry Pi
client.publish([1], [2])
Drag options to blanks, or click blank then click option'
A'home/temperature'
B'Hello IoT'
C'home/humidity'
D'IoT message'
Attempts:
3 left
💡 Hint
Common Mistakes
Swapping topic and message arguments.
Using wrong topic or message strings.
5fill in blank
hard

Fill all three blanks to subscribe to the topic 'home/lights' and start the network loop.

Raspberry Pi
client.[1]('[2]')
client.[3]()
Drag options to blanks, or click blank then click option'
Asubscribe
Bon_message
Cloop_start
Dhome/lights
Attempts:
3 left
💡 Hint
Common Mistakes
Using connect instead of subscribe.
Not starting the network loop causing no messages received.