0
0
IOT Protocolsdevops~10 mins

CBOR for constrained devices 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 encode a simple integer using CBOR.

IOT Protocols
encoded = cbor2.dumps([1])
Drag options to blanks, or click blank then click option'
A42
B'42'
C3.14
DNone
Attempts:
3 left
💡 Hint
Common Mistakes
Using a string '42' instead of integer 42
Using None which encodes as null
Using a float instead of integer
2fill in blank
medium

Complete the code to decode CBOR data back to a Python object.

IOT Protocols
decoded = cbor2.loads([1])
Drag options to blanks, or click blank then click option'
A42
B'\x18\x2a'
Cb'\x18\x2a'
DNone
Attempts:
3 left
💡 Hint
Common Mistakes
Passing a string instead of bytes
Passing an integer directly
Passing None
3fill in blank
hard

Fix the error in the CBOR encoding of a dictionary.

IOT Protocols
encoded = cbor2.dumps([1])
Drag options to blanks, or click blank then click option'
A{temp: 22, humidity: 60}
B['temp', 22, 'humidity', 60]
C{'temp': '22', 'humidity': '60'}
D{'temp': 22, 'humidity': 60}
Attempts:
3 left
💡 Hint
Common Mistakes
Using a list instead of dict
Using unquoted keys
Using string values instead of integers
4fill in blank
hard

Fill both blanks to create a CBOR map comprehension filtering sensor data above 50.

IOT Protocols
{sensor: data[1] for sensor, data in readings.items() if data [2] 50}
Drag options to blanks, or click blank then click option'
A**2
B>
C>=
D*
Attempts:
3 left
💡 Hint
Common Mistakes
Using multiplication * instead of power **
Using >= instead of >
Using incorrect operators causing syntax errors
5fill in blank
hard

Fill all three blanks to create a filtered CBOR map with uppercase keys and values above 30.

IOT Protocols
filtered = { [1]: [2] for [3], [2] in sensor_data.items() if [2] > 30 }
Drag options to blanks, or click blank then click option'
Asensor.upper()
Bvalue
Csensor
Ddata
Attempts:
3 left
💡 Hint
Common Mistakes
Using wrong variable names
Not uppercasing keys
Using 'data' instead of 'value'