Skip to content

Commit ef00664

Browse files
authored
Merge pull request #3014 from justmobilize/secrets-cleanup-p-part2
Secrets Cleanup: P Part 2
2 parents 86686fa + f9a414d commit ef00664

File tree

35 files changed

+356
-272
lines changed

35 files changed

+356
-272
lines changed

CLUE/CLUE_Servo_Barometer/code.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@
5858

5959
display.root_group = group
6060

61-
# function to convert celcius to fahrenheit
61+
# function to convert celsius to fahrenheit
6262
def c_to_f(temp):
6363
temp_f = (temp * 9/5) + 32
6464
return temp_f
@@ -87,12 +87,12 @@ def hpa_to_inHg(hPa):
8787
print(servo_value)
8888
# if metric units...
8989
if metric_units:
90-
# update temp & pressure text in celcius and hPa
90+
# update temp & pressure text in celsius and hPa
9191
temp_data.text = "%0.1f ºC" % bmp280.temperature
9292
press_data.text = "%0.1f hPa" % bmp280.pressure
9393
# if imperial units...
9494
else:
95-
# convert celcius to fahrenheit
95+
# convert celsius to fahrenheit
9696
temp_fahrenheit = c_to_f(bmp280.temperature)
9797
# convert hPa to inHg
9898
pressure_inHg = hpa_to_inHg(bmp280.pressure)

GemmaM0_Headband/code.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@
2323
# For the Gemma M0 onboard DotStar LED
2424
dotstar = adafruit_dotstar.DotStar(board.APA102_SCK, board.APA102_MOSI, 1)
2525

26-
def deg_f(deg_c): # Convert Celcius to Fahrenheit
26+
def deg_f(deg_c): # Convert celsius to Fahrenheit
2727
return(deg_c * 9 / 5) + 32.0
2828

2929
while True:

PicoW_CircuitPython_HTTP_Server/code.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@
3737
# scan for temp sensor
3838
ds18 = DS18X20(ow_bus, ow_bus.scan()[0])
3939

40-
# function to convert celcius to fahrenheit
40+
# function to convert celsius to fahrenheit
4141
def c_to_f(temp):
4242
temp_f = (temp * 9/5) + 32
4343
return temp_f

PyPortal/PyPortal_Alarm_Clock/code.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,7 @@
8585

8686
icon_file = None
8787
icon_sprite = None
88-
celcius = getenv('celcius')
88+
celsius = getenv('celsius')
8989

9090
# display/data refresh timers
9191

@@ -294,7 +294,7 @@ def tick(self, now):
294294
self.weather_icon.append(icon_sprite)
295295

296296
temperature = weather['main']['temp'] - 273.15 # its...in kelvin
297-
if celcius:
297+
if celsius:
298298
temperature_text = '%3d C' % round(temperature)
299299
else:
300300
temperature_text = '%3d F' % round(((temperature * 9 / 5) + 32))

PyPortal/PyPortal_LIFX_Controller/code.py

