Add garbage collection to main loop for memory management
This commit is contained in:
6
main.py
6
main.py
@@ -2,6 +2,7 @@ from machine import Pin
|
||||
import time
|
||||
import network
|
||||
import json
|
||||
import gc # ADD THIS - for garbage collection
|
||||
|
||||
# Initialize pins (LED light onboard)
|
||||
led = Pin("LED", Pin.OUT)
|
||||
@@ -249,6 +250,11 @@ while True:
|
||||
# Pass schedule_monitor so web interface can reload config when schedules change
|
||||
web_server.check_requests(sensors, ac_monitor, heater_monitor, schedule_monitor)
|
||||
|
||||
# ===== START: Garbage Collection =====
|
||||
# Free up unused memory to prevent fragmentation
|
||||
gc.collect()
|
||||
# ===== END: Garbage Collection =====
|
||||
|
||||
# Small delay to prevent CPU overload (0.1 seconds = 10 loops per second)
|
||||
time.sleep(0.1)
|
||||
# ===== END: Main Loop =====
|
||||
Reference in New Issue
Block a user