kopia lustrzana https://github.com/tayfunulu/WiFiManager
version 1.9.2 compatibility
it's not the optimum solution for compatibility problem between 1.8 and 1.9. But it's working :)pull/7/head
rodzic
05212924ec
commit
cf5faf4862
|
@ -37,6 +37,7 @@ def send_response(client, payload, status_code=200):
|
||||||
client.sendall(payload)
|
client.sendall(payload)
|
||||||
|
|
||||||
def handle_root(client):
|
def handle_root(client):
|
||||||
|
global wlan_sta
|
||||||
response_header = """
|
response_header = """
|
||||||
<html><h1 style="color: #5e9ca0; text-align: center;"><span style="color: #ff0000;">Wi-Fi Client Setup</span></h1>
|
<html><h1 style="color: #5e9ca0; text-align: center;"><span style="color: #ff0000;">Wi-Fi Client Setup</span></h1>
|
||||||
<form action="configure" method="post">
|
<form action="configure" method="post">
|
||||||
|
@ -44,6 +45,7 @@ def handle_root(client):
|
||||||
<tbody><tr><td>Wifi Name</td>
|
<tbody><tr><td>Wifi Name</td>
|
||||||
<td style="text-align: center;"><select id="ssid" name="ssid">
|
<td style="text-align: center;"><select id="ssid" name="ssid">
|
||||||
"""
|
"""
|
||||||
|
wlan_sta.active(True)
|
||||||
|
|
||||||
response_variable = ""
|
response_variable = ""
|
||||||
for ssid, *_ in wlan_sta.scan():
|
for ssid, *_ in wlan_sta.scan():
|
||||||
|
@ -76,9 +78,15 @@ def handle_configure(client, request):
|
||||||
if match is None:
|
if match is None:
|
||||||
send_response(client, "Parameters not found", status_code=400)
|
send_response(client, "Parameters not found", status_code=400)
|
||||||
return (False)
|
return (False)
|
||||||
|
# version 1.9 compatibility
|
||||||
ssid = match.group(1).replace("%3F","?").replace("%21","!")
|
try:
|
||||||
password = match.group(2).replace("%3F","?").replace("%21","!")
|
ssid = match.group(1).decode("utf-8").replace("%3F","?").replace("%21","!")
|
||||||
|
password = match.group(2).decode("utf-8").replace("%3F","?").replace("%21","!")
|
||||||
|
except:
|
||||||
|
ssid = match.group(1).replace("%3F","?").replace("%21","!")
|
||||||
|
password = match.group(2).replace("%3F","?").replace("%21","!")
|
||||||
|
|
||||||
|
|
||||||
if len(ssid) == 0:
|
if len(ssid) == 0:
|
||||||
send_response(client, "SSID must be provided", status_code=400)
|
send_response(client, "SSID must be provided", status_code=400)
|
||||||
return (False)
|
return (False)
|
||||||
|
@ -136,7 +144,9 @@ def start(port=80):
|
||||||
server_socket = socket.socket()
|
server_socket = socket.socket()
|
||||||
server_socket.bind(addr)
|
server_socket.bind(addr)
|
||||||
server_socket.listen(1)
|
server_socket.listen(1)
|
||||||
|
|
||||||
|
print('Connect to Wifi ssid like Micropython-XXXX , Default pass: micropythoN ')
|
||||||
|
print('And connect to esp via your favorite web browser (like 192.168.4.1)')
|
||||||
print('listening on', addr)
|
print('listening on', addr)
|
||||||
|
|
||||||
while True:
|
while True:
|
||||||
|
@ -162,8 +172,12 @@ def start(port=80):
|
||||||
# skip invalid requests
|
# skip invalid requests
|
||||||
client.close()
|
client.close()
|
||||||
continue
|
continue
|
||||||
|
|
||||||
url = ure.search("(?:GET|POST) /(.*?)(?:\\?.*?)? HTTP", request).group(1).rstrip("/")
|
# version 1.9 compatibility
|
||||||
|
try:
|
||||||
|
url = ure.search("(?:GET|POST) /(.*?)(?:\\?.*?)? HTTP", request).group(1).decode("utf-8").rstrip("/")
|
||||||
|
except:
|
||||||
|
url = ure.search("(?:GET|POST) /(.*?)(?:\\?.*?)? HTTP", request).group(1).rstrip("/")
|
||||||
print("URL is {}".format(url))
|
print("URL is {}".format(url))
|
||||||
|
|
||||||
if url == "":
|
if url == "":
|
||||||
|
@ -173,4 +187,4 @@ def start(port=80):
|
||||||
else:
|
else:
|
||||||
handle_not_found(client, url)
|
handle_not_found(client, url)
|
||||||
|
|
||||||
client.close()
|
client.close()
|
||||||
|
|
Ładowanie…
Reference in New Issue