Refactor main.py: replace manual temperature sensor initialization with dynamic configuration from SENSOR_CONFIG
This commit is contained in:
parent
39297d7c67
commit
e52e1a4f6b
45
main.py
45
main.py
@ -3,7 +3,7 @@ import time
|
||||
from scripts.networking import connect_wifi
|
||||
from scripts.discord_webhook import send_discord_message
|
||||
from scripts.monitors import TemperatureMonitor, WiFiMonitor, run_monitors
|
||||
from scripts.temperature_sensor import TemperatureSensor
|
||||
from scripts.temperature_sensor import get_configured_sensors, SENSOR_CONFIG
|
||||
|
||||
# Initialize pins (LED light onboard)
|
||||
led = Pin("LED", Pin.OUT)
|
||||
@ -16,34 +16,33 @@ wifi = connect_wifi(led)
|
||||
if wifi and wifi.isconnected():
|
||||
send_discord_message("Pico W online and connected ✅")
|
||||
|
||||
# Initialize temperature sensors
|
||||
inside_sensor = TemperatureSensor(pin=10, label="Inside")
|
||||
outside_sensor = TemperatureSensor(pin=11, label="Outside")
|
||||
# Get configured sensors
|
||||
sensors = get_configured_sensors()
|
||||
|
||||
# Set up monitors
|
||||
monitors = [
|
||||
WiFiMonitor(wifi, led, interval=5, reconnect_cooldown=60),
|
||||
TemperatureMonitor(
|
||||
sensor=inside_sensor,
|
||||
label="Inside",
|
||||
interval=300, # 5 minutes
|
||||
alert_high=85.0,
|
||||
alert_low=32.0,
|
||||
log_file="/temp_logs.csv"
|
||||
),
|
||||
TemperatureMonitor(
|
||||
sensor=outside_sensor,
|
||||
label="Outside",
|
||||
interval=300, # 5 minutes
|
||||
alert_high=100.0,
|
||||
alert_low=20.0,
|
||||
log_file="/temp_logs.csv"
|
||||
),
|
||||
# Add more monitors here later:
|
||||
# SoilMoistureMonitor(pin=26, interval=600),
|
||||
# LightLevelMonitor(pin=27, interval=900),
|
||||
]
|
||||
|
||||
# Add temperature monitors from config
|
||||
for key, sensor in sensors.items():
|
||||
config = SENSOR_CONFIG[key]
|
||||
|
||||
# Inside temp alerts go to separate channel
|
||||
send_to_alert_channel = (key == 'inside')
|
||||
|
||||
monitors.append(
|
||||
TemperatureMonitor(
|
||||
sensor=sensor,
|
||||
label=config['label'],
|
||||
interval=300, # 5 minutes
|
||||
alert_high=config['alert_high'],
|
||||
alert_low=config['alert_low'],
|
||||
log_file="/temp_logs.csv",
|
||||
send_alerts_to_separate_channel=send_to_alert_channel
|
||||
)
|
||||
)
|
||||
|
||||
# Main monitoring loop
|
||||
while True:
|
||||
run_monitors(monitors)
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user