From 4575ef16ad1474a3892ed57eb54c392c397d6e82 Mon Sep 17 00:00:00 2001 From: Jimmy Date: Tue, 21 Apr 2026 21:48:42 +1200 Subject: [PATCH] test(led-driver): add espnow peer and ap pm0 scripts Made-with: Cursor --- tests/peers.py | 25 +++++++++++++++++++++++++ tests/test_ap_pm0.py | 41 +++++++++++++++++++++++++++++++++++++++++ 2 files changed, 66 insertions(+) create mode 100644 tests/peers.py create mode 100644 tests/test_ap_pm0.py diff --git a/tests/peers.py b/tests/peers.py new file mode 100644 index 0000000..fcaf3ce --- /dev/null +++ b/tests/peers.py @@ -0,0 +1,25 @@ +from espnow import ESPNow +import network + +sta = network.WLAN(network.STA_IF) +sta.active(True) + +espnow = ESPNow() +espnow.active(True) + +# add_peer() expects a 6-byte MAC (bytes/bytearray), not integers. +# Unicast placeholders (not broadcast/multicast) so get_peers() lists them. +# PEERS = aa:aa:aa:aa:aa:START … aa:aa:aa:aa:aa:END (inclusive last octet). +_PREFIX = b"\xaa\xaa\xaa\xaa\xaa" +_START_LAST_OCTET = 1 +_END_LAST_OCTET = 40 +PEERS = tuple(_PREFIX + bytes((i,)) for i in range(_START_LAST_OCTET, _END_LAST_OCTET + 1)) +for peer in PEERS: + espnow.add_peer(peer) + +print("peers:", PEERS) + +for peer in PEERS: + espnow.send(peer, b"Hello, world!") + +print(espnow.get_peers()) \ No newline at end of file diff --git a/tests/test_ap_pm0.py b/tests/test_ap_pm0.py new file mode 100644 index 0000000..9a01de1 --- /dev/null +++ b/tests/test_ap_pm0.py @@ -0,0 +1,41 @@ +#!/usr/bin/env python3 +"""MicroPython AP example with power management disabled (pm=0). + +Run on device: + mpremote connect /dev/ttyACM0 run tests/test_ap_pm0.py +""" + +import network +import time + +AP_SSID = "led-ap" +AP_PASSWORD = "ledpass123" +AP_CHANNEL = 6 + + +def main(): + ap = network.WLAN(network.AP_IF) + ap.active(True) + + # Explicitly disable Wi-Fi power save for AP mode. + try: + ap.config(pm=0) + except (AttributeError, ValueError, TypeError): + try: + ap.config(pm=network.WLAN.PM_NONE) + except (AttributeError, ValueError, TypeError): + pass + + ap.config(essid=AP_SSID, password=AP_PASSWORD, channel=AP_CHANNEL, authmode=3) + + print("[ap-pm0] AP active:", ap.active()) + print("[ap-pm0] SSID:", AP_SSID) + print("[ap-pm0] IFCONFIG:", ap.ifconfig()) + print("[ap-pm0] Waiting for clients. Ctrl+C to stop.") + + while True: + time.sleep(2) + + +if __name__ == "__main__": + main()