adafruit / Adafruit_CircuitPython_Requests

Requests-like interface for web interfacing
MIT License
51 stars 36 forks source link

Update Open-Sky Network Private Area API Example #168

Closed DJDevon3 closed 2 months ago

DJDevon3 commented 3 months ago

Private API, website credentials required. Instructions in code comments. More daily calls than Public API. Pulls flight data from a geographic area. Example is around Orlando airport.

Added

Changed from circuitpython_base64 community library to adafruit_binascii. It encodes to base64 much faster and has Adafruit library support. It's a better way to go for examples needing base64 encoding.

Serial output example:

Connecting to WiFi...
✅ Wifi!
 | Attempting to GET OpenSky-Network Area Flights JSON!
 | ✅ OpenSky-Network JSON!
 |  | Timestamp: 03/18/2024 07:00:20
 |  | Trans:ad4804 Sign:JBU2523 Origin:United States Time:1710744961 Last:1710744961 Lon:-81.327 Lat:28.4545 BaroAlt:83.82 Ground:False Vel:69.97 Head:179.16 VertRate:-3.58 Sens:None GeoAlt:68.58 Squawk:0501 Task:False PosSys:0 Cat:0 
 |  | Trans:a05087 Sign:GTX508  Origin:United States Time:1710745220 Last:1710745220 Lon:-81.4167 Lat:28.7626 BaroAlt:914.4 Ground:False Vel:80.53 Head:154.25 VertRate:0 Sens:None GeoAlt:906.78 Squawk:None Task:False PosSys:0 Cat:0 
✂️ Disconnected from OpenSky-Network API

Finished!
Board Uptime: 1 hours
Next Update: 30 minutes
===============================
DJDevon3 commented 3 months ago

This example also has the base64 encoded string appending with \n which likely will fail for you if the other private example does. I find it really odd and a bit concerning that this works for me but not for you. I'll take another look into this one today too and ensure the \n append is sliced off.

DJDevon3 commented 3 months ago

Also added .strip to the end of binascii.b2a_base64(b"" + str(OSN_CREDENTIALS)).strip() which will strip off the \n. still have to use slice but it's 2 less characters to slice off. as far as i know this should be the final version for review.

DJDevon3 commented 3 months ago

Double checked the other PR's. This one is ready for review.