Lines changed: 16 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,8 @@
99
1010
Brent Rubell for Adafruit Industries, 2019
1111
"""
12-
import os
12+
13+
from os import getenv
1314

1415
import board
1516
import displayio
@@ -26,19 +27,26 @@
2627
# import lifx library
2728
import adafruit_lifx
2829

29-
secrets = {
30-
"ssid" : os.getenv("CIRCUITPY_WIFI_SSID"),
31-
"password" : os.getenv("CIRCUITPY_WIFI_PASSWORD"),
32-
}
30+
# Get WiFi details, ensure these are setup in settings.toml
31+
ssid = getenv("CIRCUITPY_WIFI_SSID")
32+
password = getenv("CIRCUITPY_WIFI_PASSWORD")
33+
34+
if None in [ssid, password]:
35+
raise RuntimeError(
36+
"WiFi settings are kept in settings.toml, "
37+
"please add them there. The settings file must contain "
38+
"'CIRCUITPY_WIFI_SSID', 'CIRCUITPY_WIFI_PASSWORD', "
39+
"at a minimum."
40+
)
3341

3442
# ESP32 SPI
3543
esp32_cs = DigitalInOut(board.ESP_CS)
3644
esp32_ready = DigitalInOut(board.ESP_BUSY)
3745
esp32_reset = DigitalInOut(board.ESP_RESET)
3846
spi = busio.SPI(board.SCK, board.MOSI, board.MISO)
3947
esp = adafruit_esp32spi.ESP_SPIcontrol(spi, esp32_cs, esp32_ready, esp32_reset)
40-
status_light = neopixel.NeoPixel(board.NEOPIXEL, 1, brightness=0.2)
41-
wifi = adafruit_esp32spi_wifimanager.ESPSPI_WiFiManager(esp, secrets, status_light)
48+
status_pixel = neopixel.NeoPixel(board.NEOPIXEL, 1, brightness=0.2)
49+
wifi = adafruit_esp32spi_wifimanager.WiFiManager(esp, ssid, password, status_pixel=status_pixel)
4250

4351
# These pins are used as both analog and digital! XL, XR and YU must be analog
4452
# and digital capable. YD just need to be digital
@@ -49,7 +57,7 @@
4957

5058
# Set this to your LIFX personal access token in settings.toml
5159
# (to obtain a token, visit: https://cloud.lifx.com/settings)
52-
lifx_token = os.getenv("LIFX_TOKEN")
60+
lifx_token = getenv("LIFX_TOKEN")
5361

5462
# Initialize the LIFX API Helper
5563
lifx = adafruit_lifx.LIFX(wifi, lifx_token)

PyPortal/PyPortal_LastFM/code.py

Lines changed: 20 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -7,26 +7,35 @@
77
and display it on a screen
88
If you can find something that spits out JSON data, we can display it!
99
"""
10+
11+
from os import getenv
1012
import time
1113
import board
1214
from adafruit_pyportal import PyPortal
1315

14-
# Get wifi details and more from a secrets.py file
15-
try:
16-
from secrets import secrets
17-
except ImportError:
18-
print("WiFi secrets are kept in secrets.py, please add them there!")
19-
raise
16+
# Get WiFi details, ensure these are setup in settings.toml
17+
ssid = getenv("CIRCUITPY_WIFI_SSID")
18+
password = getenv("CIRCUITPY_WIFI_PASSWORD")
19+
20+
if None in [ssid, password]:
21+
raise RuntimeError(
22+
"WiFi settings are kept in settings.toml, "
23+
"please add them there. The settings file must contain "
24+
"'CIRCUITPY_WIFI_SSID', 'CIRCUITPY_WIFI_PASSWORD', "
25+
"at a minimum."
26+
)
2027

2128
# Set up where we'll be fetching data from
2229
DATA_SOURCE = "http://ws.audioscrobbler.com/2.0/?method=user.getrecenttracks&limit=1&format=json"
2330
CAPTION = "www.last.fm/user"
2431
# If we have an access token, we can query more often
25-
if 'lfm_username' in secrets:
26-
DATA_SOURCE += "&user="+secrets['lfm_username']
27-
CAPTION += "/"+secrets['lfm_username']
28-
if 'lfm_key' in secrets:
29-
DATA_SOURCE += "&api_key="+secrets['lfm_key']
32+
lfm_username = getenv("lfm_username")
33+
lfm_key = getenv("lfm_key")
34+
if lfm_username:
35+
DATA_SOURCE += "&user=" + lfm_username
36+
CAPTION += "/" + lfm_username
37+
if lfm_key:
38+
DATA_SOURCE += "&api_key=" + lfm_key
3039
print(DATA_SOURCE)
3140

3241
# Total number of plays

PyPortal/PyPortal_LeagueLevel/code.py

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,20 +5,33 @@
55
"""
66
This project will access the League of Legends API, grab a Summoner's Level
77
and display it on a screen.
8-
You'll need a Riot API key in your secrets.py file
8+
You'll need a Riot API key in your settings.toml file
99
If you can find something that spits out JSON data, we can display it!
1010
"""
11-
import os
11+
12+
from os import getenv
1213
import time
1314
import board
1415
from adafruit_pyportal import PyPortal
1516

17+
# Get WiFi details, ensure these are setup in settings.toml
18+
ssid = getenv("CIRCUITPY_WIFI_SSID")
19+
password = getenv("CIRCUITPY_WIFI_PASSWORD")
20+
21+
if None in [ssid, password]:
22+
raise RuntimeError(
23+
"WiFi settings are kept in settings.toml, "
24+
"please add them there. The settings file must contain "
25+
"'CIRCUITPY_WIFI_SSID', 'CIRCUITPY_WIFI_PASSWORD', "
26+
"at a minimum."
27+
)
28+
1629
#Choose a valid Summoner name
1730
SUMMONER_NAME = "RiotSchmick"
1831

