feat(espnow): add debug logging and channel diagnostics
Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
47
tests/device_test_send_ch5.py
Normal file
47
tests/device_test_send_ch5.py
Normal file
@@ -0,0 +1,47 @@
|
||||
"""Device test: send one ESP-NOW packet on channel 5 (MicroPython)."""
|
||||
|
||||
import espnow
|
||||
import machine
|
||||
import network
|
||||
import ubinascii
|
||||
|
||||
|
||||
CHANNEL = 5
|
||||
DEST_HEX = "ffffffffffff"
|
||||
PAYLOAD_HEX = "4c0501000000"
|
||||
WDT_TIMEOUT_MS = 10000
|
||||
|
||||
|
||||
def _set_channel(channel):
|
||||
sta = network.WLAN(network.STA_IF)
|
||||
sta.active(True)
|
||||
sta.config(pm=network.WLAN.PM_NONE)
|
||||
sta.config(channel=channel)
|
||||
|
||||
|
||||
def _add_peer(esp, dest, channel):
|
||||
try:
|
||||
esp.add_peer(dest, channel=channel)
|
||||
except TypeError:
|
||||
esp.add_peer(dest)
|
||||
except OSError:
|
||||
pass
|
||||
|
||||
|
||||
def send_once(dest_hex=DEST_HEX, payload_hex=PAYLOAD_HEX, channel=CHANNEL):
|
||||
wdt = machine.WDT(timeout=WDT_TIMEOUT_MS)
|
||||
wdt.feed()
|
||||
dest = ubinascii.unhexlify(dest_hex)
|
||||
pkt = ubinascii.unhexlify(payload_hex)
|
||||
_set_channel(channel)
|
||||
e = espnow.ESPNow()
|
||||
e.active(True)
|
||||
_add_peer(e, dest, channel)
|
||||
wdt.feed()
|
||||
ok = e.send(dest, pkt, True)
|
||||
print("sent", ok, "ch", channel, "dest", dest_hex, "len", len(pkt))
|
||||
return ok
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
send_once()
|
||||
Reference in New Issue
Block a user