kopia lustrzana https://github.com/tayfunulu/WiFiManager
html source: formatted, fixed some issues
rodzic
491ad25172
commit
a1b6ae5855
|
@ -45,12 +45,22 @@ def send_response(client, payload, status_code=200):
|
||||||
|
|
||||||
def handle_root(client):
|
def handle_root(client):
|
||||||
global wlan_sta
|
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">
|
||||||
<table style="margin-left: auto; margin-right: auto;">
|
<table style="margin-left: auto; margin-right: auto;">
|
||||||
<tbody><tr><td>Wifi Name</td>
|
<tbody>
|
||||||
<td style="text-align: center;"><select id="ssid" name="ssid">
|
<tr>
|
||||||
|
<td>
|
||||||
|
WiFi Name
|
||||||
|
</td>
|
||||||
|
<td style="text-align: center;">
|
||||||
|
<select id="ssid" name="ssid">
|
||||||
"""
|
"""
|
||||||
wlan_sta.active(True)
|
wlan_sta.active(True)
|
||||||
|
|
||||||
|
@ -58,22 +68,42 @@ def handle_root(client):
|
||||||
for ssid, *_ in wlan_sta.scan():
|
for ssid, *_ in wlan_sta.scan():
|
||||||
response_variable += '<option value="{0}">{0}</option>'.format(ssid.decode("utf-8"))
|
response_variable += '<option value="{0}">{0}</option>'.format(ssid.decode("utf-8"))
|
||||||
|
|
||||||
response_footer = """
|
response_footer = """\
|
||||||
</select></td></tr>
|
</select>
|
||||||
<tr><td>Password</td>
|
</td>
|
||||||
|
</tr>
|
||||||
|
<tr>
|
||||||
|
<td>Password</td>
|
||||||
<td><input name="password" type="password" /></td>
|
<td><input name="password" type="password" /></td>
|
||||||
</tr></tbody>
|
</tr>
|
||||||
|
</tbody>
|
||||||
</table>
|
</table>
|
||||||
<p style="text-align: center;"><input type="submit" value="Submit" /></p>
|
<p style="text-align: center;">
|
||||||
|
<input type="submit" value="Submit" />
|
||||||
|
</p>
|
||||||
</form>
|
</form>
|
||||||
<p> </p>
|
<p> </p>
|
||||||
<hr />
|
<hr />
|
||||||
<h5><span style="color: #ff0000;">Your ssid and password information will be saved into the "passwd.dat" file in your ESP module for future usage. Be careful about security!</span></h5>
|
<h5>
|
||||||
|
<span style="color: #ff0000;">
|
||||||
|
Your ssid and password information will be saved into the
|
||||||
|
"passwd.dat" file in your ESP module for future usage.
|
||||||
|
Be careful about security!
|
||||||
|
</span>
|
||||||
|
</h5>
|
||||||
<hr />
|
<hr />
|
||||||
<h2 style="color: #2e6c80;">Some useful infos:</h2>
|
<h2 style="color: #2e6c80;">
|
||||||
|
Some useful infos:
|
||||||
|
</h2>
|
||||||
<ul>
|
<ul>
|
||||||
<li>Wi-Fi Client for MicroPython GitHub from <a href="https://github.com/cpopp/MicroPythonSamples" target="_blank" rel="noopener">cpopp</a></li>
|
<li>
|
||||||
<li>My github address <a href="https://github.com/tayfunulu" target="_blank" rel="noopener">tayfunulu</a></li>
|
Original code from <a href="https://github.com/cpopp/MicroPythonSamples"
|
||||||
|
target="_blank" rel="noopener">cpopp/MicroPythonSamples</a>.
|
||||||
|
</li>
|
||||||
|
<li>
|
||||||
|
This code available at <a href="https://github.com/tayfunulu/WiFiManager"
|
||||||
|
target="_blank" rel="noopener">tayfunulu/WiFiManager</a>.
|
||||||
|
</li>
|
||||||
</ul>
|
</ul>
|
||||||
</html>
|
</html>
|
||||||
"""
|
"""
|
||||||
|
@ -99,11 +129,19 @@ def handle_configure(client, request):
|
||||||
return False
|
return False
|
||||||
|
|
||||||
if do_connect(ssid, password):
|
if do_connect(ssid, password):
|
||||||
response_footer = """
|
response_footer = """\
|
||||||
<html>
|
<html>
|
||||||
<center><br><br>
|
<center>
|
||||||
<h1 style="color: #5e9ca0; text-align: center;"><span style="color: #ff0000;">ESP successfully connected to Wi-Fi network """ + ssid + """.</span></h1>
|
<br><br>
|
||||||
<br><br>"""
|
<h1 style="color: #5e9ca0; text-align: center;">
|
||||||
|
<span style="color: #ff0000;">
|
||||||
|
ESP successfully connected to WiFi network %(ssid)s.
|
||||||
|
</span>
|
||||||
|
</h1>
|
||||||
|
<br><br>
|
||||||
|
</center>
|
||||||
|
</html>
|
||||||
|
""" % dict(ssid=ssid)
|
||||||
send_response(client, response_footer)
|
send_response(client, response_footer)
|
||||||
try:
|
try:
|
||||||
with open("passwd.dat", "r") as f:
|
with open("passwd.dat", "r") as f:
|
||||||
|
@ -115,15 +153,21 @@ def handle_configure(client, request):
|
||||||
f.write(ex_data)
|
f.write(ex_data)
|
||||||
return True
|
return True
|
||||||
else:
|
else:
|
||||||
response_footer = """
|
response_footer = """\
|
||||||
<html>
|
<html>
|
||||||
<center>
|
<center>
|
||||||
<h1 style="color: #5e9ca0; text-align: center;"><span style="color: #ff0000;">Wi-Fi Not Configured to """ + ssid + """</span></h1>
|
<h1 style="color: #5e9ca0; text-align: center;">
|
||||||
|
<span style="color: #ff0000;">
|
||||||
|
ESP could not connect to WiFi network %(ssid)s.
|
||||||
|
</span>
|
||||||
|
</h1>
|
||||||
<br><br>
|
<br><br>
|
||||||
<form>
|
<form>
|
||||||
<input type="button" value="Go back!" onclick="history.back()"></input>
|
<input type="button" value="Go back!" onclick="history.back()"></input>
|
||||||
</form></center></html>
|
</form>
|
||||||
"""
|
</center>
|
||||||
|
</html>
|
||||||
|
""" % dict(ssid=ssid)
|
||||||
send_response(client, response_footer)
|
send_response(client, response_footer)
|
||||||
return False
|
return False
|
||||||
|
|
||||||
|
|
Ładowanie…
Reference in New Issue