Skip to content

wifi: let connect() take a scan result - #11309

Open
mikeysklar wants to merge 1 commit into
adafruit:esp32c5-wifi-5ghzfrom
mikeysklar:esp32c5-wifi-band
Open

wifi: let connect() take a scan result#11309
mikeysklar wants to merge 1 commit into
adafruit:esp32c5-wifi-5ghzfrom
mikeysklar:esp32c5-wifi-band

Conversation

@mikeysklar

Copy link
Copy Markdown
Collaborator

Stacked on #11308. Base is esp32c5-wifi-5ghz, so only the top commit is new here.

What

CIRCUITPY_WIFI_BAND in settings.toml pins a dual-band radio to one band.

Value Result
2.4 WIFI_BAND_MODE_2G_ONLY
5 WIFI_BAND_MODE_5G_ONLY
unset or anything else WIFI_BAND_MODE_AUTO

No new public API. Follows the CIRCUITPY_WIFI_HOSTNAME precedent, read via
settings_get_str() and guarded by CIRCUITPY_SETTINGS_TOML.

Why

AUTO sorts candidate APs by RSSI, and 2.4 GHz usually wins indoors. One room
from my AP, the same SSID connects on channel 5 rather than 149.

Setting Channel RSSI
unset (AUTO) 5 -51 dBm
5 149 -57 dBm

So on a same-SSID dual-band network there is otherwise no way to reach 5 GHz.

Design question

@dhalbert suggested a runtime property with an enum value such as BAND_2_4
instead, defaulting to 2.4. That is one IDF call here, but it is public API
needing stubs in the raspberrypi and zephyr-cp wifi ports. Happy to do that
instead if it is preferred.

Hardware tested

ESP32-C5-DevKitC-1-N8R8. Scanned channels per setting:

CIRCUITPY_WIFI_BAND Channels seen
unset both bands
2.4 2.4 GHz only
5 36, 44, 48, 149, 157
zzz both bands

TODO: attach the raw REPL transcript for the table above.

AI assistance

Claude wrote the settings lookup and the docs entry. I ran every band trial
and the connect timings on hardware and checked the channel numbers myself.

@dhalbert

dhalbert commented Sep 4, 2026

Copy link
Copy Markdown
Collaborator

The reason for a settings.toml value is to specify 2.4 vs 5 when using auto-connect.

I didn't suggest a property necessarily, it could also be an optional arg to connect() or start_ap(), which would limit the way it could change more. I don't know whether Espressif provides simultaneous dual-band connections but we should also look at the Nordic nRF7002, which is dual band.

EDIT: connect(), not start_station(), I think makes more sense.

@mikeysklar
mikeysklar marked this pull request as ready for review September 4, 2026 19:36
@mikeysklar
mikeysklar marked this pull request as draft September 4, 2026 19:42

@tannewt tannewt left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yup, I agree with Dan. This should only impact wifi auto-connect. I think connect can be specific by BSSID or channel already. Channel is especially good because it reduces scan time a ton.

We also considered having connect take a scan result to encapsulate this info. Or maybe ScanResult could have connect() itself.

Passing a Network from start_scanning_networks() uses its bssid and
channel, so reaching a specific AP needs no second scan. Replaces the
CIRCUITPY_WIFI_BAND settings key, which set the radio band globally.
@mikeysklar mikeysklar changed the title wifi: add CIRCUITPY_WIFI_BAND settings.toml override wifi: let connect() take a scan result Sep 5, 2026
@mikeysklar

mikeysklar commented Sep 5, 2026

Copy link
Copy Markdown
Collaborator Author

connect() takes a Network from a scan and uses its bssid and channel.

CIRCUITPY_WIFI_BAND is gone.

As tannewt suggested channel= is much faster (7x). Same for net or bssid=.

ALL_CHANNEL_SCAN is expensive.

10 trials each (connection time measured in seconds):

Call Mean Range Channel
connect(ssid, pw) 11.01 10.77-11.30 5
connect(ssid, pw, channel=149) 1.55 1.14-1.64 149
connect(ssid, pw, bssid=...) 1.62 1.59-1.64 149
connect(net, pw) 1.62 1.59-1.66 149

Scanning to get the Network costs 3.57s, so scan plus connect is 5.18s end to end.

@mikeysklar
mikeysklar marked this pull request as ready for review September 5, 2026 02:22
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants