kopia lustrzana https://github.com/tayfunulu/WiFiManager
code: fix wording / grammar
rodzic
b23e52ec53
commit
1ea05254a4
19
main.py
19
main.py
|
@ -9,7 +9,7 @@ def do_connect(ntwrk_ssid, netwrk_pass):
|
||||||
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 not sta_if.isconnected():
|
||||||
print('try to connect : ' + ntwrk_ssid + ' network...')
|
print('Trying to connect to %s...' % ntwrk_ssid)
|
||||||
sta_if.connect(ntwrk_ssid, netwrk_pass)
|
sta_if.connect(ntwrk_ssid, netwrk_pass)
|
||||||
a = 0
|
a = 0
|
||||||
while not sta_if.isconnected() | (a > 99):
|
while not sta_if.isconnected() | (a > 99):
|
||||||
|
@ -20,25 +20,24 @@ def do_connect(ntwrk_ssid, netwrk_pass):
|
||||||
print('\nConnected. Network config: ', sta_if.ifconfig())
|
print('\nConnected. Network config: ', sta_if.ifconfig())
|
||||||
return (True)
|
return (True)
|
||||||
else:
|
else:
|
||||||
print('\nProblem. Not Connected to :' + ntwrk_ssid)
|
print('\nFailed. Not Connected to: ' + ntwrk_ssid)
|
||||||
return (False)
|
return (False)
|
||||||
|
|
||||||
|
|
||||||
def check_connection():
|
def check_connection():
|
||||||
global wlan_sta
|
global wlan_sta
|
||||||
# Firstly check is there any connection
|
# First check if there already is any connection:
|
||||||
if wlan_sta.isconnected():
|
if wlan_sta.isconnected():
|
||||||
return (True)
|
return (True)
|
||||||
try:
|
try:
|
||||||
# connection of ESP to WiFi takes time
|
# ESP connecting to WiFi takes time, wait a bit and try again:
|
||||||
# wait 3 sec. and try again.
|
|
||||||
time.sleep(3)
|
time.sleep(3)
|
||||||
if not wlan_sta.isconnected():
|
if not wlan_sta.isconnected():
|
||||||
# inside passwd file. there are list of WiFi network CSV file
|
# inside passwd file, there is a list of WiFi networks (CSV format)
|
||||||
f = open("passwd.dat")
|
f = open("passwd.dat")
|
||||||
data = f.readlines()
|
data = f.readlines()
|
||||||
f.close()
|
f.close()
|
||||||
# Search WiFi's in range
|
# Search WiFis in range
|
||||||
ssids_found = wlan_sta.scan()
|
ssids_found = wlan_sta.scan()
|
||||||
|
|
||||||
# matching...
|
# matching...
|
||||||
|
@ -47,7 +46,7 @@ def check_connection():
|
||||||
|
|
||||||
for i in ssids_found:
|
for i in ssids_found:
|
||||||
if ssid_list[0] in i[0]:
|
if ssid_list[0] in i[0]:
|
||||||
print("OK. WiFi is Founded")
|
print("OK. WiFi found.")
|
||||||
if do_connect(ssid_list[0], ssid_list[1]):
|
if do_connect(ssid_list[0], ssid_list[1]):
|
||||||
return (True)
|
return (True)
|
||||||
|
|
||||||
|
@ -58,7 +57,7 @@ def check_connection():
|
||||||
return (True)
|
return (True)
|
||||||
|
|
||||||
except OSError:
|
except OSError:
|
||||||
# Web server for connection manager
|
# start web server for connection manager:
|
||||||
if networkconfig.start():
|
if networkconfig.start():
|
||||||
return (True)
|
return (True)
|
||||||
|
|
||||||
|
@ -73,4 +72,4 @@ if check_connection():
|
||||||
# import sample_mqtt.py
|
# import sample_mqtt.py
|
||||||
|
|
||||||
else:
|
else:
|
||||||
print("There is something wrong")
|
print("There is something wrong.")
|
||||||
|
|
|
@ -6,7 +6,7 @@ import time
|
||||||
wlan_ap = network.WLAN(network.AP_IF)
|
wlan_ap = network.WLAN(network.AP_IF)
|
||||||
wlan_sta = network.WLAN(network.STA_IF)
|
wlan_sta = network.WLAN(network.STA_IF)
|
||||||
|
|
||||||
# setup for ssid
|
# SSID/Password for setup
|
||||||
ssid_name = "WifiManager"
|
ssid_name = "WifiManager"
|
||||||
ssid_password = "tayfunulu"
|
ssid_password = "tayfunulu"
|
||||||
|
|
||||||
|
@ -17,7 +17,7 @@ def do_connect(ntwrk_ssid, netwrk_pass):
|
||||||
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 not sta_if.isconnected():
|
||||||
print('try to connect : ' + ntwrk_ssid + ' network...')
|
print('Trying to connect to %s...' % ntwrk_ssid)
|
||||||
sta_if.active(True)
|
sta_if.active(True)
|
||||||
sta_if.connect(ntwrk_ssid, netwrk_pass)
|
sta_if.connect(ntwrk_ssid, netwrk_pass)
|
||||||
a = 0
|
a = 0
|
||||||
|
@ -29,7 +29,7 @@ def do_connect(ntwrk_ssid, netwrk_pass):
|
||||||
print('\nConnected. Network config: ', sta_if.ifconfig())
|
print('\nConnected. Network config: ', sta_if.ifconfig())
|
||||||
return (True)
|
return (True)
|
||||||
else:
|
else:
|
||||||
print('\nProblem. Not Connected to :' + ntwrk_ssid)
|
print('\nFailed. Not Connected to: ' + ntwrk_ssid)
|
||||||
return (False)
|
return (False)
|
||||||
|
|
||||||
|
|
||||||
|
@ -117,7 +117,6 @@ def handle_configure(client, request):
|
||||||
fo = open("passwd.dat", "w")
|
fo = open("passwd.dat", "w")
|
||||||
fo.write(ssid + ";" + password + "\n")
|
fo.write(ssid + ";" + password + "\n")
|
||||||
fo.close()
|
fo.close()
|
||||||
|
|
||||||
return (True)
|
return (True)
|
||||||
else:
|
else:
|
||||||
response_footer = """
|
response_footer = """
|
||||||
|
@ -163,9 +162,9 @@ def start(port=80):
|
||||||
server_socket.bind(addr)
|
server_socket.bind(addr)
|
||||||
server_socket.listen(1)
|
server_socket.listen(1)
|
||||||
|
|
||||||
print('Connect to Wifi ssid :' + ssid_name + ' , Default pass: ' + ssid_password)
|
print('Connect to WiFi ssid ' + ssid_name + ', default password: ' + ssid_password)
|
||||||
print('And connect to esp via your favorite web browser (like 192.168.4.1)')
|
print('and access the ESP via your favorite web browser at 192.168.4.1.')
|
||||||
print('listening on', addr)
|
print('Listening on:', addr)
|
||||||
|
|
||||||
while True:
|
while True:
|
||||||
|
|
||||||
|
|
Ładowanie…
Reference in New Issue