Skip to content

Commit 1e219f2

Browse files
committed
continue if no WIFI
1 parent bf5559c commit 1e219f2

File tree

1 file changed

+26
-16
lines changed

1 file changed

+26
-16
lines changed

examples/camera/code.py

Lines changed: 26 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -27,25 +27,35 @@
2727
TZ = os.getenv("TZ")
2828

2929
print(f"Connecting to {os.getenv('CIRCUITPY_WIFI_SSID')}")
30-
wifi.radio.connect(
31-
os.getenv("CIRCUITPY_WIFI_SSID"), os.getenv("CIRCUITPY_WIFI_PASSWORD")
32-
)
33-
if wifi.radio.connected:
34-
print(f"Connected to {os.getenv('CIRCUITPY_WIFI_SSID')}!")
35-
print("My IP address is", wifi.radio.ipv4_address)
36-
pool = socketpool.SocketPool(wifi.radio)
30+
SSID = os.getenv("CIRCUITPY_WIFI_SSID")
31+
PASSWORD = os.getenv("CIRCUITPY_WIFI_PASSWORD")
32+
33+
if SSID and PASSWORD:
34+
wifi.radio.connect(
35+
os.getenv("CIRCUITPY_WIFI_SSID"), os.getenv("CIRCUITPY_WIFI_PASSWORD")
36+
)
37+
if wifi.radio.connected:
38+
print(f"Connected to {os.getenv('CIRCUITPY_WIFI_SSID')}!")
39+
print("My IP address is", wifi.radio.ipv4_address)
40+
pool = socketpool.SocketPool(wifi.radio)
3741

38-
if UTC_OFFSET is None:
39-
requests = adafruit_requests.Session(pool, ssl.create_default_context())
40-
response = requests.get("http://worldtimeapi.org/api/timezone/" + TZ)
41-
response_as_json = response.json()
42-
UTC_OFFSET = response_as_json["raw_offset"] + response_as_json["dst_offset"]
42+
if UTC_OFFSET is None:
43+
requests = adafruit_requests.Session(pool, ssl.create_default_context())
44+
response = requests.get("http://worldtimeapi.org/api/timezone/" + TZ)
45+
response_as_json = response.json()
46+
UTC_OFFSET = response_as_json["raw_offset"] + response_as_json["dst_offset"]
47+
print(f"UTC_OFFSET: {UTC_OFFSET}")
4348

44-
ntp = adafruit_ntp.NTP(pool, server="pool.ntp.org", tz_offset=UTC_OFFSET // 3600)
49+
ntp = adafruit_ntp.NTP(
50+
pool, server="pool.ntp.org", tz_offset=UTC_OFFSET // 3600
51+
)
4552

46-
rtc.RTC().datetime = ntp.datetime
53+
print(f"ntp time: {ntp.datetime}")
54+
rtc.RTC().datetime = ntp.datetime
55+
else:
56+
print("Wifi failed to connect. Time not set.")
4757
else:
48-
print("Wifi failed to connect. Time not set.")
58+
print("Wifi config not found in settintgs.toml. Time not set.")
4959

5060
pycam = adafruit_pycamera.PyCamera()
5161
# pycam.live_preview_mode()
@@ -199,7 +209,7 @@
199209
t0 = t1
200210
pycam._mode_label.text = "GIF" # pylint: disable=protected-access
201211
print(f"\nfinal size {f.tell()} for {i} frames")
202-
print(f"average framerate {i/(t1-t00)}fps")
212+
print(f"average framerate {i / (t1 - t00)}fps")
203213
print(f"best {max(ft)} worst {min(ft)} std. deviation {np.std(ft)}")
204214
f.close()
205215
pycam.display.refresh()

0 commit comments

Comments
 (0)