kopia lustrzana https://github.com/tayfunulu/WiFiManager
deduplicate do_connect()
rodzic
cbf3c8f57b
commit
f991513ea6
22
main.py
22
main.py
|
@ -5,26 +5,6 @@ import time
|
|||
wlan_sta = network.WLAN(network.STA_IF)
|
||||
|
||||
|
||||
def do_connect(ssid, password):
|
||||
sta_if = network.WLAN(network.STA_IF)
|
||||
sta_if.active(True)
|
||||
if sta_if.isconnected():
|
||||
return None
|
||||
print('Trying to connect to %s...' % ssid)
|
||||
sta_if.connect(ssid, password)
|
||||
for retry in range(100):
|
||||
connected = sta_if.isconnected()
|
||||
if connected:
|
||||
break
|
||||
time.sleep(0.1)
|
||||
print('.', end='')
|
||||
if connected:
|
||||
print('\nConnected. Network config: ', sta_if.ifconfig())
|
||||
else:
|
||||
print('\nFailed. Not Connected to: ' + ssid)
|
||||
return connected
|
||||
|
||||
|
||||
def check_connection():
|
||||
global wlan_sta
|
||||
# First check if there already is any connection:
|
||||
|
@ -46,7 +26,7 @@ def check_connection():
|
|||
for ssid_found in ssids_found:
|
||||
if ssid in ssid_found[0]:
|
||||
print("OK. WiFi found.")
|
||||
if do_connect(ssid, password):
|
||||
if networkconfig.do_connect(ssid, password):
|
||||
return True
|
||||
|
||||
if not wlan_sta.isconnected():
|
||||
|
|
|
@ -13,24 +13,24 @@ ssid_password = "tayfunulu"
|
|||
server_socket = None
|
||||
|
||||
|
||||
def do_connect(ntwrk_ssid, netwrk_pass):
|
||||
def do_connect(ssid, password):
|
||||
sta_if = network.WLAN(network.STA_IF)
|
||||
sta_if.active(True)
|
||||
if not sta_if.isconnected():
|
||||
print('Trying to connect to %s...' % ntwrk_ssid)
|
||||
sta_if.active(True)
|
||||
sta_if.connect(ntwrk_ssid, netwrk_pass)
|
||||
a = 0
|
||||
while not sta_if.isconnected() | (a > 99):
|
||||
time.sleep(0.1)
|
||||
a += 1
|
||||
print('.', end='')
|
||||
if sta_if.isconnected():
|
||||
print('\nConnected. Network config: ', sta_if.ifconfig())
|
||||
return True
|
||||
else:
|
||||
print('\nFailed. Not Connected to: ' + ntwrk_ssid)
|
||||
return False
|
||||
if sta_if.isconnected():
|
||||
return None
|
||||
print('Trying to connect to %s...' % ssid)
|
||||
sta_if.connect(ssid, password)
|
||||
for retry in range(100):
|
||||
connected = sta_if.isconnected()
|
||||
if connected:
|
||||
break
|
||||
time.sleep(0.1)
|
||||
print('.', end='')
|
||||
if connected:
|
||||
print('\nConnected. Network config: ', sta_if.ifconfig())
|
||||
else:
|
||||
print('\nFailed. Not Connected to: ' + ssid)
|
||||
return connected
|
||||
|
||||
|
||||
def send_response(client, payload, status_code=200):
|
||||
|
|
Ładowanie…
Reference in New Issue