|
1 | 1 | # SPDX-FileCopyrightText: 2024 DJDevon3 |
2 | 2 | # SPDX-License-Identifier: MIT |
3 | 3 | # Coded for Circuit Python 8.2.x |
4 | | -"""OpenSky-Network.org Private API Example""" |
| 4 | +"""OpenSky-Network.org Private Area API Example""" |
5 | 5 | # pylint: disable=import-error |
6 | 6 |
|
| 7 | +import binascii |
7 | 8 | import os |
8 | 9 | import time |
9 | 10 |
|
10 | 11 | import adafruit_connection_manager |
11 | 12 | import wifi |
12 | | -from adafruit_binascii import b2a_base64 |
13 | 13 |
|
14 | 14 | import adafruit_requests |
15 | 15 |
|
|
35 | 35 | SLEEP_TIME = 1800 |
36 | 36 |
|
37 | 37 | # Set debug to True for full JSON response. |
38 | | -# WARNING: makes credentials visible |
| 38 | +# WARNING: makes credentials visible. based on how many flights |
| 39 | +# in your area, full response could crash microcontroller |
39 | 40 | DEBUG = False |
40 | 41 |
|
41 | 42 | # Initalize Wifi, Socket Pool, Request Session |
|
45 | 46 |
|
46 | 47 | # -- Base64 Conversion -- |
47 | 48 | OSN_CREDENTIALS = str(osnusername) + ":" + str(osnpassword) |
48 | | -OSN_CREDENTIALS_B = b"" + str(OSN_CREDENTIALS) + "" |
49 | | -BASE64_ASCII = b2a_base64(OSN_CREDENTIALS_B) |
50 | | -BASE64_STRING = str(BASE64_ASCII) # bytearray |
51 | | -TRUNCATED_BASE64_STRING = BASE64_STRING[2:-1] # truncate bytearray head/tail |
| 49 | +# base64 encode and strip appended \n from bytearray |
| 50 | +OSN_CREDENTIALS_B = binascii.b2a_base64(b"" + str(OSN_CREDENTIALS)).strip() |
| 51 | +BASE64_STRING = str(OSN_CREDENTIALS_B) # bytearray |
| 52 | +SLICED_BASE64_STRING = BASE64_STRING[2:-1] # slice bytearray head/tail |
52 | 53 |
|
53 | 54 | if DEBUG: |
54 | | - print("Original Binary Data: ", OSN_CREDENTIALS_B) |
55 | | - print("Base64 ByteArray: ", BASE64_ASCII) |
56 | | - print(f"Base64 String: {TRUNCATED_BASE64_STRING}") |
| 55 | + print("Base64 ByteArray: ", BASE64_STRING) |
| 56 | + print(f"Base64 Sliced String: {SLICED_BASE64_STRING}") |
57 | 57 |
|
58 | 58 | # Area requires OpenSky-Network.org username:password to be base64 encoded |
59 | | -OSN_HEADER = {"Authorization": "Basic " + str(TRUNCATED_BASE64_STRING)} |
| 59 | +OSN_HEADER = {"Authorization": "Basic " + str(SLICED_BASE64_STRING)} |
60 | 60 |
|
61 | 61 | # Example request of all traffic over Florida. |
62 | 62 | # Geographic areas calls cost less against the limit. |
|
0 commit comments