22
33import gc
44import math
5+ import os
56
67from adafruit_datetime import datetime , timedelta
78from adafruit_pyportal import PyPortal
@@ -35,26 +36,37 @@ def _utc_to_local(utc_timestamp: float, utc_offset: str = "-0000") -> datetime:
3536 return utc_time + delta
3637
3738
39+ # Starting with CircuitPython v9.0 an "sd" folder has to be created to be used as a mount point
40+ # For newer installs this should already be present but may not if migrating from v8.x
41+ # See: https://github.com/adafruit/circuitpython/issues/8872
42+ # See: https://github.com/adafruit/circuitpython/pull/8860
43+ if "sd" not in os .listdir ("/" ):
44+ # Our boot.py already makes the filesystem writeable so we shouldn't need to guard
45+ os .mkdir ("/sd" )
46+
3847# Device Initialization
3948PYPORTAL = PyPortal () # This also takes care of mounting the SD to /sd
4049skyportal_ui = SkyPortalUI ()
4150
4251PYPORTAL .network .connect ()
4352print ("Wifi connected" )
4453
54+ SESSION = PYPORTAL .network ._wifi .requests
55+
4556# The internal PyPortal query to AIO returns as "%Y-%m-%d %H:%M:%S.%L %j %u %z %Z"
4657# This method sets the internal clock, but we also retain it to transform the API time to local
4758init_timestamp = PYPORTAL .get_local_time (location = secrets ["timezone" ])
4859utc_offset = init_timestamp .split ()[4 ]
4960
5061grid_bounds = build_bounding_box ()
51- skyportal_ui .post_connect_init (grid_bounds )
62+ skyportal_ui .post_connect_init (grid_bounds , SESSION )
5263
5364api_handler : APIHandlerBase
5465if skyportal_config .AIRCRAFT_DATA_SOURCE == "adsblol" :
5566 from skyportal .networklib import ADSBLol
5667
5768 api_handler = ADSBLol (
69+ request_session = SESSION ,
5870 lat = skyportal_config .MAP_CENTER_LAT ,
5971 lon = skyportal_config .MAP_CENTER_LON ,
6072 radius = skyportal_config .GRID_WIDTH_MI * 2 ,
@@ -63,12 +75,13 @@ def _utc_to_local(utc_timestamp: float, utc_offset: str = "-0000") -> datetime:
6375elif skyportal_config .AIRCRAFT_DATA_SOURCE == "opensky" :
6476 from skyportal .networklib import OpenSky
6577
66- api_handler = OpenSky (grid_bounds = grid_bounds )
78+ api_handler = OpenSky (request_session = SESSION , grid_bounds = grid_bounds )
6779 print ("Using OpenSky as aircraft data source" )
6880elif skyportal_config .AIRCRAFT_DATA_SOURCE == "proxy" :
6981 from skyportal .networklib import ProxyAPI
7082
7183 api_handler = ProxyAPI (
84+ request_session = SESSION ,
7285 lat = skyportal_config .MAP_CENTER_LAT ,
7386 lon = skyportal_config .MAP_CENTER_LON ,
7487 radius = skyportal_config .GRID_WIDTH_MI * 2 ,
0 commit comments