Connecting to the same WiFi access point with an incorrect password succeeds, after successfully connecting and disconnecting with a valid password.
Pi Pico W 2 running: 1.25.0-preview
Do something like this:
class WC():
def __init__(self):
self._wlan: network.WLAN = network.WLAN(network.STA_IF) # WiFi client
def connect(self, ssid: str, pwd: str) -> bool:
i: int = 10
self._wlan.connect(ssid, pwd)
while i > 0 and self._wlan.status() == network.STAT_CONNECTING:
i -= 1
time.sleep(1)
if self._wlan.status() == network.STAT_GOT_IP or self._wlan.status() == 2:
self._ssid = ssid
self._pwd = pwd
return True
elif self._wlan.status() == network.STAT_CONNECTING:
log.info('Still connecting, try later’)
elif self._wlan.status() == network.STAT_IDLE:
log.info('Network idle’)
elif self._wlan.status() == network.STAT_WRONG_PASSWORD:
log.info('Connection failed. Check password’)
elif self._wlan.status() == network.STAT_NO_AP_FOUND:
log.info('Connection failed. Check ssid’)
elif self._wlan.status() == network.STAT_CONNECT_FAIL:
log.info('Connection failed %s.', self._wlan.status())
else:
log.info('Unknown Status: %s', self._wlan.status())
return False
def disconnect(self) -> boot:
self._wlan.disconnect()
time.sleep(2)
wc = WC()
wc.connect(‘ssid’, ‘goodpwd’) # Succeeds
wc.disconnect()
wc.connect(‘ssid’, ‘badpwd’) # Succeeds - NO!
Do I need to reinitialize the WLAN in the disconnect and drop the ip address - somehow?
docs: full Documentation for the Pi Pico W
a) When I want to use the following code on the Pico W:
'''
w = network.WLAN(network.STA_IF)
w.status('rssi')
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
ValueError: unknown status param
'''
I got an error!!!
But in the documentation is described exact this usage....
'''
Return the current status of the wireless connection.
When called with no argument the return value describes the network link status. The possible statuses are defined as constants:
STAT_IDLE – no connection and no activity,
STAT_CONNECTING – connecting in progress,
STAT_WRONG_PASSWORD – failed due to incorrect password,
STAT_NO_AP_FOUND – failed because no access point replied,
STAT_CONNECT_FAIL – failed due to other problems,
STAT_GOT_IP – connection successful.
When called with one argument param should be a string naming the status parameter to retrieve. Supported parameters in WiFI STA mode are: 'rssi'.
''
b) Next issue:
when I use the wifi connect method with a wrong password in a network which I logged in recently with the right password, the login seems to be successfull!!!
WHY?
WTF happens here?
For example I use the following config for my connection:
config = {'ssid': 'default', 'key': 'default'}
If I set ONLY the right ssid and let key as default the pico connects!?!
You have to give just the right 'ssid` to log in.
This is not the good behaviour I want to have!
My example is here:
https://github.com/hasenradball/PicoEx/blob/main/Pico_wifi_example.py
Frank