"""Device test: receive ESP-NOW packets on channel 5 (MicroPython).""" import espnow import machine import network import ubinascii import time CHANNEL = 5 TIMEOUT_MS = 1000 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 recv_loop(channel=CHANNEL, timeout_ms=TIMEOUT_MS): wdt = machine.WDT(timeout=WDT_TIMEOUT_MS) _set_channel(channel) e = espnow.ESPNow() e.active(True) print("recv ready ch", channel) while True: wdt.feed() host, msg = e.recv(timeout_ms) if host: mac_hex = ubinascii.hexlify(host).decode() print("rx", mac_hex, "len", len(msg), "hex", ubinascii.hexlify(msg).decode()) else: print("rx timeout") time.sleep_ms(10) if __name__ == "__main__": recv_loop()