From 2dd55a7b239097ce6fb60fc32cc2e31baad21217 Mon Sep 17 00:00:00 2001 From: Justin Myers Date: Sat, 22 Feb 2025 10:39:00 -0800 Subject: [PATCH 1/3] Remove secrets and more --- adafruit_pyportal/__init__.py | 2 -- adafruit_pyportal/network.py | 12 +++++------- docs/conf.py | 1 - examples/pyportal_internet_json_fetching.py | 21 +++++++++++---------- examples/pyportal_simpletest.py | 4 ++-- 5 files changed, 18 insertions(+), 22 deletions(-) diff --git a/adafruit_pyportal/__init__.py b/adafruit_pyportal/__init__.py index 456a719..1f25c53 100755 --- a/adafruit_pyportal/__init__.py +++ b/adafruit_pyportal/__init__.py @@ -124,7 +124,6 @@ def __init__( # noqa: PLR0912,PLR0913,PLR0915 Too many branches,Too many argume esp=None, external_spi=None, debug=False, - secrets_data=None, ): graphics = Graphics( default_bg=default_bg, @@ -161,7 +160,6 @@ def __init__( # noqa: PLR0912,PLR0913,PLR0915 Too many branches,Too many argume image_position=image_position, image_dim_json_path=image_dim_json_path, debug=debug, - secrets_data=secrets_data, ) self.url = url diff --git a/adafruit_pyportal/network.py b/adafruit_pyportal/network.py index 5fddddf..22f2fb6 100755 --- a/adafruit_pyportal/network.py +++ b/adafruit_pyportal/network.py @@ -83,7 +83,6 @@ def __init__( # noqa: PLR0913 Too many arguments in function definition image_resize=None, image_position=None, image_dim_json_path=None, - secrets_data=None, ): if status_neopixel: status_led = neopixel.NeoPixel(status_neopixel, 1, brightness=0.2) @@ -95,7 +94,6 @@ def __init__( # noqa: PLR0913 Too many arguments in function definition wifi, extract_values=extract_values, debug=debug, - secrets_data=secrets_data, ) self._convert_image = convert_image @@ -113,16 +111,16 @@ def ip_address(self): def image_converter_url(self, image_url, width, height, color_depth=16): """Generate a converted image url from the url passed in, - with the given width and height. aio_username and aio_key must be - set in secrets.""" + with the given width and height. ADAFRUIT_AIO_USERNAME and + ADAFRUIT_AIO_KEY must be set in settings.toml.""" try: - aio_username = self._get_setting("AIO_USERNAME") - aio_key = self._get_setting("AIO_KEY") + aio_username = self._get_setting("ADAFRUIT_AIO_USERNAME") + aio_key = self._get_setting("ADAFRUIT_AIO_KEY") except KeyError as error: raise KeyError( "\n\nOur image converter service require a login/password to rate-limit. " "Please register for a free adafruit.io account and place the user/key in " - "your secrets file under 'aio_username' and 'aio_key'" + "your settings.toml file under 'ADAFRUIT_AIO_USERNAME' and 'ADAFRUIT_AIO_KEY'" ) from error return IMAGE_CONVERTER_SERVICE % ( diff --git a/docs/conf.py b/docs/conf.py index 1f9f713..807c67c 100644 --- a/docs/conf.py +++ b/docs/conf.py @@ -37,7 +37,6 @@ "audiocore", "microcontroller", "neopixel", - "secrets", "adafruit_sdcard", "storage", "sdcardio", diff --git a/examples/pyportal_internet_json_fetching.py b/examples/pyportal_internet_json_fetching.py index 9cadbbb..eed7183 100644 --- a/examples/pyportal_internet_json_fetching.py +++ b/examples/pyportal_internet_json_fetching.py @@ -5,25 +5,26 @@ Example to illustrate the device capability to get json data """ -# NOTE: Make sure you've created your secrets.py file before running this example -# https://learn.adafruit.com/adafruit-pyportal/internet-connect#whats-a-secrets-file-17-2 +# NOTE: Make sure you've created your settings.toml file before running this example +# https://learn.adafruit.com/adafruit-pyportal/create-your-settings-toml-file import adafruit_connection_manager import adafruit_requests import board from adafruit_esp32spi import adafruit_esp32spi from digitalio import DigitalInOut -# Get wifi details and more from a secrets.py file -try: - from secrets import secrets -except ImportError: - print("WiFi secrets are kept in secrets.py, please add them there!") - raise +# Get wifi details and more from a settings.toml file +# tokens used by this Demo: CIRCUITPY_WIFI_SSID, CIRCUITPY_WIFI_PASSWORD, +# ADAFRUIT_AIO_USERNAME, ADAFRUIT_AIO_KEY +ssid = getenv("CIRCUITPY_WIFI_SSID") +password = getenv("CIRCUITPY_WIFI_PASSWORD") +aio_username = getenv("ADAFRUIT_AIO_USERNAME") +aio_key = getenv("ADAFRUIT_AIO_KEY") print("ESP32 SPI webclient test") TEXT_URL = "http://wifitest.adafruit.com/testwifi/index.html" -JSON_URL = "http://api.coindesk.com/v1/bpi/currentprice/USD.json" +JSON_URL = "http://wifitest.adafruit.com/testwifi/sample.json" # ESP32 Pins: @@ -49,7 +50,7 @@ print("Connecting to AP...") while not esp.is_connected: try: - esp.connect_AP(secrets["ssid"], secrets["password"]) + esp.connect_AP(ssid, password) except RuntimeError as e: print("could not connect to AP, retrying: ", e) continue diff --git a/examples/pyportal_simpletest.py b/examples/pyportal_simpletest.py index 94b150a..5eeabc7 100644 --- a/examples/pyportal_simpletest.py +++ b/examples/pyportal_simpletest.py @@ -2,8 +2,8 @@ # # SPDX-License-Identifier: MIT -# NOTE: Make sure you've created your secrets.py file before running this example -# https://learn.adafruit.com/adafruit-pyportal/internet-connect#whats-a-secrets-file-17-2 +# NOTE: Make sure you've created your settings.toml file before running this example +# https://learn.adafruit.com/adafruit-pyportal/create-your-settings-toml-file import board from displayio import CIRCUITPYTHON_TERMINAL From 0274f09ad4e611c10248124a5094579f73ce8703 Mon Sep 17 00:00:00 2001 From: Justin Myers Date: Sat, 22 Feb 2025 11:21:06 -0800 Subject: [PATCH 2/3] Fix example --- examples/pyportal_internet_json_fetching.py | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/examples/pyportal_internet_json_fetching.py b/examples/pyportal_internet_json_fetching.py index eed7183..eec6a94 100644 --- a/examples/pyportal_internet_json_fetching.py +++ b/examples/pyportal_internet_json_fetching.py @@ -7,6 +7,8 @@ # NOTE: Make sure you've created your settings.toml file before running this example # https://learn.adafruit.com/adafruit-pyportal/create-your-settings-toml-file +from os import getenv + import adafruit_connection_manager import adafruit_requests import board @@ -42,10 +44,10 @@ if esp.status == adafruit_esp32spi.WL_IDLE_STATUS: print("ESP32 found and in idle mode") print("Firmware vers.", esp.firmware_version) -print("MAC addr:", [hex(i) for i in esp.MAC_address]) +print("MAC addr:", ":".join("%02X" % byte for byte in esp.MAC_address)) for ap in esp.scan_networks(): - print("\t%s\t\tRSSI: %d" % (str(ap["ssid"], "utf-8"), ap["rssi"])) + print("\t%-23s RSSI: %d" % (ap.ssid, ap.rssi)) print("Connecting to AP...") while not esp.is_connected: @@ -54,8 +56,8 @@ except RuntimeError as e: print("could not connect to AP, retrying: ", e) continue -print("Connected to", str(esp.ssid, "utf-8"), "\tRSSI:", esp.rssi) -print("My IP address is", esp.pretty_ip(esp.ip_address)) +print("Connected to", esp.ap_info.ssid, "\tRSSI:", esp.ap_info.rssi) +print("My IP address is", esp.ipv4_address) print("IP lookup adafruit.com: %s" % esp.pretty_ip(esp.get_host_by_name("adafruit.com"))) print("Ping google.com: %d ms" % esp.ping("google.com")) From 402f808190f38e14c6eec5bab00fe4d098d3cc72 Mon Sep 17 00:00:00 2001 From: Justin Myers Date: Sat, 22 Feb 2025 14:55:54 -0800 Subject: [PATCH 3/3] Removing unneeded AIO keys from example --- examples/pyportal_internet_json_fetching.py | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/examples/pyportal_internet_json_fetching.py b/examples/pyportal_internet_json_fetching.py index eec6a94..dfc125a 100644 --- a/examples/pyportal_internet_json_fetching.py +++ b/examples/pyportal_internet_json_fetching.py @@ -16,12 +16,9 @@ from digitalio import DigitalInOut # Get wifi details and more from a settings.toml file -# tokens used by this Demo: CIRCUITPY_WIFI_SSID, CIRCUITPY_WIFI_PASSWORD, -# ADAFRUIT_AIO_USERNAME, ADAFRUIT_AIO_KEY +# tokens used by this Demo: CIRCUITPY_WIFI_SSID, CIRCUITPY_WIFI_PASSWORD ssid = getenv("CIRCUITPY_WIFI_SSID") password = getenv("CIRCUITPY_WIFI_PASSWORD") -aio_username = getenv("ADAFRUIT_AIO_USERNAME") -aio_key = getenv("ADAFRUIT_AIO_KEY") print("ESP32 SPI webclient test")