fix(main): blocking espnow rx loop and pass peer host
Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
34
src/main.py
34
src/main.py
@@ -42,31 +42,27 @@ esp.send(BROADCAST_MAC, hello)
|
||||
print("espnow hello", len(hello), "B")
|
||||
|
||||
|
||||
def _on_espnow_message(msg):
|
||||
def _on_espnow_message(host, msg):
|
||||
if not msg:
|
||||
return
|
||||
if msg[0] == WIRE_MAGIC:
|
||||
_handle_packet(msg, settings, presets)
|
||||
_handle_packet(host, msg, settings, presets)
|
||||
return
|
||||
if msg[0:1] == b"{":
|
||||
process_data(msg, settings, presets)
|
||||
|
||||
|
||||
async def main():
|
||||
while True:
|
||||
presets.tick()
|
||||
wdt.feed()
|
||||
if esp.any():
|
||||
host, msg = esp.recv(0)
|
||||
if host and msg:
|
||||
print(host, len(msg), "B")
|
||||
try:
|
||||
_on_espnow_message(msg)
|
||||
print(msg)
|
||||
except Exception as e:
|
||||
print("espnow rx error:", e)
|
||||
await asyncio.sleep(0)
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
asyncio.run(main())
|
||||
while True:
|
||||
wdt.feed()
|
||||
while esp.any():
|
||||
host, msg = esp.recv(0)
|
||||
if not host or not msg:
|
||||
continue
|
||||
print(host, len(msg), "B")
|
||||
try:
|
||||
_on_espnow_message(host, msg)
|
||||
print(msg)
|
||||
except Exception as e:
|
||||
print("espnow rx error:", e)
|
||||
presets.tick()
|
||||
|
||||
Reference in New Issue
Block a user