ESP-NOW: STA interface, notify browser on send failure

- Activate STA interface before ESP-NOW to fix ESP_ERR_ESPNOW_IF
- Notify browser on send failure: WebSocket sends error JSON; preset API returns 503
- Use exceptions for failure (not return value) to avoid false errors when send succeeds
- presets.js: handle server error messages in WebSocket onmessage

Made-with: Cursor
This commit is contained in:
2026-03-08 23:47:55 +13:00
parent 91bd78ab31
commit 0fdc11c0b0
4 changed files with 38 additions and 6 deletions

View File

@@ -1,3 +1,5 @@
import network
import aioespnow
@@ -20,11 +22,17 @@ class ESPNow:
if getattr(self, "_initialized", False):
return
# Initialize ESPNow once (no disk persistence)
# ESP-NOW requires a WiFi interface to be active (STA or AP). Activate STA
# so ESP-NOW has an interface to use; we don't need to connect to an AP.
try:
sta = network.WLAN(network.STA_IF)
sta.active(True)
except Exception as e:
print("ESPNow: STA active failed:", e)
self._esp = aioespnow.AIOESPNow()
self._esp.active(True)
try:
self._esp.add_peer(b"\xff\xff\xff\xff\xff\xff")
except Exception:
@@ -56,6 +64,6 @@ class ESPNow:
try:
await self._esp.asend(b"\xff\xff\xff\xff\xff\xff", payload)
except Exception as e:
# Log send failures but don't crash the app
print("ESPNow.send error:", e)
raise