WLAN.connect with bssid?

All ESP32 boards running MicroPython.
Target audience: MicroPython users with an ESP32 board.
Post Reply
Taki7o7
Posts: 9
Joined: Sun Jul 03, 2022 11:50 pm

WLAN.connect with bssid?

Post by Taki7o7 » Wed Jul 13, 2022 10:55 am

Hey there, i want to prevent connecting to a network with the same name, so i'd like to use the bssid parameter, but it won't really let me

Code: Select all

def do_connect():
    import network
    sta_if = network.WLAN(network.STA_IF)
    if not sta_if.isconnected():
        print('connecting to network...')
        sta_if.active(True)
        sta_if.connect(ssid='myssid', password='mypass', bssid='5c:5c:5c:5c:5c:5c')
        while not sta_if.isconnected():
            pass
    print('network config:', sta_if.ifconfig())
    
do_connect()
It throws TypeError: extra keyword arguments given

what am I doing wrong? :(

Taki7o7
Posts: 9
Joined: Sun Jul 03, 2022 11:50 pm

Re: WLAN.connect with bssid?

Post by Taki7o7 » Wed Jul 13, 2022 11:49 am

Hmm, seems thats not supported at all (anymore?!) Also, no WPS? Isn't just the SSID a really bad identifier to use?

User avatar
jimmo
Posts: 2754
Joined: Tue Aug 08, 2017 1:57 am
Location: Sydney, Australia
Contact:

Re: WLAN.connect with bssid?

Post by jimmo » Wed Jul 13, 2022 2:09 pm

Taki7o7 wrote:
Wed Jul 13, 2022 11:49 am
Hmm, seems thats not supported at all (anymore?!) Also, no WPS? Isn't just the SSID a really bad identifier to use?
I'm fairly sure that the bssid is supported on ESP32, PYBD, and RP2 PicoW. Which port are you using?

WPS is not supported.

Taki7o7
Posts: 9
Joined: Sun Jul 03, 2022 11:50 pm

Re: WLAN.connect with bssid?

Post by Taki7o7 » Wed Jul 13, 2022 2:29 pm

jimmo wrote:
Wed Jul 13, 2022 2:09 pm
Taki7o7 wrote:
Wed Jul 13, 2022 11:49 am
Hmm, seems thats not supported at all (anymore?!) Also, no WPS? Isn't just the SSID a really bad identifier to use?
I'm fairly sure that the bssid is supported on ESP32, PYBD, and RP2 PicoW. Which port are you using?

WPS is not supported.
well, ESP32 generic

User avatar
karfas
Posts: 193
Joined: Sat Jan 16, 2021 12:53 pm
Location: Vienna, Austria

Re: WLAN.connect with bssid?

Post by karfas » Wed Jul 13, 2022 2:41 pm

Taki7o7 wrote:
Wed Jul 13, 2022 10:55 am
Hey there, i want to prevent connecting to a network with the same name, so i'd like to use the bssid parameter, but it won't really let me

Code: Select all

        sta_if.connect(ssid='myssid', password='mypass', bssid='5c:5c:5c:5c:5c:5c')
It throws TypeError: extra keyword arguments given
Router name and password are positional parameters.
The only keyword argument allowed is bssid - you get the extra keyword exception for ssid= and/or password=.

Code: Select all

        sta_if.connect('myssid', 'mypass', bssid='5c:5c:5c:5c:5c:5c')
Can also be found by reading the station example in the fine manual at https://docs.micropython.org/en/latest/ ... ckref.html
A few hours of debugging might save you from minutes of reading the documentation! :D
My repositories: https://github.com/karfas

Taki7o7
Posts: 9
Joined: Sun Jul 03, 2022 11:50 pm

Re: WLAN.connect with bssid?

Post by Taki7o7 » Wed Jul 13, 2022 3:22 pm

karfas wrote:
Wed Jul 13, 2022 2:41 pm
Taki7o7 wrote:
Wed Jul 13, 2022 10:55 am
Hey there, i want to prevent connecting to a network with the same name, so i'd like to use the bssid parameter, but it won't really let me

Code: Select all

        sta_if.connect(ssid='myssid', password='mypass', bssid='5c:5c:5c:5c:5c:5c')
It throws TypeError: extra keyword arguments given
Router name and password are positional parameters.
The only keyword argument allowed is bssid - you get the extra keyword exception for ssid= and/or password=.

Code: Select all

        sta_if.connect('myssid', 'mypass', bssid='5c:5c:5c:5c:5c:5c')
Can also be found by reading the station example in the fine manual at https://docs.micropython.org/en/latest/ ... ckref.html
oh damn, thank you so much. Also i passed the bssid in wrong format ^^

Greetings from vienna to vienna :D

Jibun no kage
Posts: 144
Joined: Mon Jul 25, 2022 9:45 pm

Re: WLAN.connect with bssid?

Post by Jibun no kage » Mon Aug 01, 2022 2:57 am

We sure it is supported for Pico, i.e. rp2? explicit use of bssid? I can't seem to get it to work. If I pass a MAC style string as bssid, I value error. If I convert the bssid to a unhexify bytes array removing the colons, I don't get any error but the connection never happens, just an endless loop where isconnected is always false.

I know the ssid and passphrase are right, they work when I let the connection attempt find the router without the explicit bssid connection attempt.

As least under Pico or rp2, the ssid and passphrase appear to be required otherwise you get a type error if the ssid is missing, and you get EPERM error if the passphrase is missing.

Post Reply