Skip to content

Commit

Permalink
feat(add wifi dropdown): make it easier to find nearby access points
Browse files Browse the repository at this point in the history
Add: Drop Down to allow easier identification of nearby compatible ac…
  • Loading branch information
MikeSchapp committed Nov 13, 2022
2 parents 48dd1c4 + 6786e0c commit 4bbf281
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 6 deletions.
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -11,4 +11,4 @@ run_tests:
dist:
mkdir -p dist
cp -r firmware/* dist
python -m upip install -r requirements.txt -p 'dist/'
python -m upip install -r requirements.txt -p 'dist/'
16 changes: 13 additions & 3 deletions firmware/lib/webpage.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,22 +21,32 @@ def default_route(*args, **kwargs):

"""Default page for new users of BabyScout to land on"""
options = [
{"ssid": "SSID:"},
{"password": "Password:"},
{"babybuddy": "BabyBuddy URL:"},
{"babyauth": "BabyBuddy API Key"},
]
render = ""
access_point_options = """
<select id="ssid" name="ssid">
"""
for ap in args[0]:
access_point_options += f'''
<option value="{ap}">{ap}</option>
'''
access_point_options += "</select><br><br>"
render += access_point_options
for option in options:
for key, value in option.items():
render += f""" <input type="text" id="{key}" name="{key}" placeholder="{value}"><br><br>"""
render += f"""
<input type="text" id="{key}" name="{key}" placeholder="{value}"><br><br>
"""
return template.render_template(
load_webpage("webpages/default.html"), {"render": render}
)


def config_route(*args, **kwargs):
"""Page used to recive and process new secrets into a secrets.json file"""
"""Page used to recieve and process new secrets into a secrets.json file"""
request = kwargs.get("request")
secret_json = {}
if request.query_strings:
Expand Down
6 changes: 4 additions & 2 deletions firmware/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -83,11 +83,13 @@ def button_pressed():
else:
ap_mode = True
if ap_mode:
# Grab nearby access points for later configuration
nearby_access_points = pico_connection.nearby_access_points
# Start ap mode to allow for conffiguration of BabyScout via wifi access point.
print("No matching wifi, falling back to webpage based setup.")
print("No matching wifi or babybuddy configuration, falling back to webpage based setup.")
ap = pico_connection.access_point_wifi_setup("BabyScout", "BabyBuddy")
ip = ap.ifconfig()[0]
app = WebRouter(ip, 80, default_route, "webpages/static")
app = WebRouter(ip, 80, partial(default_route, nearby_access_points), "webpages/static")
app.route("/config")(config_route)()
app.serve()

Expand Down
7 changes: 7 additions & 0 deletions firmware/webpages/static/babyscout.css
Original file line number Diff line number Diff line change
Expand Up @@ -19,4 +19,11 @@ body {
border:0;
box-shadow:0 0 15px 4px rgba(0,0,0,0.06);
border-radius: 8px;
}

select {
padding:10px;
border:0;
box-shadow:0 0 15px 4px rgba(0,0,0,0.06);
border-radius: 8px;
}

0 comments on commit 4bbf281

Please sign in to comment.