Skip to content

Secrets Cleanup: P Part 2 #3014

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Apr 15, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions CLUE/CLUE_Servo_Barometer/code.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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)
Expand Down
2 changes: 1 addition & 1 deletion GemmaM0_Headband/code.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
2 changes: 1 addition & 1 deletion PicoW_CircuitPython_HTTP_Server/code.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions PyPortal/PyPortal_Alarm_Clock/code.py
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@

icon_file = None
icon_sprite = None
celcius = getenv('celcius')
celsius = getenv('celsius')

# display/data refresh timers

Expand Down Expand Up @@ -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))
Expand Down
24 changes: 16 additions & 8 deletions PyPortal/PyPortal_LIFX_Controller/code.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,8 @@

Brent Rubell for Adafruit Industries, 2019
"""
import os

from os import getenv

import board
import displayio
Expand All @@ -26,19 +27,26 @@
# 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)
esp32_ready = DigitalInOut(board.ESP_BUSY)
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
Expand All @@ -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)
Expand Down
31 changes: 20 additions & 11 deletions PyPortal/PyPortal_LastFM/code.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
19 changes: 16 additions & 3 deletions PyPortal/PyPortal_LeagueLevel/code.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
30 changes: 18 additions & 12 deletions PyPortal/PyPortal_MQTT_Control/code.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
#
# SPDX-License-Identifier: MIT

from os import getenv
import board
import displayio
import busio
Expand All @@ -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)
Expand All @@ -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
Expand Down Expand Up @@ -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,
)
Expand Down
11 changes: 0 additions & 11 deletions PyPortal/PyPortal_MQTT_Control/secrets.py

This file was deleted.

12 changes: 12 additions & 0 deletions PyPortal/PyPortal_MQTT_Control/settings.toml
Original file line number Diff line number Diff line change
@@ -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"
20 changes: 13 additions & 7 deletions PyPortal/PyPortal_Mirror_Display/code.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
#
# SPDX-License-Identifier: MIT

from os import getenv
import sys
import time
import board
Expand All @@ -11,20 +12,25 @@
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"
LOCATION = "New York, US"

# 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 = []

Expand Down
21 changes: 14 additions & 7 deletions PyPortal/PyPortal_OpenWeather/code.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -15,20 +17,25 @@
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"
LOCATION = "Manhattan, US"

# 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 = []

Expand Down
Loading