Background/aims:
I'm trying to get my Raspberry Pi Pico Wh connected to my mesh wi-fi network for a star wars themed notification light project I'm working on. I'm only able to get it connected when I specify a BSSID of the access point I want it to connect to. What I'd ideally like is to be able to give it an array of BSSID's of my access points and try them one-by-one until one works.
I've tried various ways of passing the BSSID value but I can only get it working when I hard code it. From what I've been reading using b"..."
as a string converts it to a byte array so I suspect how I've been trying to pass it isn't valid? I'm not 100% sure though as I'm still new to Micropython/Python.
(Working) Hardcoding the BSSID:
After much trial and error this code works to connect me to an access point I specify with the BSSID.
import network
wlan = network.WLAN(network.STA_IF)
wlan.active(True)
wlan.connect("SSID", "Password", bssid=b"\x00\x11\x22\x33\x44\x55")
(Not working) When I pass the BSSID as a variable:
I have tried other ways to pass the value but this is the closest I've gotten to a like for like. This code - even though it is passing the same value - gives me an 'extra positional arguments given' error.
import network
wlan = network.WLAN(network.STA_IF)
wlan.active(True)
BSSID_office = ":00:11:22:33:44:55"
print('bssid=b"' + BSSID_office.replace(":",r"\x") + '"')
wlan.connect("SSID", "Password", ('bssid=b"' + BSSID_office.replace(":",r"\x") + '"'))
This gives me the following output and error:
bssid=b"\x00\x11\x22\x33\x44\x55"
Traceback (most recent call last):
File "<stdin>", line 35, in <module>
TypeError: extra positional arguments given
I've also tried concatenating the bssid=
with an unhexified value using the ubinascii.unhexlify
function (as suggested here: https://forum.micropython.org/viewtopic.php?t=5261 which explains the exact same issue I'm facing) but that gets me a casting error:
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
TypeError: can't convert 'bytes' object to str implicitly