From 2b5fd71ab0245a5ee22ca5da48ebae6bbbc1fbbc Mon Sep 17 00:00:00 2001 From: Justin Myers Date: Wed, 9 Apr 2025 10:16:06 -0700 Subject: [PATCH 1/2] Secrets Cleanup: P Part 2 --- PyPortal/PyPortal_LIFX_Controller/code.py | 24 ++++++--- PyPortal/PyPortal_LastFM/code.py | 31 +++++++---- PyPortal/PyPortal_LeagueLevel/code.py | 19 +++++-- PyPortal/PyPortal_MQTT_Control/code.py | 30 ++++++----- PyPortal/PyPortal_MQTT_Control/secrets.py | 11 ---- PyPortal/PyPortal_MQTT_Control/settings.toml | 12 +++++ PyPortal/PyPortal_Mirror_Display/code.py | 20 +++++--- PyPortal/PyPortal_OpenWeather/code.py | 21 +++++--- .../PyPortal_Philips_Hue_Controller/code.py | 27 ++++++---- .../month_clock/code.py | 22 +++++--- PyPortal/PyPortal_Remote/code.py | 24 +++++---- PyPortal/PyPortal_Smart_Switch/code.py | 51 ++++++++++--------- PyPortal/PyPortal_Smart_Switch/secrets.py | 15 ------ PyPortal/PyPortal_Smart_Switch/settings.toml | 12 +++++ PyPortal/PyPortal_Smart_Thermometer/code.py | 38 +++++++------- PyPortal/PyPortal_TOTP_Friend/code.py | 17 +++---- PyPortal/PyPortal_TOTP_Friend/secrets.py | 14 ----- PyPortal/PyPortal_TOTP_Friend/totp_keys.py | 14 +++++ .../PyPortal_Tides/admiralty_tides/code.py | 20 +++++--- .../admiralty_tides_graphical/code.py | 20 +++++--- .../PyPortal_Titano_Weather_Station/code.py | 24 +++++---- .../secrets.py | 15 ------ .../settings.toml | 14 +++++ PyPortal/PyPortal_Twin_Peaks/code.py | 6 +-- PyPortal/PyPortal_UV_Index/code.py | 20 +++++--- PyPortal/PyPortal_UV_Index/secrets.py | 12 ----- .../settings.toml} | 7 +-- .../.circuitpython.skip | 1 - PyPortal/PyPortal_User_Interface/secrets.py | 11 ---- PyPortal/pyportal_pet_planter/code.py | 30 +++++++---- PyPortal/pyportal_weather_station/code.py | 32 +++++++----- 31 files changed, 349 insertions(+), 265 deletions(-) delete mode 100644 PyPortal/PyPortal_MQTT_Control/secrets.py create mode 100644 PyPortal/PyPortal_MQTT_Control/settings.toml delete mode 100644 PyPortal/PyPortal_Smart_Switch/secrets.py create mode 100644 PyPortal/PyPortal_Smart_Switch/settings.toml delete mode 100755 PyPortal/PyPortal_TOTP_Friend/secrets.py create mode 100644 PyPortal/PyPortal_TOTP_Friend/totp_keys.py delete mode 100644 PyPortal/PyPortal_Titano_Weather_Station/secrets.py create mode 100644 PyPortal/PyPortal_Titano_Weather_Station/settings.toml delete mode 100644 PyPortal/PyPortal_UV_Index/secrets.py rename PyPortal/{PyPortal_NeoPixel_Color_Picker/secrets.py => PyPortal_UV_Index/settings.toml} (51%) mode change 100755 => 100644 delete mode 100644 PyPortal/PyPortal_User_Interface/.circuitpython.skip delete mode 100644 PyPortal/PyPortal_User_Interface/secrets.py diff --git a/PyPortal/PyPortal_LIFX_Controller/code.py b/PyPortal/PyPortal_LIFX_Controller/code.py index ebe489e89..139722e78 100755 --- a/PyPortal/PyPortal_LIFX_Controller/code.py +++ b/PyPortal/PyPortal_LIFX_Controller/code.py @@ -9,7 +9,8 @@ Brent Rubell for Adafruit Industries, 2019 """ -import os + +from os import getenv import board import displayio @@ -26,10 +27,17 @@ # import lifx library import adafruit_lifx -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." + ) # ESP32 SPI esp32_cs = DigitalInOut(board.ESP_CS) @@ -37,8 +45,8 @@ 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) +status_pixel = neopixel.NeoPixel(board.NEOPIXEL, 1, brightness=0.2) +wifi = adafruit_esp32spi_wifimanager.WiFiManager(esp, ssid, password, status_pixel=status_pixel) # These pins are used as both analog and digital! XL, XR and YU must be analog # and digital capable. YD just need to be digital @@ -49,7 +57,7 @@ # Set this to your LIFX personal access token in settings.toml # (to obtain a token, visit: https://cloud.lifx.com/settings) -lifx_token = os.getenv("LIFX_TOKEN") +lifx_token = getenv("LIFX_TOKEN") # Initialize the LIFX API Helper lifx = adafruit_lifx.LIFX(wifi, lifx_token) diff --git a/PyPortal/PyPortal_LastFM/code.py b/PyPortal/PyPortal_LastFM/code.py index 53197d910..2be34fff8 100644 --- a/PyPortal/PyPortal_LastFM/code.py +++ b/PyPortal/PyPortal_LastFM/code.py @@ -7,26 +7,35 @@ 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 = "http://ws.audioscrobbler.com/2.0/?method=user.getrecenttracks&limit=1&format=json" CAPTION = "www.last.fm/user" # If we have an access token, we can query more often -if 'lfm_username' in secrets: - DATA_SOURCE += "&user="+secrets['lfm_username'] - CAPTION += "/"+secrets['lfm_username'] -if 'lfm_key' in secrets: - DATA_SOURCE += "&api_key="+secrets['lfm_key'] +lfm_username = getenv("lfm_username") +lfm_key = getenv("lfm_key") +if lfm_username: + DATA_SOURCE += "&user=" + lfm_username + CAPTION += "/" + lfm_username +if lfm_key: + DATA_SOURCE += "&api_key=" + lfm_key print(DATA_SOURCE) # Total number of plays diff --git a/PyPortal/PyPortal_LeagueLevel/code.py b/PyPortal/PyPortal_LeagueLevel/code.py index c8e178895..8d32d9c05 100644 --- a/PyPortal/PyPortal_LeagueLevel/code.py +++ b/PyPortal/PyPortal_LeagueLevel/code.py @@ -5,20 +5,33 @@ """ This project will access the League of Legends API, grab a Summoner's Level and display it on a screen. -You'll need a Riot API key in your secrets.py file +You'll need a Riot API key in your settings.toml file If you can find something that spits out JSON data, we can display it! """ -import os + +from os import getenv import time import board from adafruit_pyportal import PyPortal +# 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." + ) + #Choose a valid Summoner name SUMMONER_NAME = "RiotSchmick" # Set up where we'll be fetching data from DATA_SOURCE = "https://na1.api.riotgames.com/lol/summoner/v4/summoners/by-name/"+SUMMONER_NAME -DATA_SOURCE += "?api_key=" + os.getenv("LEAGUE_TOKEN") +DATA_SOURCE += "?api_key=" + getenv("LEAGUE_TOKEN") DATA_LOCATION = ["summonerLevel"] CAPTION = "SUMMONER "+SUMMONER_NAME diff --git a/PyPortal/PyPortal_MQTT_Control/code.py b/PyPortal/PyPortal_MQTT_Control/code.py index b32ea9a2f..5ed7810d2 100644 --- a/PyPortal/PyPortal_MQTT_Control/code.py +++ b/PyPortal/PyPortal_MQTT_Control/code.py @@ -2,6 +2,7 @@ # # SPDX-License-Identifier: MIT +from os import getenv import board import displayio import busio @@ -18,14 +19,19 @@ import adafruit_touchscreen import adafruit_minimqtt.adafruit_minimqtt as MQTT -# ------------- WiFi ------------- # +# 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 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 +# ------------- WiFi ------------- # # If you are using a board with pre-defined ESP32 Pins: esp32_cs = DigitalInOut(board.ESP_CS) @@ -34,8 +40,8 @@ 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) # ------- Sensor Setup ------- # # init. the temperature sensor @@ -234,10 +240,10 @@ def message(client, topic, message): # Set up a MiniMQTT Client client = MQTT.MQTT( - broker=secrets["broker"], + broker=getenv("mqtt_broker"), port=1883, - username=secrets["user"], - password=secrets["pass"], + username=getenv("mqtt_username"), + password=getenv("mqtt_password"), socket_pool=pool, ssl_context=ssl_context, ) diff --git a/PyPortal/PyPortal_MQTT_Control/secrets.py b/PyPortal/PyPortal_MQTT_Control/secrets.py deleted file mode 100644 index 2a4b3fce5..000000000 --- a/PyPortal/PyPortal_MQTT_Control/secrets.py +++ /dev/null @@ -1,11 +0,0 @@ -# SPDX-FileCopyrightText: 2020 Anne Barela for Adafruit Industries -# -# SPDX-License-Identifier: MIT - -secrets = { - 'ssid' : '_your_wifi_ssid_', - 'password' : '_your_wifi_password_', - 'broker' : '_your_mqtt_broker_url_or_ip', - 'user' : '_your_mqtt_broker_username_', - 'pass' : '_your_mqtt_broker_password_' - } diff --git a/PyPortal/PyPortal_MQTT_Control/settings.toml b/PyPortal/PyPortal_MQTT_Control/settings.toml new file mode 100644 index 000000000..7dd5a1575 --- /dev/null +++ b/PyPortal/PyPortal_MQTT_Control/settings.toml @@ -0,0 +1,12 @@ +# SPDX-FileCopyrightText: 2020 Anne Barela 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" +mqtt_broker="your-mqtt-broker-url-or-ip" +mqtt_username="your-mqtt-broker-username" +mqtt_password="your-mqtt-broker-password" diff --git a/PyPortal/PyPortal_Mirror_Display/code.py b/PyPortal/PyPortal_Mirror_Display/code.py index 0f8ccb1cc..cc7e0f206 100644 --- a/PyPortal/PyPortal_Mirror_Display/code.py +++ b/PyPortal/PyPortal_Mirror_Display/code.py @@ -2,6 +2,7 @@ # # SPDX-License-Identifier: MIT +from os import getenv import sys import time import board @@ -11,12 +12,17 @@ sys.path.append(cwd) import openweather_graphics # pylint: disable=wrong-import-position -# 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." + ) # Use cityname, country code where countrycode is ISO3166 format. # E.g. "New York, US" or "London, GB" @@ -24,7 +30,7 @@ # Set up where we'll be fetching data from DATA_SOURCE = "http://api.openweathermap.org/data/2.5/weather?q="+LOCATION -DATA_SOURCE += "&appid="+secrets['openweather_token'] +DATA_SOURCE += "&appid=" + getenv('openweather_token') # You'll need to get a token from openweather.org, looks like 'b6907d289e10d714a6e88b30761fae22' DATA_LOCATION = [] diff --git a/PyPortal/PyPortal_OpenWeather/code.py b/PyPortal/PyPortal_OpenWeather/code.py index b9b2299b1..eaeb8fa3b 100644 --- a/PyPortal/PyPortal_OpenWeather/code.py +++ b/PyPortal/PyPortal_OpenWeather/code.py @@ -7,6 +7,8 @@ weather for your location... 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 sys import time import board @@ -15,12 +17,17 @@ sys.path.append(cwd) import openweather_graphics # pylint: disable=wrong-import-position -# 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." + ) # Use cityname, country code where countrycode is ISO3166 format. # E.g. "New York, US" or "London, GB" @@ -28,7 +35,7 @@ # Set up where we'll be fetching data from DATA_SOURCE = "http://api.openweathermap.org/data/2.5/weather?q="+LOCATION -DATA_SOURCE += "&appid="+secrets['openweather_token'] +DATA_SOURCE += "&appid=" + getenv('openweather_token') # You'll need to get a token from openweather.org, looks like 'b6907d289e10d714a6e88b30761fae22' DATA_LOCATION = [] diff --git a/PyPortal/PyPortal_Philips_Hue_Controller/code.py b/PyPortal/PyPortal_Philips_Hue_Controller/code.py index 9e12aab05..1473c028c 100644 --- a/PyPortal/PyPortal_Philips_Hue_Controller/code.py +++ b/PyPortal/PyPortal_Philips_Hue_Controller/code.py @@ -7,7 +7,8 @@ Brent Rubell for Adafruit Industries, 2019 """ -import os + +from os import getenv import board import displayio @@ -23,9 +24,17 @@ # Import Philips Hue Bridge from adafruit_hue import Bridge -secrets = dict() -secrets["ssid"] = os.getenv("CIRCUITPY_WIFI_SSID") -secrets["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." + ) # ESP32 SPI esp32_cs = DigitalInOut(board.ESP_CS) @@ -33,13 +42,13 @@ 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) +status_pixel = neopixel.NeoPixel(board.NEOPIXEL, 1, brightness=0.2) +wifi = adafruit_esp32spi_wifimanager.WiFiManager(esp, ssid, password, status_pixel=status_pixel) -# Attempt to load bridge username and IP address from secrets.py +# Attempt to load bridge username and IP address from settings.toml try: - username = os.getenv("HUE_USERNAME") - bridge_ip = os.getenv("BRIDGE_IP") + username = getenv("HUE_USERNAME") + bridge_ip = getenv("BRIDGE_IP") my_bridge = Bridge(wifi, bridge_ip, username) except: # Perform first-time bridge setup diff --git a/PyPortal/PyPortal_Quarantine_Clock/month_clock/code.py b/PyPortal/PyPortal_Quarantine_Clock/month_clock/code.py index 8101046ca..97eb6fdc8 100644 --- a/PyPortal/PyPortal_Quarantine_Clock/month_clock/code.py +++ b/PyPortal/PyPortal_Quarantine_Clock/month_clock/code.py @@ -2,6 +2,7 @@ # # SPDX-License-Identifier: MIT +from os import getenv import time import board import busio @@ -13,12 +14,17 @@ from adafruit_bitmap_font import bitmap_font from adafruit_display_text import label -try: - from secrets import secrets -except ImportError: - print("""WiFi settings are kept in secrets.py, please add them there! -the secrets dictionary must contain 'ssid' and 'password' at a minimum""") - 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." + ) # Label colors LABEL_DAY_COLOR = 0xFFFFFF @@ -88,7 +94,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 @@ -117,7 +123,7 @@ if (not refresh_time) or (time.monotonic() - refresh_time) > 3600: try: print("Getting new time from internet...") - pyportal.get_local_time(secrets['timezone']) + pyportal.get_local_time(getenv('timezone')) refresh_time = time.monotonic() # set the_time the_time = time.localtime() diff --git a/PyPortal/PyPortal_Remote/code.py b/PyPortal/PyPortal_Remote/code.py index 7a1c24af9..8fe00cdfa 100644 --- a/PyPortal/PyPortal_Remote/code.py +++ b/PyPortal/PyPortal_Remote/code.py @@ -1,6 +1,7 @@ # SPDX-FileCopyrightText: 2019 ladyada for Adafruit Industries # SPDX-License-Identifier: MIT +from os import getenv import time import math import board @@ -13,6 +14,18 @@ import adafruit_touchscreen import adafruit_imageload +# 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 the touchscreen ts = adafruit_touchscreen.Touchscreen( board.TOUCH_XL, @@ -23,13 +36,6 @@ size=(320, 240), ) -# 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 - # If you are using a board with pre-defined ESP32 Pins: esp32_cs = DigitalInOut(board.ESP_CS) esp32_ready = DigitalInOut(board.ESP_BUSY) @@ -38,9 +44,9 @@ 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) +status_pixel = neopixel.NeoPixel(board.NEOPIXEL, 1, brightness=0.2) -wifi = adafruit_esp32spi_wifimanager.ESPSPI_WiFiManager(esp, secrets, status_light) +wifi = adafruit_esp32spi_wifimanager.WiFiManager(esp, ssid, password, status_pixel=status_pixel) # Set the ip of your Roku here ip = "192.168.1.3" diff --git a/PyPortal/PyPortal_Smart_Switch/code.py b/PyPortal/PyPortal_Smart_Switch/code.py index 804647782..0a1d3f5b8 100644 --- a/PyPortal/PyPortal_Smart_Switch/code.py +++ b/PyPortal/PyPortal_Smart_Switch/code.py @@ -2,6 +2,7 @@ # # SPDX-License-Identifier: MIT +from os import getenv import time import gc import board @@ -20,6 +21,21 @@ from adafruit_minimqtt import MQTT +# 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." + ) + DISPLAY_COLOR = 0x006600 SWITCH_COLOR = 0x008800 SWITCH_FILL_COLOR = 0xffffff @@ -39,15 +55,8 @@ def get_local_timestamp(location=None): """Fetch and "set" the local time of this microcontroller to the local time at the location, using an internet time API. :param str location: Your city and country, e.g. ``"New York, US"``. """ - # pylint: enable=line-too-long api_url = None - try: - aio_username = secrets['aio_username'] - aio_key = secrets['aio_key'] - except KeyError: - raise KeyError("\n\nOur time service requires 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'")# pylint: disable=line-too-long - - location = secrets.get('timezone', location) + location = getenv('timezone', location) if location: print("Getting time for timezone", location) api_url = (TIME_SERVICE + "&tz=%s") % (aio_username, aio_key, location) @@ -70,7 +79,7 @@ def get_local_timestamp(location=None): tzseconds += tzminutes * 60 print(seconds + tzseconds, tzoffset, tzhours, tzminutes) except KeyError: - raise KeyError("Was unable to lookup the time, try setting secrets['timezone'] according to http://worldtimeapi.org/timezones") # pylint: disable=line-too-long + raise KeyError("Was unable to lookup the time, try setting timezone in your settings.toml according to http://worldtimeapi.org/timezones") # pylint: disable=line-too-long # now clean up response.close() @@ -157,7 +166,7 @@ def tick(self, now): # Update the time print("update the time") self.update_time = int(now) - self.snapshot_time = get_local_timestamp(secrets['timezone']) + self.snapshot_time = get_local_timestamp(getenv("timezone")) self.current_time = time.localtime(self.snapshot_time) else: self.current_time = time.localtime(int(now) - self.update_time + self.snapshot_time) @@ -185,8 +194,8 @@ def tick(self, now): def connected(client, userdata, flags, rc): # This function will be called when the client is connected # successfully to the broker. - onoff_feed = secrets['aio_username'] + '/feeds/' + FEED_NAME - print('Connected to Adafruit IO! Listening for topic changes on %s' % onoff_feed) + onoff_feed = f"{aio_username}/feeds/{FEED_NAME}" + print(f"Connected to Adafruit IO! Listening for topic changes on {onoff_feed}") # Subscribe to all changes on the onoff_feed. client.subscribe(onoff_feed) @@ -205,13 +214,6 @@ def message(client, topic, message): ############################################ -try: - from secrets import secrets -except ImportError: - print("""WiFi settings are kept in secrets.py, please add them there! -the secrets dictionary must contain 'ssid' and 'password' at a minimum""") - raise - esp32_cs = digitalio.DigitalInOut(board.ESP_CS) esp32_ready = digitalio.DigitalInOut(board.ESP_BUSY) esp32_reset = digitalio.DigitalInOut(board.ESP_RESET) @@ -257,7 +259,7 @@ def message(client, topic, message): 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 @@ -265,14 +267,15 @@ def message(client, topic, message): print("My IP address is", esp.pretty_ip(esp.ip_address)) -wifi = adafruit_esp32spi_wifimanager.ESPSPI_WiFiManager( - esp, secrets, debug = True) +wifi = adafruit_esp32spi_wifimanager.WiFiManager( + esp, ssid, password, debug=True +) # Set up a MiniMQTT Client mqtt_client = MQTT(broker='io.adafruit.com', - username=secrets['aio_username'], - password=secrets['aio_key'], + username=aio_username, + password=aio_key, network_manager=wifi, socket_pool=pool, ssl_context=ssl_context) diff --git a/PyPortal/PyPortal_Smart_Switch/secrets.py b/PyPortal/PyPortal_Smart_Switch/secrets.py deleted file mode 100644 index 56c9c2dd4..000000000 --- a/PyPortal/PyPortal_Smart_Switch/secrets.py +++ /dev/null @@ -1,15 +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', - # leave blank or use timezone from # http://worldtimeapi.org/timezones - 'timezone' : '', - 'aio_username' : 'CHANGE ME', - 'aio_key' : 'CHANGE ME', -} diff --git a/PyPortal/PyPortal_Smart_Switch/settings.toml b/PyPortal/PyPortal_Smart_Switch/settings.toml new file mode 100644 index 000000000..5bbf8b275 --- /dev/null +++ b/PyPortal/PyPortal_Smart_Switch/settings.toml @@ -0,0 +1,12 @@ +# 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" +ADAFRUIT_AIO_USERNAME="my_username" +ADAFRUIT_AIO_KEY="my_key" +timezone="" # leave blank or use timezone from # http://worldtimeapi.org/timezones diff --git a/PyPortal/PyPortal_Smart_Thermometer/code.py b/PyPortal/PyPortal_Smart_Thermometer/code.py index b32efa04e..e7fc0af61 100755 --- a/PyPortal/PyPortal_Smart_Thermometer/code.py +++ b/PyPortal/PyPortal_Smart_Thermometer/code.py @@ -10,6 +10,8 @@ Author: Brent Rubell for Adafruit Industries, 2019 """ + +from os import getenv import time import board import neopixel @@ -27,12 +29,20 @@ # rate at which to refresh the pyportal screen, in seconds PYPORTAL_REFRESH = 2 -# 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) @@ -40,21 +50,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.) -try: - ADAFRUIT_IO_USER = secrets['aio_username'] - ADAFRUIT_IO_KEY = secrets['aio_key'] -except KeyError: - raise KeyError('To use this code, you need to include your Adafruit IO username \ -and password in a secrets.py file on the CIRCUITPY drive.') +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(ADAFRUIT_IO_USER, ADAFRUIT_IO_KEY, wifi) +io = IO_HTTP(aio_username, aio_key, wifi) # Get the temperature feed from Adafruit IO temperature_feed = io.get_feed('temperature') diff --git a/PyPortal/PyPortal_TOTP_Friend/code.py b/PyPortal/PyPortal_TOTP_Friend/code.py index 933b3c921..da7f838ef 100644 --- a/PyPortal/PyPortal_TOTP_Friend/code.py +++ b/PyPortal/PyPortal_TOTP_Friend/code.py @@ -36,12 +36,11 @@ # How long to stay on if not in always_on mode ON_SECONDS = 60 -# Get totp keys from a secrets.py file +# Get totp_keys from a totp_keys.py file try: - from secrets import secrets + from totp_keys import totp_keys except ImportError: - print("TOTP keys are kept in secrets.py, please add them there!") - raise + print("TOTP info not found in totp_keys.py, please add them there!") # Initialize PyPortal Display display = board.DISPLAY @@ -228,13 +227,13 @@ def display_otp_key(secret_name, secret_otp): print("Monotonic time", mono_time) # Add buttons to the interface -assert len(secrets['totp_keys']) < 6, "This code can only display 5 keys at a time" +assert len(totp_keys) < 6, "This code can only display 5 keys at a time" # generate buttons buttons = [] btn_x = 5 -for i in secrets['totp_keys']: +for i in totp_keys: button = Button(name=i[0], x=btn_x, y=175, width=60, height=60, label=i[0].strip(" "), @@ -264,7 +263,7 @@ def display_otp_key(secret_name, secret_otp): countdown = ON_SECONDS # current button state, defaults to first item in totp_keys -current_button = secrets['totp_keys'][0][0] +current_button = totp_keys[0][0] buttons[0].selected = True while ALWAYS_ON or (countdown > 0): @@ -295,7 +294,7 @@ def display_otp_key(secret_name, secret_otp): for i, b in enumerate(buttons): if b.contains(p): b.selected = True - for name, secret in secrets['totp_keys']: + for name, secret in totp_keys: # check if button name is the same as a key name if b.name == name: current_button = name @@ -305,7 +304,7 @@ def display_otp_key(secret_name, secret_otp): else: b.selected = False else: - for name, secret in secrets['totp_keys']: + for name, secret in totp_keys: if current_button == name: # Generate OTP otp = generate_otp(unix_time // 30, secret) diff --git a/PyPortal/PyPortal_TOTP_Friend/secrets.py b/PyPortal/PyPortal_TOTP_Friend/secrets.py deleted file mode 100755 index 19cd6267c..000000000 --- a/PyPortal/PyPortal_TOTP_Friend/secrets.py +++ /dev/null @@ -1,14 +0,0 @@ -# SPDX-FileCopyrightText: 2019 Brent Rubell 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 = { - 'totp_keys' : [("Discord ", "JBSWY3DPEHPK3PXP"), - ("Gmail", "JBSWY3DPEHPK3PZP"), - ("GitHub", "JBSWY5DZEHPK3PXP"), - ("Adafruit", "JBSWY6DZEHPK3PXP"), - ("Outlook", "JBSWY7DZEHPK3PXP")] - } diff --git a/PyPortal/PyPortal_TOTP_Friend/totp_keys.py b/PyPortal/PyPortal_TOTP_Friend/totp_keys.py new file mode 100644 index 000000000..b700732a5 --- /dev/null +++ b/PyPortal/PyPortal_TOTP_Friend/totp_keys.py @@ -0,0 +1,14 @@ +# SPDX-FileCopyrightText: 2019 Brent Rubell for Adafruit Industries +# +# SPDX-License-Identifier: MIT + +# This file contains totp codes! +# If you put them in the code you risk committing that info or sharing it + +totp_keys = [ + ("Discord ", "JBSWY3DPEHPK3PXP"), + ("Gmail", "JBSWY3DPEHPK3PZP"), + ("GitHub", "JBSWY5DZEHPK3PXP"), + ("Adafruit", "JBSWY6DZEHPK3PXP"), + ("Outlook", "JBSWY7DZEHPK3PXP"), +] diff --git a/PyPortal/PyPortal_Tides/admiralty_tides/code.py b/PyPortal/PyPortal_Tides/admiralty_tides/code.py index 35eae1c1c..d327b9bea 100644 --- a/PyPortal/PyPortal_Tides/admiralty_tides/code.py +++ b/PyPortal/PyPortal_Tides/admiralty_tides/code.py @@ -2,6 +2,7 @@ # # SPDX-License-Identifier: MIT +from os import getenv import time import json import board @@ -9,12 +10,17 @@ from adafruit_bitmap_font import bitmap_font from adafruit_display_text.label import Label -# 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." + ) #--| USER CONFIG |-------------------------- STATION_ID = "0245" # tide location, find yours from admiralty website/ @@ -30,7 +36,7 @@ # determine the current working directory needed so we know where to find files cwd = ("/"+__file__).rsplit('/', 1)[0] pyportal = PyPortal(url=DATA_SOURCE, - headers={"Ocp-Apim-Subscription-Key":secrets['Ocp-Apim-Subscription-Key']}, + headers={"Ocp-Apim-Subscription-Key": getenv('Ocp-Apim-Subscription-Key')}, json_path=DATA_LOCATION, status_neopixel=board.NEOPIXEL, default_bg=cwd+"/images/tides_bg.bmp") diff --git a/PyPortal/PyPortal_Tides/admiralty_tides_graphical/code.py b/PyPortal/PyPortal_Tides/admiralty_tides_graphical/code.py index b36ae2981..5fe224357 100644 --- a/PyPortal/PyPortal_Tides/admiralty_tides_graphical/code.py +++ b/PyPortal/PyPortal_Tides/admiralty_tides_graphical/code.py @@ -2,6 +2,7 @@ # # SPDX-License-Identifier: MIT +from os import getenv import time import json import board @@ -10,12 +11,17 @@ from adafruit_bitmap_font import bitmap_font from adafruit_display_text.label import Label -# 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." + ) #--| USER CONFIG |-------------------------- STATION_ID = "0245" # tide location, find yours from admiralty website @@ -44,7 +50,7 @@ bg_image_path = "/images/tides_bg_graph.bmp" pyportal = PyPortal(url=DATA_SOURCE, - headers={"Ocp-Apim-Subscription-Key":secrets['Ocp-Apim-Subscription-Key']}, + headers={"Ocp-Apim-Subscription-Key": getenv('Ocp-Apim-Subscription-Key')}, json_path=DATA_LOCATION, status_neopixel=board.NEOPIXEL, default_bg=cwd+bg_image_path) diff --git a/PyPortal/PyPortal_Titano_Weather_Station/code.py b/PyPortal/PyPortal_Titano_Weather_Station/code.py index 9628aca9f..ae7e11da8 100644 --- a/PyPortal/PyPortal_Titano_Weather_Station/code.py +++ b/PyPortal/PyPortal_Titano_Weather_Station/code.py @@ -2,6 +2,7 @@ # # SPDX-License-Identifier: MIT +from os import getenv import time from calendar import alarms from calendar import timers @@ -12,20 +13,25 @@ from adafruit_pyportal import PyPortal import openweather_graphics # pylint: disable=wrong-import-position -# 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." + ) # Use cityname, country code where countrycode is ISO3166 format. # E.g. "New York, US" or "London, GB" -LOCATION = secrets['location'] +LOCATION = getenv('location') # Set up where we'll be fetching data from -DATA_SOURCE = "http://api.openweathermap.org/data/2.5/weather?q="+LOCATION -DATA_SOURCE += "&appid="+secrets['openweather_token'] +DATA_SOURCE = "http://api.openweathermap.org/data/2.5/weather?q=" + LOCATION +DATA_SOURCE += "&appid=" + getenv('openweather_token') # You'll need to get a token from openweather.org, looks like 'b6907d289e10d714a6e88b30761fae22' DATA_LOCATION = [] diff --git a/PyPortal/PyPortal_Titano_Weather_Station/secrets.py b/PyPortal/PyPortal_Titano_Weather_Station/secrets.py deleted file mode 100644 index dd41b82bf..000000000 --- a/PyPortal/PyPortal_Titano_Weather_Station/secrets.py +++ /dev/null @@ -1,15 +0,0 @@ -# SPDX-FileCopyrightText: 2020 Liz Clark 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' : '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_Titano_Weather_Station/settings.toml b/PyPortal/PyPortal_Titano_Weather_Station/settings.toml new file mode 100644 index 000000000..fd18443ce --- /dev/null +++ b/PyPortal/PyPortal_Titano_Weather_Station/settings.toml @@ -0,0 +1,14 @@ +# SPDX-FileCopyrightText: 2020 Liz Clark 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" +ADAFRUIT_AIO_USERNAME="my_username" +ADAFRUIT_AIO_KEY="my_key" +timezone="America/New_York" # http://worldtimeapi.org/timezones +openweather_token="my_openweather_token" +location="New York, US" \ No newline at end of file diff --git a/PyPortal/PyPortal_Twin_Peaks/code.py b/PyPortal/PyPortal_Twin_Peaks/code.py index 385c6746b..be572ae5a 100644 --- a/PyPortal/PyPortal_Twin_Peaks/code.py +++ b/PyPortal/PyPortal_Twin_Peaks/code.py @@ -14,11 +14,11 @@ cwd = ("/"+__file__).rsplit('/', 1)[0] -laura = (cwd+"/laura.bmp") +laura = cwd+"/laura.bmp" -woodsman = (cwd+"/woodsman.bmp") +woodsman = cwd+"/woodsman.bmp" -gottaLight = (cwd+"/gottaLight.wav") +gottaLight = cwd+"/gottaLight.wav" pyportal = PyPortal(default_bg=laura) diff --git a/PyPortal/PyPortal_UV_Index/code.py b/PyPortal/PyPortal_UV_Index/code.py index 82a231360..21f377827 100644 --- a/PyPortal/PyPortal_UV_Index/code.py +++ b/PyPortal/PyPortal_UV_Index/code.py @@ -16,6 +16,7 @@ All text above must be included in any redistribution. """ +from os import getenv import time import json import board @@ -25,12 +26,17 @@ from adafruit_display_text.Label import Label from adafruit_bitmap_font import bitmap_font -try: - from secrets import secrets -except ImportError: - print("""WiFi settings are kept in secrets.py, please add them there! -the secrets dictionary must contain 'ssid' and 'password' at a minimum""") - 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." + ) MAX_BAR_HEIGHT = 160 MARGIN = 10 @@ -48,7 +54,7 @@ BAR_FONT_FILE = cwd+'/fonts/Arial-Bold-12.bdf' #pylint:disable=line-too-long -url = 'https://enviro.epa.gov/enviro/efservice/getEnvirofactsUVHOURLY/ZIP/{0}/JSON'.format(secrets['zip']) +url = f"https://enviro.epa.gov/enviro/efservice/getEnvirofactsUVHOURLY/ZIP/{getenv('zip')}/JSON" #pylint:enable=line-too-long def extract_hour(date_time): diff --git a/PyPortal/PyPortal_UV_Index/secrets.py b/PyPortal/PyPortal_UV_Index/secrets.py deleted file mode 100644 index 6b3a03f08..000000000 --- a/PyPortal/PyPortal_UV_Index/secrets.py +++ /dev/null @@ -1,12 +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', - 'zip' : 'CHANGE ME', -} diff --git a/PyPortal/PyPortal_NeoPixel_Color_Picker/secrets.py b/PyPortal/PyPortal_UV_Index/settings.toml old mode 100755 new mode 100644 similarity index 51% rename from PyPortal/PyPortal_NeoPixel_Color_Picker/secrets.py rename to PyPortal/PyPortal_UV_Index/settings.toml index 2bc3ff875..94ed10a98 --- a/PyPortal/PyPortal_NeoPixel_Color_Picker/secrets.py +++ b/PyPortal/PyPortal_UV_Index/settings.toml @@ -2,8 +2,9 @@ # # SPDX-License-Identifier: MIT -# This file is where you keep secret settings, passwords, and tokens! +# 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 -secrets = { - } +CIRCUITPY_WIFI_SSID="your-wifi-ssid" +CIRCUITPY_WIFI_PASSWORD="your-wifi-password" +zip="CHANGE ME" diff --git a/PyPortal/PyPortal_User_Interface/.circuitpython.skip b/PyPortal/PyPortal_User_Interface/.circuitpython.skip deleted file mode 100644 index bf3e9ce8e..000000000 --- a/PyPortal/PyPortal_User_Interface/.circuitpython.skip +++ /dev/null @@ -1 +0,0 @@ -PyPortal_User_Interface/code.py 128: Line too long (117/100) (line-too-long) diff --git a/PyPortal/PyPortal_User_Interface/secrets.py b/PyPortal/PyPortal_User_Interface/secrets.py deleted file mode 100644 index 2a4b3fce5..000000000 --- a/PyPortal/PyPortal_User_Interface/secrets.py +++ /dev/null @@ -1,11 +0,0 @@ -# SPDX-FileCopyrightText: 2020 Anne Barela for Adafruit Industries -# -# SPDX-License-Identifier: MIT - -secrets = { - 'ssid' : '_your_wifi_ssid_', - 'password' : '_your_wifi_password_', - 'broker' : '_your_mqtt_broker_url_or_ip', - 'user' : '_your_mqtt_broker_username_', - 'pass' : '_your_mqtt_broker_password_' - } diff --git a/PyPortal/pyportal_pet_planter/code.py b/PyPortal/pyportal_pet_planter/code.py index e0dfaa66c..96b66ce75 100755 --- a/PyPortal/pyportal_pet_planter/code.py +++ b/PyPortal/pyportal_pet_planter/code.py @@ -2,7 +2,7 @@ # # SPDX-License-Identifier: MIT -import os +from os import getenv import time import board @@ -21,6 +21,21 @@ from adafruit_seesaw.seesaw import Seesaw from simpleio import map_range +# 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." + ) + #---| User Config |--------------- # How often to poll the soil sensor, in seconds @@ -52,11 +67,6 @@ # the current working directory (where this file is) cwd = ("/"+__file__).rsplit('/', 1)[0] -secrets = { - "ssid" : os.getenv("CIRCUITPY_WIFI_SSID"), - "password" : os.getenv("CIRCUITPY_WIFI_PASSWORD"), -} - # Set up i2c bus i2c_bus = busio.I2C(board.SCL, board.SDA) @@ -70,8 +80,8 @@ 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) # Initialize PyPortal Display display = board.DISPLAY @@ -190,8 +200,8 @@ # Initialize a new MQTT Client object mqtt_client = MQTT.MQTT(broker="io.adafruit.com", - username=os.getenv("AIO_USERNAME"), - password=os.getenv("AIO_KEY"), + username=aio_username, + password=aio_key, socket_pool=pool, ssl_context=ssl_context) diff --git a/PyPortal/pyportal_weather_station/code.py b/PyPortal/pyportal_weather_station/code.py index bba8cc2b5..b697fda17 100755 --- a/PyPortal/pyportal_weather_station/code.py +++ b/PyPortal/pyportal_weather_station/code.py @@ -10,6 +10,8 @@ Author: Brent Rubell for Adafruit Industries, 2019 """ + +from os import getenv import time import board import neopixel @@ -38,12 +40,20 @@ min_wind_speed = 0.0 max_wind_speed = 32.4 -# 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) @@ -51,14 +61,8 @@ 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) From f9a414ddbc6b60e3fec113ca0311701da4b87785 Mon Sep 17 00:00:00 2001 From: Justin Myers Date: Wed, 9 Apr 2025 11:14:47 -0700 Subject: [PATCH 2/2] Secrets Cleanup: P Part 2 - fix typos celcius to celsius --- CLUE/CLUE_Servo_Barometer/code.py | 6 +++--- GemmaM0_Headband/code.py | 2 +- PicoW_CircuitPython_HTTP_Server/code.py | 2 +- PyPortal/PyPortal_Alarm_Clock/code.py | 4 ++-- 4 files changed, 7 insertions(+), 7 deletions(-) diff --git a/CLUE/CLUE_Servo_Barometer/code.py b/CLUE/CLUE_Servo_Barometer/code.py index f616f6ccf..1bea67d92 100644 --- a/CLUE/CLUE_Servo_Barometer/code.py +++ b/CLUE/CLUE_Servo_Barometer/code.py @@ -58,7 +58,7 @@ display.root_group = group -# function to convert celcius to fahrenheit +# function to convert celsius to fahrenheit def c_to_f(temp): temp_f = (temp * 9/5) + 32 return temp_f @@ -87,12 +87,12 @@ def hpa_to_inHg(hPa): print(servo_value) # if metric units... if metric_units: - # update temp & pressure text in celcius and hPa + # update temp & pressure text in celsius and hPa temp_data.text = "%0.1f ÂșC" % bmp280.temperature press_data.text = "%0.1f hPa" % bmp280.pressure # if imperial units... else: - # convert celcius to fahrenheit + # convert celsius to fahrenheit temp_fahrenheit = c_to_f(bmp280.temperature) # convert hPa to inHg pressure_inHg = hpa_to_inHg(bmp280.pressure) diff --git a/GemmaM0_Headband/code.py b/GemmaM0_Headband/code.py index 25dda30d8..d87a61757 100644 --- a/GemmaM0_Headband/code.py +++ b/GemmaM0_Headband/code.py @@ -23,7 +23,7 @@ # For the Gemma M0 onboard DotStar LED dotstar = adafruit_dotstar.DotStar(board.APA102_SCK, board.APA102_MOSI, 1) -def deg_f(deg_c): # Convert Celcius to Fahrenheit +def deg_f(deg_c): # Convert celsius to Fahrenheit return(deg_c * 9 / 5) + 32.0 while True: diff --git a/PicoW_CircuitPython_HTTP_Server/code.py b/PicoW_CircuitPython_HTTP_Server/code.py index 76c721c8b..746270e2d 100644 --- a/PicoW_CircuitPython_HTTP_Server/code.py +++ b/PicoW_CircuitPython_HTTP_Server/code.py @@ -37,7 +37,7 @@ # scan for temp sensor ds18 = DS18X20(ow_bus, ow_bus.scan()[0]) -# function to convert celcius to fahrenheit +# function to convert celsius to fahrenheit def c_to_f(temp): temp_f = (temp * 9/5) + 32 return temp_f diff --git a/PyPortal/PyPortal_Alarm_Clock/code.py b/PyPortal/PyPortal_Alarm_Clock/code.py index 4b0c191d8..b5aa9aeb3 100644 --- a/PyPortal/PyPortal_Alarm_Clock/code.py +++ b/PyPortal/PyPortal_Alarm_Clock/code.py @@ -85,7 +85,7 @@ icon_file = None icon_sprite = None -celcius = getenv('celcius') +celsius = getenv('celsius') # display/data refresh timers @@ -294,7 +294,7 @@ def tick(self, now): self.weather_icon.append(icon_sprite) temperature = weather['main']['temp'] - 273.15 # its...in kelvin - if celcius: + if celsius: temperature_text = '%3d C' % round(temperature) else: temperature_text = '%3d F' % round(((temperature * 9 / 5) + 32))