Add ESPNow preset send backend support
Implement ESPNow helper model, WebSocket forwarding, and /presets/send endpoint that chunks and broadcasts presets to devices.
This commit is contained in:
22
src/main.py
22
src/main.py
@@ -1,10 +1,11 @@
|
||||
import asyncio
|
||||
from settings import Settings
|
||||
import gc
|
||||
import json
|
||||
import machine
|
||||
from microdot import Microdot, send_file
|
||||
from microdot.websocket import with_websocket
|
||||
from microdot.session import Session
|
||||
from settings import Settings
|
||||
|
||||
import aioespnow
|
||||
import network
|
||||
@@ -17,6 +18,7 @@ import controllers.palette as palette
|
||||
import controllers.scene as scene
|
||||
import controllers.pattern as pattern
|
||||
import controllers.settings as settings_controller
|
||||
from models.espnow import ESPNow
|
||||
|
||||
|
||||
async def main(port=80):
|
||||
@@ -25,10 +27,8 @@ async def main(port=80):
|
||||
|
||||
network.WLAN(network.STA_IF).active(True)
|
||||
|
||||
|
||||
e = aioespnow.AIOESPNow()
|
||||
e.active(True)
|
||||
e.add_peer(b"\xbb\xbb\xbb\xbb\xbb\xbb")
|
||||
# Initialize ESPNow singleton (config + peers)
|
||||
esp = ESPNow()
|
||||
|
||||
app = Microdot()
|
||||
|
||||
@@ -85,9 +85,17 @@ async def main(port=80):
|
||||
async def ws(request, ws):
|
||||
while True:
|
||||
data = await ws.receive()
|
||||
print(data)
|
||||
if data:
|
||||
await e.asend(b"\xbb\xbb\xbb\xbb\xbb\xbb", data)
|
||||
print(data)
|
||||
# Debug: log incoming WebSocket data
|
||||
try:
|
||||
parsed = json.loads(data)
|
||||
print("WS received JSON:", parsed)
|
||||
except Exception:
|
||||
print("WS received raw:", data)
|
||||
|
||||
# Forward raw JSON payload over ESPNow to configured peers
|
||||
await esp.send(data)
|
||||
else:
|
||||
break
|
||||
|
||||
|
||||
Reference in New Issue
Block a user