|
2 | 2 | # SPDX-FileCopyrightText: 2023 Limor Fried for Adafruit Industries
|
3 | 3 | #
|
4 | 4 | # SPDX-License-Identifier: Unlicense
|
5 |
| - |
| 5 | +import ssl |
| 6 | +import os |
6 | 7 | import time
|
| 8 | +import socketpool |
| 9 | +import adafruit_requests |
| 10 | +import rtc |
| 11 | +import adafruit_ntp |
| 12 | +import wifi |
7 | 13 | import bitmaptools
|
8 | 14 | import displayio
|
9 | 15 | import gifio
|
10 | 16 | import ulab.numpy as np
|
11 | 17 |
|
12 | 18 | import adafruit_pycamera
|
13 | 19 |
|
| 20 | +# Wifi details are in settings.toml file, also, |
| 21 | +# timezone info should be included to allow local time and DST adjustments |
| 22 | +# # UTC_OFFSET, if present, will override TZ and DST and no API query will be done |
| 23 | +# UTC_OFFSET=-25200 |
| 24 | +# # TZ="America/Phoenix" |
| 25 | + |
| 26 | +UTC_OFFSET = os.getenv("UTC_OFFSET") |
| 27 | +TZ = os.getenv("TZ") |
| 28 | + |
| 29 | +print(f"Connecting to {os.getenv('CIRCUITPY_WIFI_SSID')}") |
| 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) |
| 41 | + |
| 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}") |
| 48 | + |
| 49 | + ntp = adafruit_ntp.NTP( |
| 50 | + pool, server="pool.ntp.org", tz_offset=UTC_OFFSET // 3600 |
| 51 | + ) |
| 52 | + |
| 53 | + print(f"ntp time: {ntp.datetime}") |
| 54 | + rtc.RTC().datetime = ntp.datetime |
| 55 | + else: |
| 56 | + print("Wifi failed to connect. Time not set.") |
| 57 | +else: |
| 58 | + print("Wifi config not found in settintgs.toml. Time not set.") |
| 59 | + |
14 | 60 | pycam = adafruit_pycamera.PyCamera()
|
15 | 61 | # pycam.live_preview_mode()
|
16 | 62 |
|
|
163 | 209 | t0 = t1
|
164 | 210 | pycam._mode_label.text = "GIF" # pylint: disable=protected-access
|
165 | 211 | print(f"\nfinal size {f.tell()} for {i} frames")
|
166 |
| - print(f"average framerate {i/(t1-t00)}fps") |
| 212 | + print(f"average framerate {i / (t1 - t00)}fps") |
167 | 213 | print(f"best {max(ft)} worst {min(ft)} std. deviation {np.std(ft)}")
|
168 | 214 | f.close()
|
169 | 215 | pycam.display.refresh()
|
|
0 commit comments