feat(espnow): add debug logging and channel diagnostics

Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
jimmyandCursor committed 2026-05-29 16:00:54 +12:00
1 parent 8403df531d
commit 68eb547ec4
4 files changed
+228 -7

No files matched your search

+25 -7
View File
@@ -2,6 +2,7 @@
import asyncio
import urandom
import ubinascii
import espnow
import network
@@ -31,10 +32,17 @@ _PING_DELAY_MS_MAX = 500
_esp = None
_groups_received = False
_debug = False
def _dlog(*parts):
if _debug:
print(*parts)
def init_espnow(settings):
global _esp
global _esp, _debug
_debug = bool(settings.get("debug", False))
try:
ch = int(settings.get("wifi_channel", WIFI_CHANNEL_DEFAULT))
except (TypeError, ValueError):
@@ -43,13 +51,22 @@ def init_espnow(settings):
sta = network.WLAN(network.STA_IF)
sta.active(True)
sta.config(pm=network.WLAN.PM_NONE)
sta.config(channel=ch)
try:
sta.config(channel=ch)
except Exception as e:
print("espnow sta channel set failed:", e)
_esp = espnow.ESPNow()
_esp.active(True)
try:
_esp.add_peer(BROADCAST_MAC)
_dlog("espnow add bcast ok")
except Exception as e:
print("espnow add bcast failed:", e)
try:
actual_ch = sta.config("channel")
except Exception:
pass
actual_ch = "?"
print("espnow init ch", ch, "sta_ch", actual_ch, "debug", _debug)
return _esp
@@ -63,12 +80,13 @@ def _send_ping_rsp(host, settings, ping_id, delay_ms):
try:
try:
_esp.add_peer(host)
except Exception:
pass
_dlog("espnow ping add_peer ok", ubinascii.hexlify(host).decode())
except Exception as e:
_dlog("espnow ping add_peer skip", repr(e))
_esp.send(host, pkt)
print("espnow ping rsp", ping_id, delay_ms, "ms")
print("espnow ping rsp", ping_id, delay_ms, "ms", ubinascii.hexlify(host).decode())
except Exception as e:
print("espnow ping rsp failed:", e)
print("espnow ping rsp failed:", e, "host", ubinascii.hexlify(host).decode(), "len", len(pkt))
async def _send_ping_rsp_delayed(host, settings, ping_id):