From f23741077ef4b8aa9e2bf5e18e32936446cd0e9f Mon Sep 17 00:00:00 2001 From: Justin Myers Date: Tue, 1 Apr 2025 06:58:09 -0700 Subject: [PATCH 1/3] Secrets Cleanup: P Part 1 --- Pi_In_Stock_Notifier/code.py | 43 +++++++++++-------- .../Pico_W_Basic_WiFi_Test/code.py | 18 ++++++-- Purple_Air_Display/code.py | 20 ++++++--- PyPortal/PyPortal_AWS_IOT_Planter/code.py | 29 ++++++++----- PyPortal/PyPortal_AdafruitIO/code.py | 24 ++++++++--- PyPortal/PyPortal_AdafruitIO_Logger/code.py | 34 ++++++++------- PyPortal/PyPortal_Alarm_Clock/code.py | 22 +++++++--- PyPortal/PyPortal_Azure_Plant_Monitor/code.py | 25 +++++++---- PyPortal/PyPortal_CMA_Art_Frame/code.py | 13 ++++++ PyPortal/PyPortal_CMA_Art_Frame/secrets.py | 13 ------ PyPortal/PyPortal_CMA_Art_Frame/settings.toml | 9 ++++ .../.circuitpython.skip | 7 --- PyPortal/PyPortal_Electioncal_US/code.py | 18 +++++--- .../electioncal_graphics.py | 3 +- PyPortal/PyPortal_Email_Display/code.py | 29 +++++++------ PyPortal/PyPortal_GCP_IOT_Planter/code.py | 37 +++++++++++----- .../gcp_gfx_helper.py | 4 +- PyPortal/PyPortal_GithubStars/code.py | 24 +++++++---- PyPortal/PyPortal_Guitar_Tuner/secrets.py | 12 ------ PyPortal/PyPortal_HaDSkulls/code.py | 21 ++++++--- PyPortal/PyPortal_Hackster/code.py | 22 ++++++---- PyPortal/PyPortal_HacksterStream/code.py | 22 ++++++---- PyPortal/PyPortal_Halloween_Countdown/code.py | 18 ++++++-- .../PyPortal_Halloween_Countdown/secrets.py | 14 ------ .../settings.toml | 10 +++++ PyPortal/PyPortal_IOT_Scale/code.py | 32 ++++++++------ 26 files changed, 323 insertions(+), 200 deletions(-) delete mode 100644 PyPortal/PyPortal_CMA_Art_Frame/secrets.py create mode 100644 PyPortal/PyPortal_CMA_Art_Frame/settings.toml delete mode 100644 PyPortal/PyPortal_Electioncal_US/.circuitpython.skip delete mode 100644 PyPortal/PyPortal_Guitar_Tuner/secrets.py delete mode 100644 PyPortal/PyPortal_Halloween_Countdown/secrets.py create mode 100644 PyPortal/PyPortal_Halloween_Countdown/settings.toml diff --git a/Pi_In_Stock_Notifier/code.py b/Pi_In_Stock_Notifier/code.py index 8d8f13f26..15006136b 100644 --- a/Pi_In_Stock_Notifier/code.py +++ b/Pi_In_Stock_Notifier/code.py @@ -2,6 +2,7 @@ # # SPDX-License-Identifier: MIT +from os import getenv import time import ssl import wifi @@ -14,6 +15,21 @@ from digitalio import DigitalInOut, Direction, Pull from adafruit_debouncer import Debouncer +# Get WiFi details and Adafruit IO keys, ensure these are setup in settings.toml +# (visit io.adafruit.com if you need to create an account, or if you need your Adafruit IO key.) +ssid = getenv("CIRCUITPY_WIFI_SSID") +password = getenv("CIRCUITPY_WIFI_PASSWORD") +aio_username = getenv("ADAFRUIT_AIO_USERNAME") +aio_key = getenv("ADAFRUIT_AIO_KEY") + +if None in [ssid, password, aio_username, aio_key]: + raise RuntimeError( + "WiFi and Adafruit IO settings are kept in settings.toml, " + "please add them there. The settings file must contain " + "'CIRCUITPY_WIFI_SSID', 'CIRCUITPY_WIFI_PASSWORD', " + "'ADAFRUIT_AIO_USERNAME' and 'ADAFRUIT_AIO_KEY' at a minimum." + ) + alarm_out = DigitalInOut(board.A1) alarm_out.direction = Direction.OUTPUT alarm_out.value = False @@ -23,37 +39,28 @@ button = Debouncer(button_in) -# 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 - print("Adafruit Raspberry Pi In Stock Tweet Listener") # import your bearer token -bear = secrets['bearer_token'] +bearer_token = getenv('bearer_token') # query URL for tweets. looking for hashtag partyparrot sent to a specific username # disabling line-too-long because queries for tweet_query & TIME_URL cannot have line breaks # pylint: disable=line-too-long tweet_query = 'https://api.twitter.com/2/tweets/search/recent?query=In Stock at Adafruit from:rpilocator&tweet.fields=created_at' -headers = {'Authorization': 'Bearer ' + bear} +headers = {'Authorization': 'Bearer ' + bearer_token} -print("Connecting to %s"%secrets["ssid"]) -wifi.radio.connect(secrets["ssid"], secrets["password"]) -print("Connected to %s!"%secrets["ssid"]) -print("My IP address is", wifi.radio.ipv4_address) +print(f"Connecting to {ssid}") +wifi.radio.connect(ssid, password) +print(f"Connected to {ssid}!") +print(f"My IP address is {wifi.radio.ipv4_address}") pool = socketpool.SocketPool(wifi.radio) requests = adafruit_requests.Session(pool, ssl.create_default_context()) # gets and formats time from adafruit.io -aio_username = secrets["aio_username"] -aio_key = secrets["aio_key"] -location = secrets.get("timezone", None) +location = getenv("timezone", None) TIME_URL = "https://io.adafruit.com/api/v2/%s/integrations/time/strftime?x-aio-key=%s" % (aio_username, aio_key) TIME_URL += "&fmt=%25Y-%25m-%25dT%25H%3A%25M%3A%25S.%25L%25j%25u%25z%25Z" @@ -132,7 +139,7 @@ else: # if it's not new, then the wait continues - no_tweet_text = ("No stock in last hour :( Last stock: %s" % (timestamp)) + no_tweet_text = "No stock in last hour :( Last stock: %s" % (timestamp) text_area.text = "\n".join(wrap_text_to_lines(no_tweet_text, 21)) print("no new in stock notifications :(") # updates tweet ID @@ -140,6 +147,6 @@ # if the tweet wasn't today else: # if it's not new, then the wait continues - no_tweet_text = ("No stock in last hour :( Last stock: %s" % (timestamp)) + no_tweet_text = "No stock in last hour :( Last stock: %s" % (timestamp) text_area.text = "\n".join(wrap_text_to_lines(no_tweet_text, 21)) print("no new in stock notifications :(") diff --git a/Pico_W_CircuitPython_WiFi_Examples/Pico_W_Basic_WiFi_Test/code.py b/Pico_W_CircuitPython_WiFi_Examples/Pico_W_Basic_WiFi_Test/code.py index cea1e537d..f62b2a6df 100644 --- a/Pico_W_CircuitPython_WiFi_Examples/Pico_W_Basic_WiFi_Test/code.py +++ b/Pico_W_CircuitPython_WiFi_Examples/Pico_W_Basic_WiFi_Test/code.py @@ -2,17 +2,29 @@ # # SPDX-License-Identifier: MIT -import os +from os import getenv import ipaddress import wifi import socketpool +# Get WiFi details, ensure these are setup in settings.toml +ssid = getenv("CIRCUITPY_WIFI_SSID") +password = getenv("CIRCUITPY_WIFI_PASSWORD") + +if None in [ssid, password]: + raise RuntimeError( + "WiFi settings are kept in settings.toml, " + "please add them there. The settings file must contain " + "'CIRCUITPY_WIFI_SSID', 'CIRCUITPY_WIFI_PASSWORD', " + "at a minimum." + ) + print() print("Connecting to WiFi") # connect to your SSID try: - wifi.radio.connect(os.getenv('CIRCUITPY_WIFI_SSID'), os.getenv('CIRCUITPY_WIFI_PASSWORD')) + wifi.radio.connect(ssid, password) except TypeError: print("Could not find WiFi info. Check your settings.toml file!") raise @@ -25,7 +37,7 @@ print("My MAC addr:", [hex(i) for i in wifi.radio.mac_address]) # prints IP address to REPL -print("My IP address is", wifi.radio.ipv4_address) +print(f"My IP address is {wifi.radio.ipv4_address}") # pings Google ipv4 = ipaddress.ip_address("8.8.4.4") diff --git a/Purple_Air_Display/code.py b/Purple_Air_Display/code.py index ef68d009a..be1584ee6 100644 --- a/Purple_Air_Display/code.py +++ b/Purple_Air_Display/code.py @@ -7,17 +7,23 @@ # or Matrix Portal # and 64 x 32 RGB LED Matrix +from os import getenv import time import board import terminalio from adafruit_matrixportal.matrixportal import MatrixPortal -# 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, ensure these are setup in settings.toml +ssid = getenv("CIRCUITPY_WIFI_SSID") +password = getenv("CIRCUITPY_WIFI_PASSWORD") + +if None in [ssid, password]: + raise RuntimeError( + "WiFi settings are kept in settings.toml, " + "please add them there. The settings file must contain " + "'CIRCUITPY_WIFI_SSID', 'CIRCUITPY_WIFI_PASSWORD', " + "at a minimum." + ) def aqi_transform(val): aqi = pm_to_aqi(val) # derive Air Quality Index from Particulate Matter 2.5 value @@ -49,7 +55,7 @@ def message_transform(val): # picks message based on thresholds status_neopixel=board.NEOPIXEL, debug=True, url=DATA_SOURCE, - headers={"X-API-Key": secrets["purple_air_api_key"], # purpleair.com + headers={"X-API-Key": getenv("purple_air_api_key"), # purpleair.com "Accept": "application/json" }, json_path=(DATA_LOCATION, DATA_LOCATION), diff --git a/PyPortal/PyPortal_AWS_IOT_Planter/code.py b/PyPortal/PyPortal_AWS_IOT_Planter/code.py index ee44b40fd..b9583b9e5 100755 --- a/PyPortal/PyPortal_AWS_IOT_Planter/code.py +++ b/PyPortal/PyPortal_AWS_IOT_Planter/code.py @@ -10,7 +10,8 @@ Author: Brent Rubell for Adafruit Industries, 2019 """ -import os + +from os import getenv import time import json import board @@ -28,10 +29,17 @@ # Time between polling the STEMMA, in minutes SENSOR_DELAY = 15 -secrets = { - "ssid" : os.getenv("CIRCUITPY_WIFI_SSID"), - "password" : os.getenv("CIRCUITPY_WIFI_PASSWORD"), -} +# Get WiFi details, ensure these are setup in settings.toml +ssid = getenv("CIRCUITPY_WIFI_SSID") +password = getenv("CIRCUITPY_WIFI_PASSWORD") + +if None in [ssid, password]: + raise RuntimeError( + "WiFi settings are kept in settings.toml, " + "please add them there. The settings file must contain " + "'CIRCUITPY_WIFI_SSID', 'CIRCUITPY_WIFI_PASSWORD', " + "at a minimum." + ) # Get device certificate try: @@ -65,9 +73,10 @@ # Verify nina-fw version >= 1.4.0 assert int(bytes(esp.firmware_version).decode("utf-8")[2]) >= 4, "Please update nina-fw to >=1.4.0." -status_light = neopixel.NeoPixel(board.NEOPIXEL, 1, brightness=0.2) -wifi = adafruit_esp32spi_wifimanager.ESPSPI_WiFiManager( - esp, secrets, status_light) +status_pixel = neopixel.NeoPixel(board.NEOPIXEL, 1, brightness=0.2) +wifi = adafruit_esp32spi_wifimanager.WiFiManager( + esp, ssid, password, status_pixel=status_pixel +) # Initialize the graphics helper print("Loading AWS IoT Graphics...") @@ -126,8 +135,8 @@ def message(client, topic, msg): print("Message from {}: {}".format(topic, msg)) # Set up a new MiniMQTT Client -client = MQTT.MQTT(broker = os.getenv("BROKER"), - client_id = os.getenv("CLIENT_ID"), +client = MQTT.MQTT(broker = getenv("BROKER"), + client_id = getenv("CLIENT_ID"), socket_pool=pool, ssl_context=ssl_context) diff --git a/PyPortal/PyPortal_AdafruitIO/code.py b/PyPortal/PyPortal_AdafruitIO/code.py index bba018f89..a4ba33b31 100644 --- a/PyPortal/PyPortal_AdafruitIO/code.py +++ b/PyPortal/PyPortal_AdafruitIO/code.py @@ -7,19 +7,29 @@ and io plus subscribers... and display it on a screen If you can find something that spits out JSON data, we can display it! """ + +from os import getenv import time import board from adafruit_pyportal import PyPortal -# 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 Adafruit IO keys, ensure these are setup in settings.toml +# (visit io.adafruit.com if you need to create an account, or if you need your Adafruit IO key.) +ssid = getenv("CIRCUITPY_WIFI_SSID") +password = getenv("CIRCUITPY_WIFI_PASSWORD") +aio_username = getenv("ADAFRUIT_AIO_USERNAME") +aio_key = getenv("ADAFRUIT_AIO_KEY") + +if None in [ssid, password, aio_username, aio_key]: + raise RuntimeError( + "WiFi and Adafruit IO settings are kept in settings.toml, " + "please add them there. The settings file must contain " + "'CIRCUITPY_WIFI_SSID', 'CIRCUITPY_WIFI_PASSWORD', " + "'ADAFRUIT_AIO_USERNAME' and 'ADAFRUIT_AIO_KEY' at a minimum." + ) # Set up where we'll be fetching data from -DATA_SOURCE = "https://io.adafruit.com/api/v2/stats?x-aio-key="+secrets['aio_key'] +DATA_SOURCE = f"https://io.adafruit.com/api/v2/stats?x-aio-key={aio_key}" DATA_LOCATION1 = ["io_plus", "io_plus_subscriptions"] DATA_LOCATION2 = ["users", "users_active_30_days"] diff --git a/PyPortal/PyPortal_AdafruitIO_Logger/code.py b/PyPortal/PyPortal_AdafruitIO_Logger/code.py index 77d37ead8..5d743b730 100644 --- a/PyPortal/PyPortal_AdafruitIO_Logger/code.py +++ b/PyPortal/PyPortal_AdafruitIO_Logger/code.py @@ -12,6 +12,8 @@ * CircuitPython_AdafruitIO https://github.com/adafruit/Adafruit_CircuitPython_AdafruitIO """ + +from os import getenv import time import board import busio @@ -33,12 +35,20 @@ # Timeout between sending data to Adafruit IO, in seconds IO_DELAY = 30 -# 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 Adafruit IO keys, ensure these are setup in settings.toml +# (visit io.adafruit.com if you need to create an account, or if you need your Adafruit IO key.) +ssid = getenv("CIRCUITPY_WIFI_SSID") +password = getenv("CIRCUITPY_WIFI_PASSWORD") +aio_username = getenv("ADAFRUIT_AIO_USERNAME") +aio_key = getenv("ADAFRUIT_AIO_KEY") + +if None in [ssid, password, aio_username, aio_key]: + raise RuntimeError( + "WiFi and Adafruit IO settings are kept in settings.toml, " + "please add them there. The settings file must contain " + "'CIRCUITPY_WIFI_SSID', 'CIRCUITPY_WIFI_PASSWORD', " + "'ADAFRUIT_AIO_USERNAME' and 'ADAFRUIT_AIO_KEY' at a minimum." + ) # PyPortal ESP32 Setup esp32_cs = DigitalInOut(board.ESP_CS) @@ -46,17 +56,11 @@ esp32_reset = DigitalInOut(board.ESP_RESET) spi = busio.SPI(board.SCK, board.MOSI, board.MISO) esp = adafruit_esp32spi.ESP_SPIcontrol(spi, esp32_cs, esp32_ready, esp32_reset) -status_light = neopixel.NeoPixel(board.NEOPIXEL, 1, brightness=0.2) -wifi = adafruit_esp32spi_wifimanager.ESPSPI_WiFiManager(esp, secrets, status_light) - -# Set your Adafruit IO Username and Key in secrets.py -# (visit io.adafruit.com if you need to create an account, -# or if you need your Adafruit IO key.) -ADAFRUIT_IO_USER = secrets['aio_username'] -ADAFRUIT_IO_KEY = secrets['aio_key'] +status_pixel = neopixel.NeoPixel(board.NEOPIXEL, 1, brightness=0.2) +wifi = adafruit_esp32spi_wifimanager.WiFiManager(esp, ssid, password, status_pixel=status_pixel) # Create an instance of the Adafruit IO HTTP client -io = IO_HTTP(ADAFRUIT_IO_USER, ADAFRUIT_IO_KEY, wifi) +io = IO_HTTP(aio_username, aio_key, wifi) try: # Get the 'temperature' feed from Adafruit IO diff --git a/PyPortal/PyPortal_Alarm_Clock/code.py b/PyPortal/PyPortal_Alarm_Clock/code.py index 0234a7c83..4b0c191d8 100644 --- a/PyPortal/PyPortal_Alarm_Clock/code.py +++ b/PyPortal/PyPortal_Alarm_Clock/code.py @@ -20,9 +20,9 @@ #pylint:disable=no-self-use,too-many-branches,too-many-statements #pylint:disable=useless-super-delegation, too-many-locals +from os import getenv import time import json -from secrets import secrets import board from adafruit_pyportal import PyPortal from adafruit_bitmap_font import bitmap_font @@ -32,9 +32,21 @@ import displayio import adafruit_logging as logging +# Get WiFi details, ensure these are setup in settings.toml +ssid = getenv("CIRCUITPY_WIFI_SSID") +password = getenv("CIRCUITPY_WIFI_PASSWORD") + +if None in [ssid, password]: + raise RuntimeError( + "WiFi settings are kept in settings.toml, " + "please add them there. The settings file must contain " + "'CIRCUITPY_WIFI_SSID', 'CIRCUITPY_WIFI_PASSWORD', " + "at a minimum." + ) + # Set up where we'll be fetching data from -DATA_SOURCE = 'http://api.openweathermap.org/data/2.5/weather?id='+secrets['city_id'] -DATA_SOURCE += '&appid='+secrets['openweather_token'] +DATA_SOURCE = 'http://api.openweathermap.org/data/2.5/weather?id='+getenv('city_id') +DATA_SOURCE += '&appid='+getenv('openweather_token') # You'll need to get a token from openweather.org, looks like 'b6907d289e10d714a6e88b30761fae22' DATA_LOCATION = [] @@ -73,7 +85,7 @@ icon_file = None icon_sprite = None -celcius = secrets['celcius'] +celcius = getenv('celcius') # display/data refresh timers @@ -243,7 +255,7 @@ def tick(self, now): if (not self.refresh_time) or ((now - self.refresh_time) > 3600): logger.debug('Fetching time') try: - pyportal.get_local_time(location=secrets['timezone']) + pyportal.get_local_time(location=getenv('timezone')) self.refresh_time = now except RuntimeError as e: self.refresh_time = now - 3000 # delay 10 minutes before retrying diff --git a/PyPortal/PyPortal_Azure_Plant_Monitor/code.py b/PyPortal/PyPortal_Azure_Plant_Monitor/code.py index 832c14b6d..be79a9660 100755 --- a/PyPortal/PyPortal_Azure_Plant_Monitor/code.py +++ b/PyPortal/PyPortal_Azure_Plant_Monitor/code.py @@ -12,6 +12,8 @@ Authors: Brent Rubell for Adafruit Industries, 2019 : Jim Bennett for Microsoft, 2020 """ + +from os import getenv import time import json import board @@ -30,12 +32,17 @@ # init. graphics helper gfx = azure_gfx_helper.Azure_GFX(is_celsius=True) -# 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, ensure these are setup in settings.toml +ssid = getenv("CIRCUITPY_WIFI_SSID") +password = getenv("CIRCUITPY_WIFI_PASSWORD") + +if None in [ssid, password]: + raise RuntimeError( + "WiFi settings are kept in settings.toml, " + "please add them there. The settings file must contain " + "'CIRCUITPY_WIFI_SSID', 'CIRCUITPY_WIFI_PASSWORD', " + "at a minimum." + ) # PyPortal ESP32 Setup esp32_cs = DigitalInOut(board.ESP_CS) @@ -45,8 +52,8 @@ esp = adafruit_esp32spi.ESP_SPIcontrol(spi, esp32_cs, esp32_ready, esp32_reset) # Set up the WiFi manager with a status light to show the WiFi connection status -status_light = neopixel.NeoPixel(board.NEOPIXEL, 1, brightness=0.2) -wifi = adafruit_esp32spi_wifimanager.ESPSPI_WiFiManager(esp, secrets, status_light) +status_pixel = neopixel.NeoPixel(board.NEOPIXEL, 1, brightness=0.2) +wifi = adafruit_esp32spi_wifimanager.WiFiManager(esp, ssid, password, status_pixel=status_pixel) print("WiFi connecting...") wifi.connect() print("WiFi connected!") @@ -68,7 +75,7 @@ # Create an instance of the Azure IoT Central device device = IoTCentralDevice( - socket, esp, secrets["id_scope"], secrets["device_id"], secrets["key"] + socket, esp, getenv("id_scope"), getenv("device_id"), getenv("key") ) # Connect to Azure IoT Central diff --git a/PyPortal/PyPortal_CMA_Art_Frame/code.py b/PyPortal/PyPortal_CMA_Art_Frame/code.py index 6fe4a1940..8b8d62b96 100644 --- a/PyPortal/PyPortal_CMA_Art_Frame/code.py +++ b/PyPortal/PyPortal_CMA_Art_Frame/code.py @@ -2,6 +2,7 @@ # # SPDX-License-Identifier: MIT +from os import getenv import time import random import board @@ -11,6 +12,18 @@ WIDTH = board.DISPLAY.width HEIGHT = board.DISPLAY.height +# Get WiFi details, ensure these are setup in settings.toml +ssid = getenv("CIRCUITPY_WIFI_SSID") +password = getenv("CIRCUITPY_WIFI_PASSWORD") + +if None in [ssid, password]: + raise RuntimeError( + "WiFi settings are kept in settings.toml, " + "please add them there. The settings file must contain " + "'CIRCUITPY_WIFI_SSID', 'CIRCUITPY_WIFI_PASSWORD', " + "at a minimum." + ) + #pylint: disable=line-too-long # these lines show the entire collection diff --git a/PyPortal/PyPortal_CMA_Art_Frame/secrets.py b/PyPortal/PyPortal_CMA_Art_Frame/secrets.py deleted file mode 100644 index 64c59aacb..000000000 --- a/PyPortal/PyPortal_CMA_Art_Frame/secrets.py +++ /dev/null @@ -1,13 +0,0 @@ -# SPDX-FileCopyrightText: 2019 Kattni Rembor for Adafruit Industries -# -# SPDX-License-Identifier: MIT - -# This file is where you keep secret settings, passwords, and tokens! -# If you put them in the code you risk committing that info or sharing it - -secrets = { - 'ssid' : 'CHANGE ME', - 'password' : 'CHANGE ME', - 'aio_username' : 'CHANGE ME', - 'aio_key' : 'CHANGE ME', -} diff --git a/PyPortal/PyPortal_CMA_Art_Frame/settings.toml b/PyPortal/PyPortal_CMA_Art_Frame/settings.toml new file mode 100644 index 000000000..1dcd09070 --- /dev/null +++ b/PyPortal/PyPortal_CMA_Art_Frame/settings.toml @@ -0,0 +1,9 @@ +# SPDX-FileCopyrightText: 2019 Kattni Rembor for Adafruit Industries +# +# SPDX-License-Identifier: MIT + +# This file is where you keep private settings, passwords, and tokens! +# If you put them in the code you risk committing that info or sharing it + +CIRCUITPY_WIFI_SSID="your-wifi-ssid" +CIRCUITPY_WIFI_PASSWORD="your-wifi-password" diff --git a/PyPortal/PyPortal_Electioncal_US/.circuitpython.skip b/PyPortal/PyPortal_Electioncal_US/.circuitpython.skip deleted file mode 100644 index 25434fef9..000000000 --- a/PyPortal/PyPortal_Electioncal_US/.circuitpython.skip +++ /dev/null @@ -1,7 +0,0 @@ -PyPortal_Electioncal_US/electioncal_graphics.py 73: Line too long (120/100) (line-too-long) -PyPortal_Electioncal_US/electioncal_graphics.py 75: Line too long (108/100) (line-too-long) -PyPortal_Electioncal_US/electioncal_graphics.py 86: Line too long (141/100) (line-too-long) -PyPortal_Electioncal_US/electioncal_graphics.py 107: Unused variable 'time_str' (unused-variable) -PyPortal_Electioncal_US/electioncal_graphics.py 111: Method could be a function (no-self-use) -PyPortal_Electioncal_US/electioncal_graphics.py 72: Attribute 'electioncal' defined outside __init__ (attribute-defined-outside-init) -PyPortal_Electioncal_US/electioncal.py 11: Unused secrets imported from secrets (unused-import) diff --git a/PyPortal/PyPortal_Electioncal_US/code.py b/PyPortal/PyPortal_Electioncal_US/code.py index a7601499b..911e8ab95 100644 --- a/PyPortal/PyPortal_Electioncal_US/code.py +++ b/PyPortal/PyPortal_Electioncal_US/code.py @@ -2,6 +2,7 @@ # # SPDX-License-Identifier: MIT +from os import getenv import sys import time import board @@ -10,12 +11,17 @@ sys.path.append(cwd) import electioncal_graphics # pylint: disable=wrong-import-position -# Get wifi details and more from a secrets.py file -try: - from secrets import secrets # pylint: disable=unused-import -except ImportError: - print("WiFi secrets are kept in secrets.py, please add them there!") - raise +# Get WiFi details, ensure these are setup in settings.toml +ssid = getenv("CIRCUITPY_WIFI_SSID") +password = getenv("CIRCUITPY_WIFI_PASSWORD") + +if None in [ssid, password]: + raise RuntimeError( + "WiFi settings are kept in settings.toml, " + "please add them there. The settings file must contain " + "'CIRCUITPY_WIFI_SSID', 'CIRCUITPY_WIFI_PASSWORD', " + "at a minimum." + ) # Change this to your state and county, replacing spaces for underscores and in lowercase STATE="new_york" diff --git a/PyPortal/PyPortal_Electioncal_US/electioncal_graphics.py b/PyPortal/PyPortal_Electioncal_US/electioncal_graphics.py index 145219363..e6e332316 100644 --- a/PyPortal/PyPortal_Electioncal_US/electioncal_graphics.py +++ b/PyPortal/PyPortal_Electioncal_US/electioncal_graphics.py @@ -112,7 +112,8 @@ def update_time(self): date_str = date_format_str % (year, month, day) self.date_text.text = "Today is: " + date_str - def paragrapher(self, text, cut): # pylint: disable=no-self-use + @staticmethod + def paragrapher(text, cut): """ Cuts a long line into two, having spaces in mind. Note we return line2 first as it looks better to clear the line2 before printing a line1 with empty line2 diff --git a/PyPortal/PyPortal_Email_Display/code.py b/PyPortal/PyPortal_Email_Display/code.py index 987f90f1f..85a4fe70b 100755 --- a/PyPortal/PyPortal_Email_Display/code.py +++ b/PyPortal/PyPortal_Email_Display/code.py @@ -7,25 +7,30 @@ Displays an Adafruit IO Feed on a PyPortal. """ + +from os import getenv import time import board from adafruit_pyportal import PyPortal -# Get Adafruit IO details and more from a secrets.py file -try: - from secrets import secrets -except ImportError: - print("Adafruit IO secrets are kept in secrets.py, please add them there!") - raise +# (visit io.adafruit.com if you need to create an account, or if you need your Adafruit IO key.) +ssid = getenv("CIRCUITPY_WIFI_SSID") +password = getenv("CIRCUITPY_WIFI_PASSWORD") +aio_username = getenv("ADAFRUIT_AIO_USERNAME") +aio_key = getenv("ADAFRUIT_AIO_KEY") + +if None in [ssid, password, aio_username, aio_key]: + raise RuntimeError( + "WiFi and Adafruit IO settings are kept in settings.toml, " + "please add them there. The settings file must contain " + "'CIRCUITPY_WIFI_SSID', 'CIRCUITPY_WIFI_PASSWORD', " + "'ADAFRUIT_AIO_USERNAME' and 'ADAFRUIT_AIO_KEY' at a minimum." + ) -# Adafruit IO Account -IO_USER = secrets['aio_username'] -IO_KEY = secrets['aio_key'] # Adafruit IO Feed -IO_FEED = 'zapemail' +io_feed = 'zapemail' -DATA_SOURCE = "https://io.adafruit.com/api/v2/{0}/feeds/{1}?X-AIO-Key={2}".format(IO_USER, - IO_FEED, IO_KEY) +DATA_SOURCE = f"https://io.adafruit.com/api/v2/{aio_username}/feeds/{io_feed}?X-AIO-Key={aio_key}" FEED_VALUE_LOCATION = ['last_value'] cwd = ("/"+__file__).rsplit('/', 1)[0] diff --git a/PyPortal/PyPortal_GCP_IOT_Planter/code.py b/PyPortal/PyPortal_GCP_IOT_Planter/code.py index a7fc58140..4a21d3a91 100644 --- a/PyPortal/PyPortal_GCP_IOT_Planter/code.py +++ b/PyPortal/PyPortal_GCP_IOT_Planter/code.py @@ -10,6 +10,8 @@ Author: Brent Rubell for Adafruit Industries, 2019 """ + +from os import getenv import time import json import board @@ -23,25 +25,31 @@ from adafruit_seesaw.seesaw import Seesaw import digitalio +# Get WiFi details, ensure these are setup in settings.toml +ssid = getenv("CIRCUITPY_WIFI_SSID") +password = getenv("CIRCUITPY_WIFI_PASSWORD") + +if None in [ssid, password]: + raise RuntimeError( + "WiFi settings are kept in settings.toml, " + "please add them there. The settings file must contain " + "'CIRCUITPY_WIFI_SSID', 'CIRCUITPY_WIFI_PASSWORD', " + "at a minimum." + ) + # Delay before reading the sensors, in minutes SENSOR_DELAY = 10 -# 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 - # PyPortal ESP32 Setup esp32_cs = digitalio.DigitalInOut(board.ESP_CS) esp32_ready = digitalio.DigitalInOut(board.ESP_BUSY) esp32_reset = digitalio.DigitalInOut(board.ESP_RESET) spi = busio.SPI(board.SCK, board.MOSI, board.MISO) esp = adafruit_esp32spi.ESP_SPIcontrol(spi, esp32_cs, esp32_ready, esp32_reset) -status_light = neopixel.NeoPixel(board.NEOPIXEL, 1, brightness=0.2) -wifi = adafruit_esp32spi_wifimanager.ESPSPI_WiFiManager( - esp, secrets, status_light) +status_pixel = neopixel.NeoPixel(board.NEOPIXEL, 1, brightness=0.2) +wifi = adafruit_esp32spi_wifimanager.WiFiManager( + esp, ssid, password, status_pixel=status_pixel +) # Connect to WiFi print("Connecting to WiFi...") @@ -137,7 +145,14 @@ def handle_pump(command): # Initialize Google Cloud IoT Core interface -google_iot = Cloud_Core(esp, secrets) +settings = { + "cloud_region": getenv("cloud_region"), + "device_id": getenv("device_id"), + "private_key": getenv("private_key"), + "project_id": getenv("project_id"), + "registry_id": getenv("registry_id"), +} +google_iot = Cloud_Core(esp, settings) # JSON-Web-Token (JWT) Generation print("Generating JWT...") diff --git a/PyPortal/PyPortal_GCP_IOT_Planter/gcp_gfx_helper.py b/PyPortal/PyPortal_GCP_IOT_Planter/gcp_gfx_helper.py index fe6aa0720..a10d6f43f 100644 --- a/PyPortal/PyPortal_GCP_IOT_Planter/gcp_gfx_helper.py +++ b/PyPortal/PyPortal_GCP_IOT_Planter/gcp_gfx_helper.py @@ -59,7 +59,7 @@ def __init__(self, is_celsius=False): temp_group.append(temp_label) self.temp_data_label = Label(font, text="75 F") - self.temp_data_label.x = (self.display.width//3) + self.temp_data_label.x = self.display.width//3 self.temp_data_label.y = 55 temp_group.append(self.temp_data_label) self._text_group.append(temp_group) @@ -72,7 +72,7 @@ def __init__(self, is_celsius=False): water_group.append(self.water_level) self.water_lvl_label = Label(font, text="350") - self.water_lvl_label.x = (self.display.width//3) + self.water_lvl_label.x = self.display.width//3 self.water_lvl_label.y = 75 temp_group.append(self.water_lvl_label) self._text_group.append(water_group) diff --git a/PyPortal/PyPortal_GithubStars/code.py b/PyPortal/PyPortal_GithubStars/code.py index efab55c6e..7ed47111c 100644 --- a/PyPortal/PyPortal_GithubStars/code.py +++ b/PyPortal/PyPortal_GithubStars/code.py @@ -7,23 +7,31 @@ the number of stars for a repository... and display it on a screen! if you can find something that spits out JSON data, we can display it """ + +from os import getenv import time import board from adafruit_pyportal import PyPortal -# 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, ensure these are setup in settings.toml +ssid = getenv("CIRCUITPY_WIFI_SSID") +password = getenv("CIRCUITPY_WIFI_PASSWORD") + +if None in [ssid, password]: + raise RuntimeError( + "WiFi settings are kept in settings.toml, " + "please add them there. The settings file must contain " + "'CIRCUITPY_WIFI_SSID', 'CIRCUITPY_WIFI_PASSWORD', " + "at a minimum." + ) # Set up where we'll be fetching data from DATA_SOURCE = "https://api.github.com/repos/adafruit/circuitpython" CAPTION = "www.github.com/adafruit/circuitpython" # If we have an access token, we can query more often -if 'github_token' in secrets: - DATA_SOURCE += "?access_token="+secrets['github_token'] +github_token = getenv("github_token") +if github_token: + DATA_SOURCE += f"?access_token={github_token}" # The data we want to display DATA_LOCATION = ["stargazers_count"] diff --git a/PyPortal/PyPortal_Guitar_Tuner/secrets.py b/PyPortal/PyPortal_Guitar_Tuner/secrets.py deleted file mode 100644 index 8626bef95..000000000 --- a/PyPortal/PyPortal_Guitar_Tuner/secrets.py +++ /dev/null @@ -1,12 +0,0 @@ -# SPDX-FileCopyrightText: 2020 Liz Clark for Adafruit Industries -# -# SPDX-License-Identifier: MIT - -secrets = { - 'ssid' : 'your-ssid-here', - 'password' : 'your-password-here', - 'openweather_token' : 'your-openweather-token-here', - 'aio_username' : "your-aio-username-here", - 'aio_key' : 'your-aio-key-here', - 'location' : 'New York, US' -} diff --git a/PyPortal/PyPortal_HaDSkulls/code.py b/PyPortal/PyPortal_HaDSkulls/code.py index b67bf1d20..051027cf5 100644 --- a/PyPortal/PyPortal_HaDSkulls/code.py +++ b/PyPortal/PyPortal_HaDSkulls/code.py @@ -8,20 +8,27 @@ If you can find something that spits out JSON data, we can display it! Note that you need a hackaday API key to access the API! """ + +from os import getenv import time import board from adafruit_pyportal import PyPortal -# 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, ensure these are setup in settings.toml +ssid = getenv("CIRCUITPY_WIFI_SSID") +password = getenv("CIRCUITPY_WIFI_PASSWORD") + +if None in [ssid, password]: + raise RuntimeError( + "WiFi settings are kept in settings.toml, " + "please add them there. The settings file must contain " + "'CIRCUITPY_WIFI_SSID', 'CIRCUITPY_WIFI_PASSWORD', " + "at a minimum." + ) # Some data sources and JSON locations to try out CAPTION="hackaday.io/project/163309-circuitpython-hackaday" -DATA_SOURCE = "https://api.hackaday.io/v1/projects/163309?api_key="+secrets['hackaday_token'] +DATA_SOURCE = "https://api.hackaday.io/v1/projects/163309?api_key="+getenv('hackaday_token') DATA_LOCATION = ["skulls"] # the current working directory (where this file is) diff --git a/PyPortal/PyPortal_Hackster/code.py b/PyPortal/PyPortal_Hackster/code.py index e2d2d730d..3ec10d227 100644 --- a/PyPortal/PyPortal_Hackster/code.py +++ b/PyPortal/PyPortal_Hackster/code.py @@ -2,23 +2,29 @@ # # SPDX-License-Identifier: MIT +from os import getenv import time import board from adafruit_pyportal import PyPortal -# 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, ensure these are setup in settings.toml +ssid = getenv("CIRCUITPY_WIFI_SSID") +password = getenv("CIRCUITPY_WIFI_PASSWORD") + +if None in [ssid, password]: + raise RuntimeError( + "WiFi settings are kept in settings.toml, " + "please add them there. The settings file must contain " + "'CIRCUITPY_WIFI_SSID', 'CIRCUITPY_WIFI_PASSWORD', " + "at a minimum." + ) PROJECT_NAME = "3c92f0" # Set up where we'll be fetching data from DATA_SOURCE = "https://api.hackster.io/v2/projects/"+PROJECT_NAME+"?" -DATA_SOURCE += "client_id="+secrets['hackster_clientid'] -DATA_SOURCE += "&client_secret="+secrets['hackster_secret'] +DATA_SOURCE += "client_id="+getenv('hackster_clientid') +DATA_SOURCE += "&client_secret="+getenv('hackster_secret') VIEWS_LOCATION = ['stats', 'views'] LIKES_LOCATION = ['stats', 'respects'] CAPTION = "http://www.hackster.com/project/"+PROJECT_NAME diff --git a/PyPortal/PyPortal_HacksterStream/code.py b/PyPortal/PyPortal_HacksterStream/code.py index f67709bc9..beff3429b 100644 --- a/PyPortal/PyPortal_HacksterStream/code.py +++ b/PyPortal/PyPortal_HacksterStream/code.py @@ -2,22 +2,28 @@ # # SPDX-License-Identifier: MIT +from os import getenv import time import random import board import adafruit_pyportal -# Get wifi details and more from a settings.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, ensure these are setup in settings.toml +ssid = getenv("CIRCUITPY_WIFI_SSID") +password = getenv("CIRCUITPY_WIFI_PASSWORD") + +if None in [ssid, password]: + raise RuntimeError( + "WiFi settings are kept in settings.toml, " + "please add them there. The settings file must contain " + "'CIRCUITPY_WIFI_SSID', 'CIRCUITPY_WIFI_PASSWORD', " + "at a minimum." + ) # Set up where we'll be fetching data from DATA_SOURCE = "https://api.hackster.io/v2/projects?" -DATA_SOURCE += "client_id="+secrets['hackster_clientid'] -DATA_SOURCE += "&client_secret="+secrets['hackster_secret'] +DATA_SOURCE += "client_id="+getenv('hackster_clientid') +DATA_SOURCE += "&client_secret="+getenv('hackster_secret') IMAGE_LOCATION = ['records', 0, "cover_image_url"] TITLE_LOCATION = ['records',0, "name"] HID_LOCATION = ['records', 0, "hid"] diff --git a/PyPortal/PyPortal_Halloween_Countdown/code.py b/PyPortal/PyPortal_Halloween_Countdown/code.py index 6bdf44fc5..decf6c6f3 100644 --- a/PyPortal/PyPortal_Halloween_Countdown/code.py +++ b/PyPortal/PyPortal_Halloween_Countdown/code.py @@ -16,8 +16,7 @@ All text above must be included in any redistribution. """ -#pylint:disable=invalid-name -import os +from os import getenv import time import random import board @@ -25,6 +24,19 @@ from adafruit_bitmap_font import bitmap_font from adafruit_display_text.label import Label +# Get WiFi details, ensure these are setup in settings.toml +ssid = getenv("CIRCUITPY_WIFI_SSID") +password = getenv("CIRCUITPY_WIFI_PASSWORD") + +if None in [ssid, password]: + raise RuntimeError( + "WiFi settings are kept in settings.toml, " + "please add them there. The settings file must contain " + "'CIRCUITPY_WIFI_SSID', 'CIRCUITPY_WIFI_PASSWORD', " + "at a minimum." + ) + + # The time of the thing! EVENT_YEAR = 2019 EVENT_MONTH = 10 @@ -83,7 +95,7 @@ if (not refresh_time) or (time.monotonic() - refresh_time) > 3600: try: print("Getting time from internet!") - pyportal.get_local_time(location=os.getenv("TIMEZONE")) + pyportal.get_local_time(location=getenv("timezone")) refresh_time = time.monotonic() except RuntimeError as e: print("Some error occured, retrying! -", e) diff --git a/PyPortal/PyPortal_Halloween_Countdown/secrets.py b/PyPortal/PyPortal_Halloween_Countdown/secrets.py deleted file mode 100644 index 0d76178f1..000000000 --- a/PyPortal/PyPortal_Halloween_Countdown/secrets.py +++ /dev/null @@ -1,14 +0,0 @@ -# SPDX-FileCopyrightText: 2019 Kattni Rembor for Adafruit Industries -# -# SPDX-License-Identifier: MIT - -# This file is where you keep secret settings, passwords, and tokens! -# If you put them in the code you risk committing that info or sharing it - -secrets = { - 'ssid' : 'CHANGE ME', - 'password' : 'CHANGE ME', - 'timezone' : 'CHANGE ME', - 'aio_username' : 'CHANGE ME', - 'aio_key' : 'CHANGE ME', -} diff --git a/PyPortal/PyPortal_Halloween_Countdown/settings.toml b/PyPortal/PyPortal_Halloween_Countdown/settings.toml new file mode 100644 index 000000000..9d1ca379d --- /dev/null +++ b/PyPortal/PyPortal_Halloween_Countdown/settings.toml @@ -0,0 +1,10 @@ +# SPDX-FileCopyrightText: 2019 Kattni Rembor for Adafruit Industries +# +# SPDX-License-Identifier: MIT + +# This file is where you keep private settings, passwords, and tokens! +# If you put them in the code you risk committing that info or sharing it + +CIRCUITPY_WIFI_SSID="your-wifi-ssid" +CIRCUITPY_WIFI_PASSWORD="your-wifi-password" +timezone="America/New_York" # http://worldtimeapi.org/timezones diff --git a/PyPortal/PyPortal_IOT_Scale/code.py b/PyPortal/PyPortal_IOT_Scale/code.py index a10cd0c59..224e978f7 100644 --- a/PyPortal/PyPortal_IOT_Scale/code.py +++ b/PyPortal/PyPortal_IOT_Scale/code.py @@ -8,6 +8,8 @@ Brent Rubell for Adafruit Industries, 2019 """ + +from os import getenv import time import board import adafruit_dymoscale @@ -22,12 +24,20 @@ import neopixel from adafruit_io.adafruit_io import IO_HTTP -# 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 Adafruit IO keys, ensure these are setup in settings.toml +# (visit io.adafruit.com if you need to create an account, or if you need your Adafruit IO key.) +ssid = getenv("CIRCUITPY_WIFI_SSID") +password = getenv("CIRCUITPY_WIFI_PASSWORD") +aio_username = getenv("ADAFRUIT_AIO_USERNAME") +aio_key = getenv("ADAFRUIT_AIO_KEY") + +if None in [ssid, password, aio_username, aio_key]: + raise RuntimeError( + "WiFi and Adafruit IO settings are kept in settings.toml, " + "please add them there. The settings file must contain " + "'CIRCUITPY_WIFI_SSID', 'CIRCUITPY_WIFI_PASSWORD', " + "'ADAFRUIT_AIO_USERNAME' and 'ADAFRUIT_AIO_KEY' at a minimum." + ) # the current working directory (where this file is) cwd = ("/"+__file__).rsplit('/', 1)[0] @@ -69,14 +79,8 @@ esp32_reset = digitalio.DigitalInOut(board.ESP_RESET) spi = busio.SPI(board.SCK, board.MOSI, board.MISO) esp = adafruit_esp32spi.ESP_SPIcontrol(spi, esp32_cs, esp32_ready, esp32_reset) -status_light = neopixel.NeoPixel(board.NEOPIXEL, 1, brightness=0.2) -wifi = adafruit_esp32spi_wifimanager.ESPSPI_WiFiManager(esp, secrets, status_light) - -# Set your Adafruit IO Username and Key in secrets.py -# (visit io.adafruit.com if you need to create an account, -# or if you need your Adafruit IO key.) -aio_username = secrets['aio_username'] -aio_key = secrets['aio_key'] +status_pixel = neopixel.NeoPixel(board.NEOPIXEL, 1, brightness=0.2) +wifi = adafruit_esp32spi_wifimanager.WiFiManager(esp, ssid, password, status_pixel=status_pixel) # Create an instance of the IO_HTTP client io = IO_HTTP(aio_username, aio_key, wifi) From 06fcc8e04c0050673abf73389fe8f8a2b525fc8c Mon Sep 17 00:00:00 2001 From: Justin Myers Date: Tue, 8 Apr 2025 11:13:48 -0700 Subject: [PATCH 2/3] Secrets Cleanup: P Part 1 - fix PyPortal_CMA_Art_Frame --- PyPortal/PyPortal_CMA_Art_Frame/code.py | 11 +++++++---- PyPortal/PyPortal_CMA_Art_Frame/settings.toml | 3 +++ 2 files changed, 10 insertions(+), 4 deletions(-) diff --git a/PyPortal/PyPortal_CMA_Art_Frame/code.py b/PyPortal/PyPortal_CMA_Art_Frame/code.py index 8b8d62b96..23d806063 100644 --- a/PyPortal/PyPortal_CMA_Art_Frame/code.py +++ b/PyPortal/PyPortal_CMA_Art_Frame/code.py @@ -12,16 +12,19 @@ WIDTH = board.DISPLAY.width HEIGHT = board.DISPLAY.height -# Get WiFi details, ensure these are setup in settings.toml +# Get WiFi details and Adafruit IO keys, ensure these are setup in settings.toml +# (visit io.adafruit.com if you need to create an account, or if you need your Adafruit IO key.) ssid = getenv("CIRCUITPY_WIFI_SSID") password = getenv("CIRCUITPY_WIFI_PASSWORD") +aio_username = getenv("ADAFRUIT_AIO_USERNAME") +aio_key = getenv("ADAFRUIT_AIO_KEY") -if None in [ssid, password]: +if None in [ssid, password, aio_username, aio_key]: raise RuntimeError( - "WiFi settings are kept in settings.toml, " + "WiFi and Adafruit IO settings are kept in settings.toml, " "please add them there. The settings file must contain " "'CIRCUITPY_WIFI_SSID', 'CIRCUITPY_WIFI_PASSWORD', " - "at a minimum." + "'ADAFRUIT_AIO_USERNAME' and 'ADAFRUIT_AIO_KEY' at a minimum." ) #pylint: disable=line-too-long diff --git a/PyPortal/PyPortal_CMA_Art_Frame/settings.toml b/PyPortal/PyPortal_CMA_Art_Frame/settings.toml index 1dcd09070..bc33202be 100644 --- a/PyPortal/PyPortal_CMA_Art_Frame/settings.toml +++ b/PyPortal/PyPortal_CMA_Art_Frame/settings.toml @@ -7,3 +7,6 @@ CIRCUITPY_WIFI_SSID="your-wifi-ssid" CIRCUITPY_WIFI_PASSWORD="your-wifi-password" +ADAFRUIT_AIO_USERNAME="my_username" +ADAFRUIT_AIO_KEY="my_key" +CIRCUITPY_PYSTACK_SIZE=2048 From fb932a96ecabf3a7e2b60703c5b8c1336aae6976 Mon Sep 17 00:00:00 2001 From: foamyguy Date: Wed, 9 Apr 2025 11:21:53 -0500 Subject: [PATCH 3/3] refactor rsa private key to its own file in gcpiot. add aio name and key to placeholder settings.toml for halloween countdown. --- PyPortal/PyPortal_GCP_IOT_Planter/code.py | 3 ++- PyPortal/PyPortal_GCP_IOT_Planter/rsa_private_key.py | 6 ++++++ PyPortal/PyPortal_Halloween_Countdown/settings.toml | 2 ++ 3 files changed, 10 insertions(+), 1 deletion(-) create mode 100644 PyPortal/PyPortal_GCP_IOT_Planter/rsa_private_key.py diff --git a/PyPortal/PyPortal_GCP_IOT_Planter/code.py b/PyPortal/PyPortal_GCP_IOT_Planter/code.py index 4a21d3a91..6b8b23425 100644 --- a/PyPortal/PyPortal_GCP_IOT_Planter/code.py +++ b/PyPortal/PyPortal_GCP_IOT_Planter/code.py @@ -24,6 +24,7 @@ import adafruit_minimqtt.adafruit_minimqtt as MQTT from adafruit_seesaw.seesaw import Seesaw import digitalio +from rsa_private_key import private_key # Get WiFi details, ensure these are setup in settings.toml ssid = getenv("CIRCUITPY_WIFI_SSID") @@ -148,7 +149,7 @@ def handle_pump(command): settings = { "cloud_region": getenv("cloud_region"), "device_id": getenv("device_id"), - "private_key": getenv("private_key"), + "private_key": private_key, "project_id": getenv("project_id"), "registry_id": getenv("registry_id"), } diff --git a/PyPortal/PyPortal_GCP_IOT_Planter/rsa_private_key.py b/PyPortal/PyPortal_GCP_IOT_Planter/rsa_private_key.py new file mode 100644 index 000000000..9a732aebb --- /dev/null +++ b/PyPortal/PyPortal_GCP_IOT_Planter/rsa_private_key.py @@ -0,0 +1,6 @@ +# SPDX-FileCopyrightText: 2025 Tim Cocks for Adafruit Industries +# +# SPDX-License-Identifier: MIT + +# Replace the value with your generated RSA Private Key +private_key = (0, 0, 0, 0, 0) diff --git a/PyPortal/PyPortal_Halloween_Countdown/settings.toml b/PyPortal/PyPortal_Halloween_Countdown/settings.toml index 9d1ca379d..01fc77e45 100644 --- a/PyPortal/PyPortal_Halloween_Countdown/settings.toml +++ b/PyPortal/PyPortal_Halloween_Countdown/settings.toml @@ -7,4 +7,6 @@ CIRCUITPY_WIFI_SSID="your-wifi-ssid" CIRCUITPY_WIFI_PASSWORD="your-wifi-password" +ADAFRUIT_AIO_USERNAME="my_username" +ADAFRUIT_AIO_KEY="my_key" timezone="America/New_York" # http://worldtimeapi.org/timezones