1932
# Set up where we'll be fetching data from
2033
DATA_SOURCE = "https://na1.api.riotgames.com/lol/summoner/v4/summoners/by-name/"+SUMMONER_NAME
21-
DATA_SOURCE += "?api_key=" + os.getenv("LEAGUE_TOKEN")
34+
DATA_SOURCE += "?api_key=" + getenv("LEAGUE_TOKEN")
2235
DATA_LOCATION = ["summonerLevel"]
2336
CAPTION = "SUMMONER "+SUMMONER_NAME
2437

PyPortal/PyPortal_MQTT_Control/code.py

Lines changed: 18 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
#
33
# SPDX-License-Identifier: MIT
44

5+
from os import getenv
56
import board
67
import displayio
78
import busio
@@ -18,14 +19,19 @@
1819
import adafruit_touchscreen
1920
import adafruit_minimqtt.adafruit_minimqtt as MQTT
2021

21-
# ------------- WiFi ------------- #
22+
# Get WiFi details, ensure these are setup in settings.toml
23+
ssid = getenv("CIRCUITPY_WIFI_SSID")
24+
password = getenv("CIRCUITPY_WIFI_PASSWORD")
25+
26+
if None in [ssid, password]:
27+
raise RuntimeError(
28+
"WiFi settings are kept in settings.toml, "
29+
"please add them there. The settings file must contain "
30+
"'CIRCUITPY_WIFI_SSID', 'CIRCUITPY_WIFI_PASSWORD', "
31+
"at a minimum."
32+
)
2233

23-
# Get wifi details and more from a secrets.py file
24-
try:
25-
from secrets import secrets
26-
except ImportError:
27-
print("WiFi secrets are kept in secrets.py, please add them there!")
28-
raise
34+
# ------------- WiFi ------------- #
2935

3036
# If you are using a board with pre-defined ESP32 Pins:
3137
esp32_cs = DigitalInOut(board.ESP_CS)
@@ -34,8 +40,8 @@
3440

3541
spi = busio.SPI(board.SCK, board.MOSI, board.MISO)
3642
esp = adafruit_esp32spi.ESP_SPIcontrol(spi, esp32_cs, esp32_ready, esp32_reset)
37-
status_light = neopixel.NeoPixel(board.NEOPIXEL, 1, brightness=0.2)
38-
wifi = adafruit_esp32spi_wifimanager.ESPSPI_WiFiManager(esp, secrets, status_light)
43+
status_pixel = neopixel.NeoPixel(board.NEOPIXEL, 1, brightness=0.2)
44+
wifi = adafruit_esp32spi_wifimanager.WiFiManager(esp, ssid, password, status_pixel=status_pixel)
3945

4046
# ------- Sensor Setup ------- #
4147
# init. the temperature sensor
@@ -234,10 +240,10 @@ def message(client, topic, message):
234240

235241
# Set up a MiniMQTT Client
236242
client = MQTT.MQTT(
237-
broker=secrets["broker"],
243+
broker=getenv("mqtt_broker"),
238244
port=1883,
239-
username=secrets["user"],
240-
password=secrets["pass"],
245+
username=getenv("mqtt_username"),
246+
password=getenv("mqtt_password"),
241247
socket_pool=pool,
242248
ssl_context=ssl_context,
243249
)

PyPortal/PyPortal_MQTT_Control/secrets.py

Lines changed: 0 additions & 11 deletions
This file was deleted.
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
# SPDX-FileCopyrightText: 2020 Anne Barela for Adafruit Industries
2+
#
3+
# SPDX-License-Identifier: MIT
4+
5+
# This file is where you keep private settings, passwords, and tokens!
6+
# If you put them in the code you risk committing that info or sharing it
7+
8+
CIRCUITPY_WIFI_SSID="your-wifi-ssid"
9+
CIRCUITPY_WIFI_PASSWORD="your-wifi-password"
10+
mqtt_broker="your-mqtt-broker-url-or-ip"
11+
mqtt_username="your-mqtt-broker-username"
12+
mqtt_password="your-mqtt-broker-password"

0 commit comments

Comments
 (0)