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