0
0
IOT Protocolsdevops~30 mins

Rule engine for IoT data routing in IOT Protocols - Mini Project: Build & Apply

Choose your learning style9 modes available
Rule engine for IoT data routing
📖 Scenario: You are managing a smart home system where multiple IoT sensors send data. You want to create a simple rule engine that routes sensor data to different actions based on sensor type and value.
🎯 Goal: Build a basic rule engine that reads sensor data, applies routing rules, and outputs the action to take for each sensor reading.
📋 What You'll Learn
Create a dictionary with sensor data entries
Add a configuration variable for a threshold value
Write a loop that applies routing rules based on sensor type and threshold
Print the routing decisions for each sensor
💡 Why This Matters
🌍 Real World
IoT devices send data continuously. A rule engine helps decide what actions to take automatically, like turning on air conditioning or sending alerts.
💼 Career
Understanding how to route IoT data with simple rules is useful for roles in IoT development, DevOps automation, and smart system management.
Progress0 / 4 steps
1
Create sensor data dictionary
Create a dictionary called sensor_data with these exact entries: 'temperature': 22, 'humidity': 55, 'motion': 1
IOT Protocols
Need a hint?

Use curly braces to create a dictionary with keys and values separated by colons.

2
Add threshold configuration
Create a variable called temp_threshold and set it to 25 to use as the temperature threshold.
IOT Protocols
Need a hint?

Just assign the number 25 to the variable named temp_threshold.

3
Apply routing rules
Write a for loop using variables sensor and value to iterate over sensor_data.items(). Inside the loop, create a variable action and set it to 'Turn on AC' if sensor is 'temperature' and value is greater than temp_threshold. Otherwise, set action to 'No action'.
IOT Protocols
Need a hint?

Use an if-else statement inside the loop to decide the action based on sensor type and value.

4
Print routing decisions
Inside the existing for loop, add a print statement that outputs the text "Sensor: {sensor}, Value: {value}, Action: {action}" using an f-string.
IOT Protocols
Need a hint?

Use print(f"Sensor: {sensor}, Value: {value}, Action: {action}") inside the loop to show the routing results.