From 0370235697f95a8e1a361e012a884b9e0b966dbf Mon Sep 17 00:00:00 2001 From: TilCreator Date: Tue, 29 May 2018 22:19:01 +0200 Subject: [PATCH 1/3] Improve webinterface --- wifimgr.py | 230 +++++++++++++++++++++++++++++++++++++---------------- 1 file changed, 161 insertions(+), 69 deletions(-) diff --git a/wifimgr.py b/wifimgr.py index 387866c..0700f78 100644 --- a/wifimgr.py +++ b/wifimgr.py @@ -9,6 +9,109 @@ NETWORK_PROFILES = 'wifi.dat' +html_head = """ + + WiFi Manager + + +""" + wlan_ap = network.WLAN(network.AP_IF) wlan_sta = network.WLAN(network.STA_IF) @@ -119,62 +222,58 @@ def handle_root(client): wlan_sta.active(True) ssids = sorted(ssid.decode('utf-8') for ssid, *_ in wlan_sta.scan()) send_header(client) + client.sendall("") + client.sendall(html_head) client.sendall("""\ - -

- - Wi-Fi Client Setup - -

-
- - + + +

+ Wi-Fi Client Setup +

+

+ SSIDs (click to select) +

+ - - + +
  • + {0} +
  • +
    """.format(ssid)) client.sendall("""\ - - - - - -
    - {0} -
    Password:
    -

    - -

    -
    -

     

    -
    -
    - - Your ssid and password information will be saved into the - "%(filename)s" file in your ESP module for future usage. - Be careful about security! - -
    -
    -

    - Some useful infos: -

    - +
  • + SSID + +
  • +
  • + Password + +
  • +
  • + +
  • + +
    +

    + Infos: +

    +

    + Your ssid and password information will be saved into the "{}" file in your ESP module for future usage. Be careful about security! +

    +

    + Original code from cpopp/MicroPythonSamples. +

    +

    + This code available at tayfunulu/WiFiManager. +

    + + - """ % dict(filename=NETWORK_PROFILES)) + """.format(NETWORK_PROFILES)) client.close() @@ -196,17 +295,14 @@ def handle_configure(client, request): if do_connect(ssid, password): response = """\ -
    -

    -

    - - ESP successfully connected to WiFi network %(ssid)s. - + {} + +

    + ESP successfully connected to WiFi network "{}"

    -

    -
    + - """ % dict(ssid=ssid) + """.format(html_head, ssid) send_response(client, response) try: profiles = read_profiles() @@ -218,19 +314,15 @@ def handle_configure(client, request): else: response = """\ -
    -

    - - ESP could not connect to WiFi network %(ssid)s. - + {} + +

    + ESP could not connect to WiFi network "{}"

    -

    -
    - -
    -
    + + - """ % dict(ssid=ssid) + """.format(html_head, ssid) send_response(client, response) return False @@ -265,7 +357,7 @@ def start(port=80): client, addr = server_socket.accept() print('client connected from', addr) try: - client.settimeout(5.0) + client.settimeout(15.0) request = b"" try: while "\r\n\r\n" not in request: From b4ab02d419d9c3b0dbfefe79131c0544514ea474 Mon Sep 17 00:00:00 2001 From: TilCreator Date: Wed, 30 May 2018 12:56:29 +0200 Subject: [PATCH 2/3] Change positional placeholders back to named placeholders --- wifimgr.py | 22 +++++++++++----------- 1 file changed, 11 insertions(+), 11 deletions(-) diff --git a/wifimgr.py b/wifimgr.py index f84869d..55a59b2 100644 --- a/wifimgr.py +++ b/wifimgr.py @@ -238,12 +238,12 @@ def handle_root(client): while len(ssids): ssid = ssids.pop(0) client.sendall("""\ - +
  • - {0} + {ssid}
  • - """.format(ssid)) + """.format(ssid=ssid)) client.sendall("""\
  • SSID @@ -262,7 +262,7 @@ def handle_root(client): Infos:

    - Your ssid and password information will be saved into the "{}" file in your ESP module for future usage. Be careful about security! + Your ssid and password information will be saved into the "{filename}" file in your ESP module for future usage. Be careful about security!

    Original code from cpopp/MicroPythonSamples. @@ -273,7 +273,7 @@ def handle_root(client): - """.format(NETWORK_PROFILES)) + """.format(filename=NETWORK_PROFILES)) client.close() @@ -298,14 +298,14 @@ def handle_configure(client, request): if do_connect(ssid, password): response = """\ - {} + {html_head}

    - ESP successfully connected to WiFi network "{}" + ESP successfully connected to WiFi network "{ssid}"

    - """.format(html_head, ssid) + """.format(html_head=html_head, ssid=ssid) send_response(client, response) try: profiles = read_profiles() @@ -320,15 +320,15 @@ def handle_configure(client, request): else: response = """\ - {} + {html_head}

    - ESP could not connect to WiFi network "{}" + ESP could not connect to WiFi network "{ssid}"

    - """.format(html_head, ssid) + """.format(html_head=html_head, ssid=ssid) send_response(client, response) return False From cdfb0e815c3a29d27ec6d4d666987c8e72a96d99 Mon Sep 17 00:00:00 2001 From: TilCreator Date: Thu, 31 May 2018 15:46:38 +0200 Subject: [PATCH 3/3] Improve headline `h[1-6]` usage --- wifimgr.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/wifimgr.py b/wifimgr.py index 55a59b2..1c1b96a 100644 --- a/wifimgr.py +++ b/wifimgr.py @@ -60,7 +60,7 @@ margin: 10px auto; } - h3 { + h2 { margin: 10px 0px -10px 0px; } @@ -230,9 +230,9 @@ def handle_root(client):

    Wi-Fi Client Setup

    -

    +

    SSIDs (click to select) -

    +
      """) while len(ssids):