Skip to content

wifi: CircuitPython's wifi.radio API on network.WLAN - #127

Merged
bdbarnett merged 1 commit into
mainfrom
wifi-radio-api
Oct 7, 2026
Merged

bdbarnett merged 1 commit into
mainfrom
wifi-radio-api

Conversation

@bdbarnett

Copy link
Copy Markdown
Contributor

This replaces lib/wifi.py with a version that gives MicroPython CircuitPython's wifi.radio API, so board code written for CircuitPython runs unchanged.

What's new:

  • radio.connect() raises ConnectionError (an OSError) with CircuitPython's reasons, and timeout=0 joins without waiting.
  • Scanning, ap_info with live RSSI, static addresses, power management, TX power, hostname, and an access point.
  • connect_from_secrets() keeps its contract. When secrets.py is missing or its network isn't in range, it now falls back to the networks wifi_manager remembered.

Two behaviours change for existing callers:

  • radio.connect() used to return None quietly when it failed. It now raises. No caller in our repos relies on the old behaviour.
  • connect_from_secrets() no longer re-syncs NTP when the board is already connected. tests/test_wifi.py now asserts that, and its fake radio gains the disconnect() and config() the new code calls.

Tested on hardware. An ESP32-S3 (LCD-7) hopped between two ESP32-P4 access points started with the new start_ap(), a→b→a→b→a, joining each in 1.1–1.4 s. Wrong password, missing network and timeout=0 behaved as documented. The wifi_manager fallback worked both without secrets.py and with a secrets.py network out of range.

Boards that freeze PyDevices (--modules pydevices) carry the old copy until their firmware is rebuilt, because frozen modules come before /lib.

connect() raises ConnectionError with CircuitPython's reasons (Authentication
failure, No network with that ssid, a timeout) and returns at once when already
on that network; timeout=0 starts a join without waiting. Adds scanning,
ap_info with live rssi, static addresses, power management, tx power,
hostname and an access point. connect_from_secrets() keeps its contract and
now falls back to the networks wifi_manager remembered when secrets.py is
missing or its network isn't in range; it skips NTP when already connected.

Tested on an ESP32-S3 (LCD-7) hopping between two P4 access points started
with start_ap(): five hops, the wrong-password, missing-network and timeout=0
cases, and the wifi_manager fallback with and without secrets.py.
@bdbarnett
bdbarnett merged commit ae30bce into main Oct 7, 2026
3 checks passed
@bdbarnett
bdbarnett deleted the wifi-radio-api branch October 7, 2026 16:50
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Development

Successfully merging this pull request may close these issues.

1 participant