I am trying to do a simple function that tells me if certain Wi-Fi networks are "connectable" (the test one is the one I am using at home, therefore: it sure is "connectable") without using scan (), because scan ( ) gives me all the networks (mine and those of my neighbors) and I only want mine, the "connectable" ones. The function is
Code: Select all
import network
from time import sleep
cfg=[('MIWIFI_2G_kYXg', 'mypassword')]
def FilterSSID():
goodStations=[]
for ssid,psw in cfg:
print (ssid,psw)
station=network.WLAN(network.STA_IF)
if not station.active():
station.active(True)
m=5
while m>0 and not station.isconnected():
try:
station.connect (ss,pw)
except:
print ("err",m)
m-=1
sleep(1)
if station.isconnected():
good.append([ssid,psw])
station.disconnect()
m=10
while station.isconnected() and m>0:
m-=1
sleep(1)
return goodStations
print (FilterSSID())
Code: Select all
>>> %Run -c $EDITOR_CONTENT
myssid mypassword
err 5
err 4
err 3
err 2
err 1
[]
>>>
Instead, if, from the IDE console I do
Code: Select all
>>> import network
>>> st=network.WLAN(network.STA_IF)
>>> st.scan()
Code: Select all
[(b'MIWIFI_2G_kYXg', b'\x88]\xfb\xca\xf1\x8c', 11, -66, 4, False), (b'MIWIFI_2G_kYXg', b'\x8c\xde\xf9\x0b4\n', 11, -75, 4, False), (b'MiFibra-4526-24G', b'j\xa2"pE*', 6, -84, 3, False), (b'MiFibra-4526', b'\x04\xa2"pE(', 6, -85, 3, False), (b'MiFibra-2AB3', b'H\x8d6\x17*\xb5', 1, -88, 3, False), (b'MOVISTAR_2898', b'4W`f(\x99', 11, -90, 3, False), (b'MOVISTAR_6BD0', b'\x94\x91\x7f\xe8k\xdf', 6, -92, 3, False), (b'MIWIFI_2G_U9CG', b'\xf4\xb5\xaa\x97\x05\x85', 11, -92, 4, False), (b'MiFibra-3CE4', b'L\x1b\x86\xdd<\xe6', 1, -94, 3, False)]
I'm using a ESP-32 dev kit (WROOM-32) and Thonny IDE.
Do you know what can happen?