Update main application and dependencies

- Update main.py and run_web.py for local development
- Update microdot session handling
- Update wifi utility
This commit is contained in:
2026-01-27 13:05:07 +13:00
parent 3ed435824c
commit e74ef6d64f
4 changed files with 168 additions and 16 deletions

View File

@@ -16,6 +16,7 @@ import controllers.tab as tab
import controllers.palette as palette
import controllers.scene as scene
import controllers.pattern as pattern
import controllers.settings as settings_controller
async def main(port=80):
@@ -56,6 +57,7 @@ async def main(port=80):
app.mount(palette.controller, '/palettes')
app.mount(scene.controller, '/scenes')
app.mount(pattern.controller, '/patterns')
app.mount(settings_controller.controller, '/settings')
# Serve index.html at root
@app.route('/')
@@ -63,6 +65,12 @@ async def main(port=80):
"""Serve the main web UI."""
return send_file('templates/index.html')
# Serve settings page
@app.route('/settings')
def settings_page(request):
"""Serve the settings page."""
return send_file('templates/settings.html')
# Static file route
@app.route("/static/<path:path>")
def static_handler(request, path):
@@ -87,13 +95,13 @@ async def main(port=80):
server = asyncio.create_task(app.start_server(host="0.0.0.0", port=port))
wdt = machine.WDT(timeout=10000)
wdt.feed()
#wdt = machine.WDT(timeout=10000)
#wdt.feed()
while True:
gc.collect()
for i in range(60):
wdt.feed()
#wdt.feed()
await asyncio.sleep_ms(500)
# cleanup before ending the application

View File

@@ -2,9 +2,11 @@ import network
from time import sleep
def connect(ssid, password, ip, gateway):
if ssid is None or password is None:
print("Missing ssid or password")
if ssid is None:
print("Missing ssid")
return None
if password is None:
password = ''
try:
sta_if = network.WLAN(network.STA_IF)
if ip is not None and gateway is not None:
@@ -23,12 +25,15 @@ def connect(ssid, password, ip, gateway):
return None
def ap(ssid, password):
def ap(ssid, password, channel=None):
ap_if = network.WLAN(network.AP_IF)
ap_mac = ap_if.config('mac')
print(ssid)
ap_if.active(True)
ap_if.config(essid=ssid, password=password)
if channel is not None:
ap_if.config(essid=ssid, password=password, channel=channel)
else:
ap_if.config(essid=ssid, password=password)
ap_if.active(False)
ap_if.active(True)
print(ap_if.ifconfig())
@@ -36,3 +41,60 @@ def ap(ssid, password):
def get_mac():
ap_if = network.WLAN(network.AP_IF)
return ap_if.config('mac')
def get_ap_config():
"""Get current AP configuration."""
try:
ap_if = network.WLAN(network.AP_IF)
if ap_if.active():
config = ap_if.ifconfig()
return {
'ssid': ap_if.config('essid'),
'channel': ap_if.config('channel'),
'ip': config[0] if config else None,
'active': True
}
return {
'ssid': None,
'channel': None,
'ip': None,
'active': False
}
except Exception as e:
print(f"Error getting AP config: {e}")
return None
def get_sta_status():
"""Get current station connection status."""
try:
sta_if = network.WLAN(network.STA_IF)
if sta_if.active():
if sta_if.isconnected():
config = sta_if.ifconfig()
return {
'connected': True,
'ssid': sta_if.config('essid'),
'ip': config[0] if config else None,
'gateway': config[2] if len(config) > 2 else None,
'netmask': config[1] if len(config) > 1 else None,
'dns': config[3] if len(config) > 3 else None
}
return {
'connected': False,
'ssid': None,
'ip': None,
'gateway': None,
'netmask': None,
'dns': None
}
return {
'connected': False,
'ssid': None,
'ip': None,
'gateway': None,
'netmask': None,
'dns': None
}
except Exception as e:
print(f"Error getting STA status: {e}")
return None