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

amended wifi connection for compatibility with list format wifi.json #64

Open
wants to merge 3 commits into
base: tilda-master
Choose a base branch
from
Open
Show file tree
Hide file tree
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
26 changes: 20 additions & 6 deletions stmhal/init-files/bootstrap.py
Original file line number Diff line number Diff line change
Expand Up @@ -233,17 +233,31 @@ def download(url, target, expected_hash):
except ValueError as e:
print(e)

if type(w) is dict:
# convert original format json (dict, one network) to new (list, many networks)
w = [w]

wifi_info = "\nMore information:\nbadge.emfcamp.org/TiLDA_MK3/wifi"
if "ssid" not in w:
if not all( [ ("ssid" in config) for config in w ] ):
label.text("Couldn't find a valid wifi.json :(" + wifi_info)
while True: pyb.wfi()

label.text("Connecting to '%s'.\nIf this is incorrect, please check your wifi.json%s" % (w["ssid"], wifi_info))
n = network.CC3100()
if ("pw" in w) and w["pw"]:
n.connect(w["ssid"], w["pw"], timeout=10)
else:
n.connect(w["ssid"], timeout=10)
visible_ssids = [ ap['ssid'] for ap in n.list_aps() ]
known_ssids = [ ap['ssid'] for ap in w ]

if len(set(known_ssids).intersection(visible_ssids)) < 1:
label.text("Couldn't find any networks listed in wifi.json :(" + wifi_info)

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nitpick: could you add a \n before the wifi_info?

while True: pyb.wfi()

for ap in w:
if ap["ssid"] in visible_ssids:
label.text("Connecting to '%s'.\nIf this is incorrect, please check your wifi.json%s" % (ap["ssid"], wifi_info))
if ("pw" in ap) and ap["pw"]:
n.connect(ap["ssid"], ap["pw"], timeout=10)
else:
n.connect(ap["ssid"], timeout=10)
break # found a visible AP, don't bother with any more

success = False
failure_counter = 0
Expand Down
2 changes: 1 addition & 1 deletion stmhal/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,7 @@ static const char fresh_bootstrap_py[] =
#include "genhdr/bootstrap.py.h"
;

static const char fresh_wifi_json[] = "{\"ssid\":\"emfcamp-insecure\"}\r\n";
static const char fresh_wifi_json[] = "[{\"ssid\":\"emfcamp-insecure\"}]\r\n";

static const char fresh_pybcdc_inf[] =
#include "genhdr/pybcdc_inf.h"
Expand Down