|
27 | 27 | TZ = os.getenv("TZ") |
28 | 28 |
|
29 | 29 | 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) |
37 | 41 |
|
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}") |
43 | 48 |
|
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 | + ) |
45 | 52 |
|
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.") |
47 | 57 | else: |
48 | | - print("Wifi failed to connect. Time not set.") |
| 58 | + print("Wifi config not found in settintgs.toml. Time not set.") |
49 | 59 |
|
50 | 60 | pycam = adafruit_pycamera.PyCamera() |
51 | 61 | # pycam.live_preview_mode() |
|
199 | 209 | t0 = t1 |
200 | 210 | pycam._mode_label.text = "GIF" # pylint: disable=protected-access |
201 | 211 | 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") |
203 | 213 | print(f"best {max(ft)} worst {min(ft)} std. deviation {np.std(ft)}") |
204 | 214 | f.close() |
205 | 215 | pycam.display.refresh() |
|
0 commit comments