|
5 | 5 | adafruit_requests using BytesIO
|
6 | 6 | """
|
7 | 7 |
|
8 |
| -import ssl |
9 | 8 | from io import BytesIO
|
| 9 | +from os import getenv |
10 | 10 |
|
| 11 | +import adafruit_connection_manager |
11 | 12 | import adafruit_requests as requests
|
12 | 13 | import board
|
13 | 14 | import displayio
|
14 |
| -import socketpool |
15 | 15 | import wifi
|
16 | 16 |
|
17 | 17 | import adafruit_imageload
|
18 | 18 |
|
19 |
| -# Get wifi details and more from a secrets.py file |
20 |
| -try: |
21 |
| - from secrets import secrets |
22 |
| -except ImportError: |
23 |
| - print("WiFi secrets are kept in secrets.py, please add them there!") |
24 |
| - raise |
| 19 | +# Get WiFi details, ensure these are setup in settings.toml |
| 20 | +ssid = getenv("CIRCUITPY_WIFI_SSID") |
| 21 | +password = getenv("CIRCUITPY_WIFI_PASSWORD") |
25 | 22 |
|
26 |
| -wifi.radio.connect(secrets["ssid"], secrets["password"]) |
| 23 | +wifi.radio.connect(ssid, password) |
27 | 24 |
|
28 | 25 | print("My IP address is", wifi.radio.ipv4_address)
|
29 | 26 |
|
30 |
| -socket = socketpool.SocketPool(wifi.radio) |
31 |
| -https = requests.Session(socket, ssl.create_default_context()) |
| 27 | +pool = adafruit_connection_manager.get_radio_socketpool(wifi.radio) |
| 28 | +ssl_context = adafruit_connection_manager.get_radio_ssl_context(wifi.radio) |
| 29 | +https = requests.Session(pool, ssl_context) |
32 | 30 |
|
33 | 31 | url = "https://raw.githubusercontent.com/adafruit/Adafruit_CircuitPython_ImageLoad/main/examples/images/4bit.bmp"
|
34 | 32 |
|
35 |
| -print("Fetching text from %s" % url) |
| 33 | +print(f"Fetching text from {url}") |
36 | 34 | response = https.get(url)
|
37 | 35 | print("GET complete")
|
38 | 36 |
|
|
0 commit comments