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

@@ -179,14 +179,20 @@ async def send_presets(request, session):
batch = test_batch
last_msg = test_msg
else:
await send_chunk(batch)
try:
await send_chunk(batch)
except Exception:
return json.dumps({"error": "ESP-NOW send failed"}), 503, {'Content-Type': 'application/json'}
await asyncio.sleep_ms(SEND_DELAY_MS)
messages_sent += 1
batch = {name: preset_obj}
last_msg = build_message(presets=batch, save=save_flag, default=default_id)
if batch:
await send_chunk(batch)
try:
await send_chunk(batch)
except Exception:
return json.dumps({"error": "ESP-NOW send failed"}), 503, {'Content-Type': 'application/json'}
await asyncio.sleep_ms(SEND_DELAY_MS)
messages_sent += 1