diff --git a/Scripts/monitors.py b/Scripts/monitors.py index e129b14..75c5565 100644 --- a/Scripts/monitors.py +++ b/Scripts/monitors.py @@ -77,6 +77,12 @@ class TemperatureMonitor(Monitor): temp = list(temps.values())[0] # Get first temp reading + # ===== ADD THIS: Validate temperature is reasonable ===== + if temp < -50 or temp > 150: # Sanity check (outside normal range) + print("⚠️ Warning: {} sensor returned invalid temp: {:.1f}°F".format(self.label, temp)) + return # Don't cache invalid reading + # ===== END: Validation ===== + # Cache the reading for web server (avoid blocking reads) self.last_temp = temp self.last_read_time = current_time diff --git a/config.json b/config.json index 1673f7c..bb64f8c 100644 --- a/config.json +++ b/config.json @@ -32,5 +32,6 @@ } ], "schedule_enabled": true, - "permanent_hold": false + "permanent_hold": false, + "temp_hold_start_time": null } \ No newline at end of file diff --git a/main.py b/main.py index e87723c..c49f8b4 100644 --- a/main.py +++ b/main.py @@ -376,20 +376,8 @@ while True: # Web requests web_server.check_requests(sensors, ac_monitor, heater_monitor, schedule_monitor, config) - # ===== RETRY NTP SYNC (if initial failed) ===== - if not ntp_synced and retry_ntp_attempts < max_ntp_attempts: - if time.time() % 10 < 1: # Every 10 seconds - if sync_ntp_time(TIMEZONE_OFFSET): - ntp_synced = True - last_ntp_sync = time.time() - print("NTP sync succeeded on retry #{} (UTC{:+d})".format(retry_ntp_attempts + 1, TIMEZONE_OFFSET)) - else: - retry_ntp_attempts += 1 - print("NTP retry {} failed".format(retry_ntp_attempts)) - # ===== PERIODIC RE-SYNC (every 24 hours) ===== - # Re-sync once a day to correct clock drift - if ntp_synced and (time.time() - last_ntp_sync) > 86400: # 24 hours in seconds + if ntp_synced and (time.time() - last_ntp_sync) > 86400: print("24-hour re-sync due...") if sync_ntp_time(TIMEZONE_OFFSET): last_ntp_sync = time.time() @@ -397,8 +385,15 @@ while True: else: print("Daily NTP re-sync failed (will retry tomorrow)") # ===== END: PERIODIC RE-SYNC ===== - # Enable garbage collection to free memory - gc.collect() + + # ===== ADD THIS: AGGRESSIVE GARBAGE COLLECTION ===== + current_time = time.time() + if int(current_time) % 5 == 0: # Every 5 seconds + gc.collect() + # Optional: Print memory stats occasionally + if int(current_time) % 60 == 0: # Every minute + print("💾 Memory free: {} KB".format(gc.mem_free() // 1024)) + # ===== END: AGGRESSIVE GC ===== time.sleep(0.1) except KeyboardInterrupt: