html source: formatted, fixed some issues

pull/3/head
Thomas Waldmann 2017-12-11 20:28:21 +01:00
rodzic 491ad25172
commit a1b6ae5855
1 zmienionych plików z 84 dodań i 40 usunięć

Wyświetl plik

@ -45,38 +45,68 @@ 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>
<form action="configure" method="post"> <h1 style="color: #5e9ca0; text-align: center;">
<table style="margin-left: auto; margin-right: auto;"> <span style="color: #ff0000;">
<tbody><tr><td>Wifi Name</td> Wi-Fi Client Setup
<td style="text-align: center;"><select id="ssid" name="ssid"> </span>
""" </h1>
<form action="configure" method="post">
<table style="margin-left: auto; margin-right: auto;">
<tbody>
<tr>
<td>
WiFi Name
</td>
<td style="text-align: center;">
<select id="ssid" name="ssid">
"""
wlan_sta.active(True) wlan_sta.active(True)
response_variable = "" response_variable = ""
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>
<td><input name="password" type="password" /></td> </tr>
</tr></tbody> <tr>
</table> <td>Password</td>
<p style="text-align: center;"><input type="submit" value="Submit" /></p> <td><input name="password" type="password" /></td>
</form> </tr>
<p>&nbsp;</p> </tbody>
<hr /> </table>
<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> <p style="text-align: center;">
<hr /> <input type="submit" value="Submit" />
<h2 style="color: #2e6c80;">Some useful infos:</h2> </p>
<ul> </form>
<li>Wi-Fi Client for MicroPython GitHub from&nbsp;<a href="https://github.com/cpopp/MicroPythonSamples" target="_blank" rel="noopener">cpopp</a></li> <p>&nbsp;</p>
<li>My github address <a href="https://github.com/tayfunulu" target="_blank" rel="noopener">tayfunulu</a></li> <hr />
</ul> <h5>
</html> <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 />
<h2 style="color: #2e6c80;">
Some useful infos:
</h2>
<ul>
<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>
</html>
"""
send_response(client, response_header + response_variable + response_footer) send_response(client, response_header + response_variable + response_footer)
@ -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;">
<br><br> <span style="color: #ff0000;">
<form> ESP could not connect to WiFi network %(ssid)s.
<input type="button" value="Go back!" onclick="history.back()"></input> </span>
</form></center></html> </h1>
""" <br><br>
<form>
<input type="button" value="Go back!" onclick="history.back()"></input>
</form>
</center>
</html>
""" % dict(ssid=ssid)
send_response(client, response_footer) send_response(client, response_footer)
return False return False