Skip to content

Commit

Permalink
continue if no WIFI
Browse files Browse the repository at this point in the history
  • Loading branch information
FoamyGuy committed May 10, 2024
1 parent bf5559c commit 1e219f2
Showing 1 changed file with 26 additions and 16 deletions.
42 changes: 26 additions & 16 deletions examples/camera/code.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,25 +27,35 @@
TZ = os.getenv("TZ")

print(f"Connecting to {os.getenv('CIRCUITPY_WIFI_SSID')}")
wifi.radio.connect(
os.getenv("CIRCUITPY_WIFI_SSID"), os.getenv("CIRCUITPY_WIFI_PASSWORD")
)
if wifi.radio.connected:
print(f"Connected to {os.getenv('CIRCUITPY_WIFI_SSID')}!")
print("My IP address is", wifi.radio.ipv4_address)
pool = socketpool.SocketPool(wifi.radio)
SSID = os.getenv("CIRCUITPY_WIFI_SSID")
PASSWORD = os.getenv("CIRCUITPY_WIFI_PASSWORD")

if SSID and PASSWORD:
wifi.radio.connect(
os.getenv("CIRCUITPY_WIFI_SSID"), os.getenv("CIRCUITPY_WIFI_PASSWORD")
)
if wifi.radio.connected:
print(f"Connected to {os.getenv('CIRCUITPY_WIFI_SSID')}!")
print("My IP address is", wifi.radio.ipv4_address)
pool = socketpool.SocketPool(wifi.radio)

if UTC_OFFSET is None:
requests = adafruit_requests.Session(pool, ssl.create_default_context())
response = requests.get("http://worldtimeapi.org/api/timezone/" + TZ)
response_as_json = response.json()
UTC_OFFSET = response_as_json["raw_offset"] + response_as_json["dst_offset"]
if UTC_OFFSET is None:
requests = adafruit_requests.Session(pool, ssl.create_default_context())
response = requests.get("http://worldtimeapi.org/api/timezone/" + TZ)
response_as_json = response.json()
UTC_OFFSET = response_as_json["raw_offset"] + response_as_json["dst_offset"]
print(f"UTC_OFFSET: {UTC_OFFSET}")

ntp = adafruit_ntp.NTP(pool, server="pool.ntp.org", tz_offset=UTC_OFFSET // 3600)
ntp = adafruit_ntp.NTP(
pool, server="pool.ntp.org", tz_offset=UTC_OFFSET // 3600
)

rtc.RTC().datetime = ntp.datetime
print(f"ntp time: {ntp.datetime}")
rtc.RTC().datetime = ntp.datetime
else:
print("Wifi failed to connect. Time not set.")
else:
print("Wifi failed to connect. Time not set.")
print("Wifi config not found in settintgs.toml. Time not set.")

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

0 comments on commit 1e219f2

Please sign in to comment.