Complete the code to publish a message to the correct MQTT topic.
client.publish('[1]', 'Hello World')
The MQTT topic uses slashes / to separate levels in the topic hierarchy.
Complete the code to subscribe to all temperature topics under 'home'.
client.subscribe('[1]')
# in the middle of the topic, which is invalid.The plus sign + is a single-level wildcard in MQTT topics.
Fix the error in the topic filter to subscribe to all sensors under 'home'.
client.subscribe('[1]')
# in the middle of the topic filter.The # wildcard matches all subtopics from the point it is used.
Fill both blanks to create a topic filter that matches any sensor data in any room under 'home'.
client.subscribe('home/[1]/[2]')
# too early or in the wrong position.The first + matches any single room, and # matches all subtopics after that.
Fill all three blanks to create a dictionary comprehension that maps sensor names to their latest values from a topic list.
sensor_data = { [1]: [2] for [3] in topics if 'sensor' in [3] }This comprehension extracts the sensor name from the topic string and maps it to its value.