连接到 micro python 中的 Wifi 挂起
Connecting to Wifi in micro python hangs
我正在尝试设置一个以交互方式获取用户输入并连接到 WiFi 的功能。我可以扫描附近的网络并获取 SSID 列表,但是一旦我去实际连接程序总是挂起。我似乎无法弄清楚为什么。
import machine
import urequests
import network
from network import WLAN
def wifi_con():
station = network.WLAN(network.STA_IF)
station.active(True)
wlan = WLAN()
nets = wlan.scan()
for i in range(len(nets)):
print(str(i) + '\t' + str(nets[i][0])[2:-1])
print('Please enter the number corresponding to the SSID you wish to connect to:')
sel = -1
sel = int(input())
while sel not in range(len(nets)):
print('Please enter the number corresponding to the SSID you wish to connect to:')
print("please enter the wifi password: ")
connect_options = {
'ssid':str(nets[sel][0])[2:-1],
'password':input()
}
print(nets[sel][0], str(input()))
wlan.connect(str(nets[sel][0])[2:-1], input())
# test that we actually connected
print('getting the paste')
r = urequests.get('https://pastebin.com/raw/CZ6Mkdeg')
print(r.content)
硬件:LOLIN D32(基于esp32的板)
这是板上唯一的代码,所以我认为没有其他任何东西干扰它。
所以万一以后有人来找这个问题,我已经找到了。显然,即使我正在重置电路板,电路板仍保持着早些时候的连接。我断开了与 wifi 的连接 using this function,然后在我意识到我像白痴一样多次调用 input() 之后我的功能起作用了
我正在尝试设置一个以交互方式获取用户输入并连接到 WiFi 的功能。我可以扫描附近的网络并获取 SSID 列表,但是一旦我去实际连接程序总是挂起。我似乎无法弄清楚为什么。
import machine
import urequests
import network
from network import WLAN
def wifi_con():
station = network.WLAN(network.STA_IF)
station.active(True)
wlan = WLAN()
nets = wlan.scan()
for i in range(len(nets)):
print(str(i) + '\t' + str(nets[i][0])[2:-1])
print('Please enter the number corresponding to the SSID you wish to connect to:')
sel = -1
sel = int(input())
while sel not in range(len(nets)):
print('Please enter the number corresponding to the SSID you wish to connect to:')
print("please enter the wifi password: ")
connect_options = {
'ssid':str(nets[sel][0])[2:-1],
'password':input()
}
print(nets[sel][0], str(input()))
wlan.connect(str(nets[sel][0])[2:-1], input())
# test that we actually connected
print('getting the paste')
r = urequests.get('https://pastebin.com/raw/CZ6Mkdeg')
print(r.content)
硬件:LOLIN D32(基于esp32的板)
这是板上唯一的代码,所以我认为没有其他任何东西干扰它。
所以万一以后有人来找这个问题,我已经找到了。显然,即使我正在重置电路板,电路板仍保持着早些时候的连接。我断开了与 wifi 的连接 using this function,然后在我意识到我像白痴一样多次调用 input() 之后我的功能起作用了