Add favicon handler and heartbeat LED blink.
This keeps the UI console clean and makes device status visible. Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
17
src/main.py
17
src/main.py
@@ -2,6 +2,7 @@ import asyncio
|
|||||||
import gc
|
import gc
|
||||||
import json
|
import json
|
||||||
import machine
|
import machine
|
||||||
|
from machine import Pin
|
||||||
from microdot import Microdot, send_file
|
from microdot import Microdot, send_file
|
||||||
from microdot.websocket import with_websocket
|
from microdot.websocket import with_websocket
|
||||||
from microdot.session import Session
|
from microdot.session import Session
|
||||||
@@ -23,6 +24,7 @@ from models.espnow import ESPNow
|
|||||||
|
|
||||||
async def main(port=80):
|
async def main(port=80):
|
||||||
settings = Settings()
|
settings = Settings()
|
||||||
|
print(settings)
|
||||||
print("Starting")
|
print("Starting")
|
||||||
|
|
||||||
sta = network.WLAN(network.STA_IF)
|
sta = network.WLAN(network.STA_IF)
|
||||||
@@ -72,6 +74,11 @@ async def main(port=80):
|
|||||||
"""Serve the settings page."""
|
"""Serve the settings page."""
|
||||||
return send_file('templates/settings.html')
|
return send_file('templates/settings.html')
|
||||||
|
|
||||||
|
# Favicon: avoid 404 in browser console (no file needed)
|
||||||
|
@app.route('/favicon.ico')
|
||||||
|
def favicon(request):
|
||||||
|
return '', 204
|
||||||
|
|
||||||
# Static file route
|
# Static file route
|
||||||
@app.route("/static/<path:path>")
|
@app.route("/static/<path:path>")
|
||||||
def static_handler(request, path):
|
def static_handler(request, path):
|
||||||
@@ -107,10 +114,20 @@ async def main(port=80):
|
|||||||
#wdt = machine.WDT(timeout=10000)
|
#wdt = machine.WDT(timeout=10000)
|
||||||
#wdt.feed()
|
#wdt.feed()
|
||||||
|
|
||||||
|
# Initialize heartbeat LED (XIAO ESP32S3 built-in LED on GPIO 21)
|
||||||
|
|
||||||
|
led = Pin(21, Pin.OUT)
|
||||||
|
|
||||||
|
|
||||||
|
led_state = False
|
||||||
|
|
||||||
while True:
|
while True:
|
||||||
gc.collect()
|
gc.collect()
|
||||||
for i in range(60):
|
for i in range(60):
|
||||||
#wdt.feed()
|
#wdt.feed()
|
||||||
|
# Heartbeat: toggle LED every 500 ms
|
||||||
|
|
||||||
|
led.value(not led.value())
|
||||||
await asyncio.sleep_ms(500)
|
await asyncio.sleep_ms(500)
|
||||||
# cleanup before ending the application
|
# cleanup before ending the application
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user