Skip to content

WiFi Association with specific BSSID #3403

@astrobokonon

Description

@astrobokonon

It'd be nice to be able to specify the specific mac address of the access point you want to connect to as a backup/sanity parameter in multi-access point environments.

When connecting, the exact AP associated with seems to be chosen somewhat at random - sometimes it's the strongest signal, other times it definitely isn't. In the field with MicroPython based devices, I've seen it try to connect to an AP with an RSSI of -80, rather than the one right next to it at -45. To get around that, I do an initial scan at boot, sort by strongest signals, and then connect() with the specific SSID and BSSID of the best RSSI from the scan.

Looking at the debug port during startup, it seems to be doing the same random choice - I've got two different APs broadcasting the same SSID, and it connected to the one with the "lower" signal strength (-48 vs. -40). Everything in here looks normal but I include it here just in case

I (2628) wifi:wifi driver task: 3ffff00c, prio:23, stack:3584, core=0
I (2628) system_api: Base MAC address is not set
I (2628) system_api: read default base MAC address from EFUSE
I (2628) wifi:wifi firmware version: 9c89486
I (2638) wifi:wifi certification version: v7.0
I (2638) wifi:config NVS flash: disabled
I (2638) wifi:config nano formating: disabled
I (2648) wifi:Init data frame dynamic rx buffer num: 32
I (2648) wifi:Init management frame dynamic rx buffer num: 32
I (2658) wifi:Init management short buffer num: 32
I (2658) wifi:Init dynamic tx buffer num: 32
I (2668) wifi:Init static rx buffer size: 1600
I (2668) wifi:Init static rx buffer num: 10
I (2678) wifi:Init dynamic rx buffer num: 32
I (2808) phy: phy_version: 603, 72dfd77, Jul  7 2020, 19:57:05, 0, 2
I (2808) wifi:enable tsf
I (2808) wifi:mode : softAP (7c:df:xx:xx:xx:xx)
I (2808) wifi:Total power save buffer number: 16
I (2808) wifi:Init max length of beacon: 752/752
I (2818) wifi:Init max length of beacon: 752/752
I (2928) wifi:mode : sta (7c:df:xx:xx:xx:xx)
I (4328) cp iternext: stop iteration
I (5058) wifi:new:<6,0>, old:<1,1>, ap:<255,255>, sta:<6,0>, prof:1
I (5528) wifi:state: init -> auth (b0)
I (5538) wifi:state: auth -> assoc (0)
I (5548) wifi:state: assoc -> run (10)
I (5558) wifi:connected with <MYSSID>, aid = 12, channel 6, BW20, bssid = 7a:8a:xx:xx:xx:xx
I (5558) wifi:security: WPA2-PSK, phy: bgn, rssi: -48
I (5558) wifi:pm start, type: 1

W (5568) wifi: connected
I (5598) wifi:AP's beacon interval = 102400 us, DTIM period = 1
I (7618) esp_netif_handlers: sta ip: 192.168.1.234, mask: 255.255.255.0, gw: 192.168.1.1
W (7618) wifi: got ip
I (7658) wifi:state: run -> init (0)
I (7658) wifi:pm stop, total sleep time: 1485945 us / 2090829 us

I (7658) wifi:new:<6,0>, old:<6,0>, ap:<255,255>, sta:<6,0>, prof:1

Since MAC isn't an available property of wifi.Network during wifi.radio.start_scanning_networks I can't do my usual trick here, and it looks like wifi.radio.connect() doesn't accept BSSID anyways.

Testing with CircuitPython 6.0.0-alpha.3-165-g9256e6b37 on 2020-09-11; Saola 1 w/Wroom with ESP32S2.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions