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