Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix for #5 out of memory on esp8266 #7

Merged
merged 1 commit into from
May 25, 2018
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 21 additions & 9 deletions wifimgr.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import ure
import time


ap_ssid = "WifiManager"
ap_password = "tayfunulu"
ap_authmode = 3 # WPA2
Expand Down Expand Up @@ -99,22 +100,31 @@ def do_connect(ssid, password):
return connected


def send_response(client, payload, status_code=200):
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")
client.sendall("Content-Length: {}\r\n".format(len(payload)))
if content_length is not None:
client.sendall("Content-Length: {}\r\n".format(content_length))

client.sendall("\r\n")

if len(payload) > 0:
def send_response(client, payload, status_code=200):
content_length = len(payload)

send_header(client, status_code, content_length)

if content_length > 0:
client.sendall(payload)

client.close()

def handle_root(client):
wlan_sta.active(True)
ssids = sorted(ssid.decode('utf-8') for ssid, *_ in wlan_sta.scan())

response = []
response.append("""\
send_header(client)

client.sendall("""\
<html>
<h1 style="color: #5e9ca0; text-align: center;">
<span style="color: #ff0000;">
Expand All @@ -126,16 +136,18 @@ def handle_root(client):
<tbody>
""")

for ssid in ssids:
response.append("""\
while len(ssids):
ssid = ssids.pop(0)

client.sendall("""\
<tr>
<td colspan="2">
<input type="radio" name="ssid" value="{0}" />{0}
</td>
</tr>
""".format(ssid))

response.append("""\
client.sendall("""\
<tr>
<td>Password:</td>
<td><input name="password" type="password" /></td>
Expand Down Expand Up @@ -171,8 +183,8 @@ def handle_root(client):
</ul>
</html>
""" % dict(filename=NETWORK_PROFILES))
send_response(client, "\n".join(response))

client.close()

def handle_configure(client, request):
match = ure.search("ssid=([^&]*)&password=(.*)", request)
Expand Down