ESP32 microPython的network部分,修改官方给出的例程出现了一个不理解的现象。
下面是代码
def do_connect():
print("Connecting...")
wlan.active(True)
wl = Wlanlist(wlan.scan())
if not wlan.isconnected():
if(wl.show('SSID')):#自己写的函数,用于检查是否存在对应SSID的WiFi
wlan.connect('SSID','wifimima')
while not wlan.isconnected():
pass
print("Connected")#没有生效
return 1
else:
print("connect to FISHGAN10 failed")
return 0
if wlan.isconnected():
print("Connected")
return 2
else:
return 3
#测试部分
print(do_connect())
对应的输出结果:
可以看到,在下面这个语句后面的print和return没有被执行
while not wlan.isconnected():
pass
搜索资料得pass是用于占位,那么这个while not函数是用来保证connect函数完成后程序再往下运行。那连接成功后为什么后面的语句没有执行呢。