some simple python syntax fixes

pull/3/head
Thomas Waldmann 2017-12-11 15:12:22 +01:00
rodzic 1ea05254a4
commit 72292a72ab
2 zmienionych plików z 16 dodań i 16 usunięć

16
main.py
Wyświetl plik

@ -18,17 +18,17 @@ def do_connect(ntwrk_ssid, netwrk_pass):
print('.', end='')
if sta_if.isconnected():
print('\nConnected. Network config: ', sta_if.ifconfig())
return (True)
return True
else:
print('\nFailed. Not Connected to: ' + ntwrk_ssid)
return (False)
return False
def check_connection():
global wlan_sta
# First check if there already is any connection:
if wlan_sta.isconnected():
return (True)
return True
try:
# ESP connecting to WiFi takes time, wait a bit and try again:
time.sleep(3)
@ -48,20 +48,20 @@ def check_connection():
if ssid_list[0] in i[0]:
print("OK. WiFi found.")
if do_connect(ssid_list[0], ssid_list[1]):
return (True)
return True
if not wlan_sta.isconnected():
if networkconfig.start():
return (True)
return True
else:
return (True)
return True
except OSError:
# start web server for connection manager:
if networkconfig.start():
return (True)
return True
return (False)
return False
if check_connection():

Wyświetl plik

@ -27,10 +27,10 @@ def do_connect(ntwrk_ssid, netwrk_pass):
print('.', end='')
if sta_if.isconnected():
print('\nConnected. Network config: ', sta_if.ifconfig())
return (True)
return True
else:
print('\nFailed. Not Connected to: ' + ntwrk_ssid)
return (False)
return False
def send_response(client, payload, status_code=200):
@ -85,7 +85,7 @@ def handle_configure(client, request):
if match is None:
send_response(client, "Parameters not found", status_code=400)
return (False)
return False
# version 1.9 compatibility
try:
ssid = match.group(1).decode("utf-8").replace("%3F", "?").replace("%21", "!")
@ -96,7 +96,7 @@ def handle_configure(client, request):
if len(ssid) == 0:
send_response(client, "SSID must be provided", status_code=400)
return (False)
return False
if do_connect(ssid, password):
response_footer = """
@ -117,7 +117,7 @@ def handle_configure(client, request):
fo = open("passwd.dat", "w")
fo.write(ssid + ";" + password + "\n")
fo.close()
return (True)
return True
else:
response_footer = """
<html>
@ -129,7 +129,7 @@ def handle_configure(client, request):
</form></center></html>
"""
send_response(client, response_footer)
return (False)
return False
def handle_not_found(client, url):
@ -170,7 +170,7 @@ def start(port=80):
if wlan_sta.isconnected():
client.close
return (True)
return True
client, addr = server_socket.accept()
client.settimeout(5.0)
@ -179,7 +179,7 @@ def start(port=80):
request = b""
try:
while not "\r\n\r\n" in request:
while "\r\n\r\n" not in request:
request += client.recv(512)
except OSError:
pass