0
0
IOT Protocolsdevops~10 mins

Publishing sensor data 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 sensor data to the MQTT broker.

IOT Protocols
client.[1]("sensor/temperature", "22.5")
Drag options to blanks, or click blank then click option'
Apublish
Bconnect
Csubscribe
Ddisconnect
Attempts:
3 left
💡 Hint
Common Mistakes
Using subscribe instead of publish
Trying to connect instead of sending data
2fill in blank
medium

Complete the code to connect the client to the MQTT broker at 'broker.hivemq.com'.

IOT Protocols
client.[1]("broker.hivemq.com", 1883, 60)
Drag options to blanks, or click blank then click option'
Apublish
Bsubscribe
Cconnect
Ddisconnect
Attempts:
3 left
💡 Hint
Common Mistakes
Using publish instead of connect
Trying to disconnect before connecting
3fill in blank
hard

Fix the error in the code to publish JSON sensor data correctly.

IOT Protocols
client.publish("sensor/humidity", [1])
Drag options to blanks, or click blank then click option'
Ajson.load({'humidity': 45})
B{'humidity': 45}
C45
Djson.dumps({'humidity': 45})
Attempts:
3 left
💡 Hint
Common Mistakes
Publishing a dictionary directly
Using json.load instead of json.dumps
4fill in blank
hard

Fill both blanks to create a dictionary comprehension that publishes sensor readings above 30.

IOT Protocols
filtered_data = {sensor: value[1] for sensor, value in readings.items() if value [2] 30}
Drag options to blanks, or click blank then click option'
A**2
B>
C<
D*2
Attempts:
3 left
💡 Hint
Common Mistakes
Using exponentiation instead of multiplication
Filtering values less than 30
5fill in blank
hard

Fill all three blanks to create a dictionary of sensor names in uppercase with values above 50.

IOT Protocols
result = [1]: [2] for [3], [2] in data.items() if [2] > 50
Drag options to blanks, or click blank then click option'
Asensor.upper()
Bvalue
Csensor
Ddata
Attempts:
3 left
💡 Hint
Common Mistakes
Using data as iteration variable
Using sensor instead of sensor.upper() for keys