0
0
IOT Protocolsdevops~10 mins

Publish-subscribe architecture 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 publish a message to a topic using MQTT.

IOT Protocols
client.publish('[1]', 'Hello World')
Drag options to blanks, or click blank then click option'
Ahome/livingroom/temperature
Bconnect
Csubscribe
Ddisconnect
Attempts:
3 left
💡 Hint
Common Mistakes
Using method names like 'connect' or 'subscribe' as the topic name.
Leaving the topic name blank or using invalid strings.
2fill in blank
medium

Complete the code to subscribe to a topic to receive messages.

IOT Protocols
client.[1]('home/kitchen/humidity')
Drag options to blanks, or click blank then click option'
Apublish
Bsubscribe
Cconnect
Ddisconnect
Attempts:
3 left
💡 Hint
Common Mistakes
Using publish instead of subscribe to listen for messages.
Confusing connection methods with subscription.
3fill in blank
hard

Fix the error in the code to correctly connect to the MQTT broker.

IOT Protocols
client.[1]('mqtt.example.com', 1883)
Drag options to blanks, or click blank then click option'
Aconnect
Bpublish
Csubscribe
Ddisconnect
Attempts:
3 left
💡 Hint
Common Mistakes
Using publish or subscribe instead of connect to connect.
Omitting the port number or using wrong method names.
4fill in blank
hard

Fill both blanks to create a dictionary comprehension that maps topics to their message lengths for topics with messages longer than 5 characters.

IOT Protocols
{topic: len(message) for topic, message in messages.items() if len(message) [1] [2]
Drag options to blanks, or click blank then click option'
A>
B5
C<
D==
Attempts:
3 left
💡 Hint
Common Mistakes
Using < or == instead of >.
Swapping the number and operator positions.
5fill in blank
hard

Fill all three blanks to create a dictionary comprehension that maps uppercase topic names to message sizes for messages with size greater than 10.

IOT Protocols
{ [1]: [2] for topic, message in data.items() if len(message) [3] 10 }
Drag options to blanks, or click blank then click option'
Atopic.upper()
Blen(message)
C>
Dtopic
Attempts:
3 left
💡 Hint
Common Mistakes
Using the original topic name instead of uppercase.
Using wrong comparison operators or values.