feat: Add static IP configuration options to config and main files. Also remove creation of config from web_server.py because I was already doing it in main.py like it should be done, somewhere first.

Fixes #25
This commit is contained in:
Aaron 2025-11-11 16:55:27 -05:00
parent b3c56864ac
commit 1016e96b58
3 changed files with 27 additions and 24 deletions

View File

@ -237,16 +237,9 @@ class TempWebServer:
try:
with open('config.json', 'r') as f:
return json.load(f)
except:
return {
'ac_target': 77.0,
'ac_swing': 1.0,
'heater_target': 80.0,
'heater_swing': 2.0,
'schedules': [],
'schedule_enabled': False,
'permanent_hold': False
}
except Exception as e:
print("Error loading config:", e)
raise # Or handle as appropriate
def _handle_schedule_update(self, request, sensors, ac_monitor, heater_monitor, schedule_monitor, config):
"""Handle schedule form submission."""
@ -646,7 +639,7 @@ class TempWebServer:
print("DEBUG: Generating status page...")
# ===== FORCE GARBAGE COLLECTION BEFORE BIG ALLOCATION =====
import gc
import gc # type: ignore
gc.collect()
print("DEBUG: Memory freed, {} bytes available".format(gc.mem_free()))
# ===== END GARBAGE COLLECTION =====
@ -1307,8 +1300,8 @@ class TempWebServer:
time_value = schedule.get('time', '')
name_value = schedule.get('name', '')
heater_value = schedule.get('heater_target', config.get('heater_target', 72.0))
ac_value = schedule.get('ac_target', config.get('ac_target', 75.0))
heater_value = schedule.get('heater_target', config.get('heater_target'))
ac_value = schedule.get('ac_target', config.get('ac_target'))
print("DEBUG: Values: time='{}', name='{}', heater={}, ac={}".format(
time_value, name_value, heater_value, ac_value))

View File

@ -1,4 +1,8 @@
{
"static_ip": "192.168.86.43",
"subnet": "255.255.255.0",
"gateway": "192.168.86.1",
"dns": "192.168.86.1",
"timezone_offset": -5,
"ac_target": 77.0,
"ac_swing": 1.0,

16
main.py
View File

@ -91,11 +91,17 @@ def load_config():
print("No saved config found, creating default config.json...")
default_config = {
'static_ip': '192.168.86.43',
'subnet': '255.255.255.0',
'gateway': '192.168.86.1',
'dns': '192.168.86.1',
'timezone_offset': -6, # Timezone offset from UTC (CST=-6, EST=-5, MST=-7, PST=-8, add 1 for DST)
'ac_target': 75.0, # Default AC target temp
'ac_swing': 1.0, # Default AC tolerance (+/- degrees)
'heater_target': 72.0, # Default heater target temp
'heater_swing': 2.0, # Default heater tolerance (+/- degrees)
'temp_hold_duration': 3600, # Default hold duration in seconds (1 hour)
'temp_hold_start_time': None, # No hold active at startup
'schedules': [ # Default 4 schedules
{
'time': '06:00',
@ -169,11 +175,11 @@ wifi = connect_wifi(led)
# Set static IP and print WiFi details
if wifi and wifi.isconnected():
# Configure static IP (easier to bookmark web interface)
static_ip = '192.168.86.43' # Change this to match your network
subnet = '255.255.255.0'
gateway = '192.168.86.1' # Usually your router IP
dns = '192.168.86.1' # Usually your router IP
# Get static IP settings from config
static_ip = config.get('static_ip')
subnet = config.get('subnet')
gateway = config.get('gateway')
dns = config.get('dns')
# Apply static IP configuration
wifi.ifconfig((static_ip, subnet, gateway, dns))