Complete the code to subscribe to the MQTT topic for receiving sensor data.
client.subscribe('[1]')
The MQTT client subscribes to the topic sensor/data to receive sensor data messages.
Complete the code to filter incoming data points where temperature is above 30 degrees.
filtered_data = [d for d in data if d['temperature'] [1] 30]
The filter keeps data points where temperature is greater than 30.
Fix the error in the code to publish JSON data to the MQTT topic.
client.publish('sensor/data', [1].dumps(payload))
The json.dumps() function converts the payload dictionary to a JSON string for publishing.
Fill both blanks to create a dictionary comprehension that maps device IDs to their latest temperature readings if above 25.
{device['id']: device['temperature'] for device in devices if device['temperature'] [1] [2]The comprehension filters devices with temperature greater than 25 and maps their IDs to temperatures.
Fill all four blanks to create a dictionary comprehension that maps sensor names in uppercase to their values if the value is below 50.
{ [1]: [2] for [3], [4] in sensors.items() if [2] < 50 }The comprehension maps sensor names converted to uppercase to their values, filtering values below 50.