diff --git a/README.md b/README.md index 289e1a2..cabca5c 100644 --- a/README.md +++ b/README.md @@ -1,7 +1,7 @@ # WiFi Manager Lang : Micropython -Tested : 1.8 and 1.9.3 +Tested : 1.15 Description : WiFi manager for ESP8266 - ESP12 - ESP32 for micropython @@ -11,11 +11,19 @@ Tested : 1.8 and 1.9.3 - Save wifi password in "wifi.dat" (csv format) - Easy to apply +Added Features: + - Add Json response feature instead of html + - Can Integrate to any native app with json response + Usage: -Upload main.py and wifimgr.py to ESP. +Upload main.py and wifimanager-html.py to ESP.(for configure with browser) +Use wifimanager-json.py to ESP.(for configure with Native App) Write your code into main.py or import it from main.py. + - 192.168.1.4 will return available network ssid in json response. + - 192.168.1.4/configure send ssid and password in json data and it will return success/failed message in json response. + Logic: 1. step: Check "wifi.dat" file and try saved networks/passwords. 2. step: Publish web page to configure new wifi. diff --git a/wifimgr.py b/wifimanager-html.py similarity index 87% rename from wifimgr.py rename to wifimanager-html.py index a697655..03d3c01 100644 --- a/wifimgr.py +++ b/wifimanager-html.py @@ -36,11 +36,13 @@ def get_connection(): wlan_sta.active(True) networks = wlan_sta.scan() - AUTHMODE = {0: "open", 1: "WEP", 2: "WPA-PSK", 3: "WPA2-PSK", 4: "WPA/WPA2-PSK"} + AUTHMODE = {0: "open", 1: "WEP", 2: "WPA-PSK", + 3: "WPA2-PSK", 4: "WPA/WPA2-PSK"} for ssid, bssid, channel, rssi, authmode, hidden in sorted(networks, key=lambda x: x[3], reverse=True): ssid = ssid.decode('utf-8') encrypted = authmode > 0 - print("ssid: %s chan: %d rssi: %d authmode: %s" % (ssid, channel, rssi, AUTHMODE.get(authmode, '?'))) + print("ssid: %s chan: %d rssi: %d authmode: %s" % + (ssid, channel, rssi, AUTHMODE.get(authmode, '?'))) if encrypted: if ssid in profiles: password = profiles[ssid] @@ -93,13 +95,14 @@ def do_connect(ssid, password): time.sleep(0.1) print('.', end='') if connected: - print('\nConnected. Network config: ', wlan_sta.ifconfig()) + print('\nConnected. Network config: ', wlan_sta.ifconfig()[0]) else: + wlan_sta.disconnect() print('\nFailed. Not Connected to: ' + ssid) return connected -def send_header(client, status_code=200, content_length=None ): +def send_header(client, status_code=200, content_length=None): client.sendall("HTTP/1.0 {} OK\r\n".format(status_code)) client.sendall("Content-Type: text/html\r\n") if content_length is not None: @@ -135,7 +138,7 @@ def handle_root(client): client.sendall("""\