2222from adafruit_matrixportal .matrixportal import MatrixPortal
2323import microcontroller
2424
25-
2625# Release any existing displays
2726displayio .release_displays ()
2827
29-
30-
31- # --- API Configuration ---
32- API_URL = "http://airlabs.co/api/v9/flights?api_key="
33- API_KEY = ""
34- TEST_API = "http://opensky-network.org/api/states/all?"
35-
3628quotes_url = "https://www.adafruit.com/api/quotes.php"
3729
38-
3930THRESHOLD_DISTANCE = 150 # 5 miles
4031
4132# font = bitmap_font.load_font("/tom-thumb.pcf")
4233font = terminalio .FONT
4334text_color = 0xFC6900 # e.g., Retro Orange
4435colors = [0xFC6900 , 0xDD8000 ]
4536
46-
4737# --- Wi-Fi setup ---
4838wifi .radio .connect (
4939 os .getenv ("CIRCUITPY_WIFI_SSID" ), os .getenv ("CIRCUITPY_WIFI_PASSWORD" )
5343# --- Networking setup ---
5444context = ssl .create_default_context ()
5545
56-
57- with open ("/www.flightaware.com.cer" , "rb" ) as certfile :
46+ with open ("/ssl.com-root.pem" , "rb" ) as certfile :
5847 context .load_verify_locations (cadata = certfile .read ())
5948
6049pool = socketpool .SocketPool (wifi .radio )
9079 doublebuffer = False ,
9180)
9281
93-
9482# --- Drawing setup ---
9583group = Group ()
96- # Create icon group
97-
98-
9984# Associate the RGB matrix with a Display
10085display = framebufferio .FramebufferDisplay (matrix , auto_refresh = False )
101-
102-
10386# display.show(icon_group)
10487
10588
@@ -111,22 +94,26 @@ def degrees_to_cardinal(d):
11194
11295seen_flight_numbers = set () # To keep track of processed flight numbers
11396
97+ bounding_box = {
98+ "min_latitude" : 44.953469 ,
99+ "max_latitude" : 40.962321 ,
100+ "min_longitude" : - 111.045360 ,
101+ "max_longitude" : - 104.046577 ,
102+ }
114103
115-
116-
104+ # curl -X GET "https://aeroapi.flightaware.com/aeroapi/flights/search?query=-latlong+%2244.953469+-111.045360+40.962321+-104.046577%22&max_pages=1" \
105+ # -H "Accept: application/json; charset=UTF-8" \
106+ # -H "x-apikey: -AN API KEY-"
117107
118108api_url = "https://aeroapi.flightaware.com/aeroapi/flights/search"
119- username = "UserName "
120- api_key = "API_KEY "
109+ username = "A-Name "
110+ api_key = "API-KEY "
121111
122- # Use CircuitPython base64 library for encoding
123- headers = {"x-apikey" : api_key }
124112
125113def construct_query_string (params ):
126114 return "&" .join (f"{ key } ={ value } " for key , value in params .items ())
127115
128116
129-
130117def fetch_flight_data ():
131118 base_url = "https://aeroapi.flightaware.com/aeroapi/flights/search"
132119 params = {
@@ -135,7 +122,7 @@ def fetch_flight_data():
135122 }
136123 headers = {
137124 "Accept" : "application/json; charset=UTF-8" ,
138- "x-apikey" : "API_KEY"
125+ "x-apikey" : "anA5AXJkYlfC2SNgWghB27mkNO9RRaTI" # Make sure to replace API_KEY with your actual API key
139126 }
140127
141128 # Construct the full URL with the query string
@@ -144,25 +131,28 @@ def fetch_flight_data():
144131 # Use the requests object that was initialized with a session
145132 response = requests .get (full_url , headers = headers )
146133
147- if response .status_code == 200 :
134+
135+ if response .status_code == 200 :
136+ print ("in da loop" )
148137 flights = response .json ()['flights' ]
149138 for flight in flights :
150- print ("Flight Properties:" )
151- print (f"Ident: { flight .get ('ident' , 'N/A' )} " )
152- print (f"FA Flight ID: { flight .get ('fa_flight_id' , 'N/A' )} " )
153- print (f"Origin: { flight .get ('origin' , {}).get ('code' , 'N/A' )} " )
154- print (f"Destination: { flight .get ('destination' , {}).get ('code' , 'N/A' )} " )
155- print (f"Altitude: { flight .get ('last_position' , {}).get ('altitude' , 'N/A' )} 00 ft" )
156- print (f"Groundspeed: { flight .get ('last_position' , {}).get ('groundspeed' , 'N/A' )} knots" )
157- print (f"Heading: { flight .get ('last_position' , {}).get ('heading' , 'N/A' )} " )
158- print (f"Latitude: { flight .get ('last_position' , {}).get ('latitude' , 'N/A' )} " )
159- print (f"Longitude: { flight .get ('last_position' , {}).get ('longitude' , 'N/A' )} " )
160- print (f"Timestamp: { flight .get ('last_position' , {}).get ('timestamp' , 'N/A' )} " )
161- print ("------" )
162- # Print only one flight's properties for brevity; remove the break to print all
163- break
164- else :
165- print (f"Request failed with status code { response .status_code } " )
139+ print ("Flight Properties:" )
140+ print (f"Ident: { flight .get ('ident' , 'N/A' )} " )
141+ print (f"FA Flight ID: { flight .get ('fa_flight_id' , 'N/A' )} " )
142+ print (f"Origin: { flight .get ('origin' , {}).get ('code' , 'N/A' )} " )
143+ print (f"Destination: { flight .get ('destination' , {}).get ('code' , 'N/A' )} " )
144+ print (f"Altitude: { flight .get ('last_position' , {}).get ('altitude' , 'N/A' )} 00 ft" )
145+ print (f"Groundspeed: { flight .get ('last_position' , {}).get ('groundspeed' , 'N/A' )} knots" )
146+ print (f"Heading: { flight .get ('last_position' , {}).get ('heading' , 'N/A' )} " )
147+ print (f"Latitude: { flight .get ('last_position' , {}).get ('latitude' , 'N/A' )} " )
148+ print (f"Longitude: { flight .get ('last_position' , {}).get ('longitude' , 'N/A' )} " )
149+ print (f"Timestamp: { flight .get ('last_position' , {}).get ('timestamp' , 'N/A' )} " )
150+ print ("------" )
151+ # Print only one flight's properties for brevity; remove the break to print all
152+ break
153+ else :
154+ print (f"Request failed with status code { response .status_code } " )
155+
166156
167157def requestTest ():
168158 try :
@@ -181,8 +171,10 @@ def requestTest():
181171 except Exception as e :
182172 print ("Error:\n " , str (e ))
183173 print ("Resetting microcontroller in 10 seconds" )
184- time .sleep (10 )
174+ time .sleep (1200 )
185175 microcontroller .reset ()
186176
177+
187178while True :
188179 fetch_flight_data ()
180+ time .sleep (1200 )
0 commit comments