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:
parent
b3c56864ac
commit
1016e96b58
@ -237,16 +237,9 @@ class TempWebServer:
|
|||||||
try:
|
try:
|
||||||
with open('config.json', 'r') as f:
|
with open('config.json', 'r') as f:
|
||||||
return json.load(f)
|
return json.load(f)
|
||||||
except:
|
except Exception as e:
|
||||||
return {
|
print("Error loading config:", e)
|
||||||
'ac_target': 77.0,
|
raise # Or handle as appropriate
|
||||||
'ac_swing': 1.0,
|
|
||||||
'heater_target': 80.0,
|
|
||||||
'heater_swing': 2.0,
|
|
||||||
'schedules': [],
|
|
||||||
'schedule_enabled': False,
|
|
||||||
'permanent_hold': False
|
|
||||||
}
|
|
||||||
|
|
||||||
def _handle_schedule_update(self, request, sensors, ac_monitor, heater_monitor, schedule_monitor, config):
|
def _handle_schedule_update(self, request, sensors, ac_monitor, heater_monitor, schedule_monitor, config):
|
||||||
"""Handle schedule form submission."""
|
"""Handle schedule form submission."""
|
||||||
@ -646,7 +639,7 @@ class TempWebServer:
|
|||||||
print("DEBUG: Generating status page...")
|
print("DEBUG: Generating status page...")
|
||||||
|
|
||||||
# ===== FORCE GARBAGE COLLECTION BEFORE BIG ALLOCATION =====
|
# ===== FORCE GARBAGE COLLECTION BEFORE BIG ALLOCATION =====
|
||||||
import gc
|
import gc # type: ignore
|
||||||
gc.collect()
|
gc.collect()
|
||||||
print("DEBUG: Memory freed, {} bytes available".format(gc.mem_free()))
|
print("DEBUG: Memory freed, {} bytes available".format(gc.mem_free()))
|
||||||
# ===== END GARBAGE COLLECTION =====
|
# ===== END GARBAGE COLLECTION =====
|
||||||
@ -1307,8 +1300,8 @@ class TempWebServer:
|
|||||||
|
|
||||||
time_value = schedule.get('time', '')
|
time_value = schedule.get('time', '')
|
||||||
name_value = schedule.get('name', '')
|
name_value = schedule.get('name', '')
|
||||||
heater_value = schedule.get('heater_target', config.get('heater_target', 72.0))
|
heater_value = schedule.get('heater_target', config.get('heater_target'))
|
||||||
ac_value = schedule.get('ac_target', config.get('ac_target', 75.0))
|
ac_value = schedule.get('ac_target', config.get('ac_target'))
|
||||||
|
|
||||||
print("DEBUG: Values: time='{}', name='{}', heater={}, ac={}".format(
|
print("DEBUG: Values: time='{}', name='{}', heater={}, ac={}".format(
|
||||||
time_value, name_value, heater_value, ac_value))
|
time_value, name_value, heater_value, ac_value))
|
||||||
|
|||||||
@ -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,
|
"timezone_offset": -5,
|
||||||
"ac_target": 77.0,
|
"ac_target": 77.0,
|
||||||
"ac_swing": 1.0,
|
"ac_swing": 1.0,
|
||||||
|
|||||||
16
main.py
16
main.py
@ -91,11 +91,17 @@ def load_config():
|
|||||||
print("No saved config found, creating default config.json...")
|
print("No saved config found, creating default config.json...")
|
||||||
|
|
||||||
default_config = {
|
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)
|
'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_target': 75.0, # Default AC target temp
|
||||||
'ac_swing': 1.0, # Default AC tolerance (+/- degrees)
|
'ac_swing': 1.0, # Default AC tolerance (+/- degrees)
|
||||||
'heater_target': 72.0, # Default heater target temp
|
'heater_target': 72.0, # Default heater target temp
|
||||||
'heater_swing': 2.0, # Default heater tolerance (+/- degrees)
|
'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
|
'schedules': [ # Default 4 schedules
|
||||||
{
|
{
|
||||||
'time': '06:00',
|
'time': '06:00',
|
||||||
@ -169,11 +175,11 @@ wifi = connect_wifi(led)
|
|||||||
|
|
||||||
# Set static IP and print WiFi details
|
# Set static IP and print WiFi details
|
||||||
if wifi and wifi.isconnected():
|
if wifi and wifi.isconnected():
|
||||||
# Configure static IP (easier to bookmark web interface)
|
# Get static IP settings from config
|
||||||
static_ip = '192.168.86.43' # Change this to match your network
|
static_ip = config.get('static_ip')
|
||||||
subnet = '255.255.255.0'
|
subnet = config.get('subnet')
|
||||||
gateway = '192.168.86.1' # Usually your router IP
|
gateway = config.get('gateway')
|
||||||
dns = '192.168.86.1' # Usually your router IP
|
dns = config.get('dns')
|
||||||
|
|
||||||
# Apply static IP configuration
|
# Apply static IP configuration
|
||||||
wifi.ifconfig((static_ip, subnet, gateway, dns))
|
wifi.ifconfig((static_ip, subnet, gateway, dns))
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user