Merge pull request #3014 from justmobilize/secrets-cleanup-p-part2

Secrets Cleanup: P Part 2
This commit is contained in:
foamyguy 2025-04-15 10:17:18 -05:00 committed by GitHub
commit ef00664e14
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
35 changed files with 356 additions and 272 deletions

View file

@ -58,7 +58,7 @@ group.append(press_data)
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 @@ while True:
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)

View file

@ -23,7 +23,7 @@ pixels = neopixel.NeoPixel(board.D1, # NeoPixels on pin D1
# 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:

View file

@ -37,7 +37,7 @@ ow_bus = OneWireBus(board.GP6)
# 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

View file

@ -85,7 +85,7 @@ mugsy_background = 'mugsy_background.bmp'
icon_file = None
icon_sprite = None
celcius = getenv('celcius')
celsius = getenv('celsius')
# display/data refresh timers
@ -294,7 +294,7 @@ class Time_State(State):
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))

View file

@ -9,7 +9,8 @@ https://learn.adafruit.com/pyportal-smart-lighting-controller
Brent Rubell for Adafruit Industries, 2019
"""
import os
from os import getenv
import board
import displayio
@ -26,10 +27,17 @@ from adafruit_esp32spi import adafruit_esp32spi_wifimanager
# 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_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
@ -49,7 +57,7 @@ ts = adafruit_touchscreen.Touchscreen(board.TOUCH_XL, board.TOUCH_XR,
# 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)

View file

@ -7,26 +7,35 @@ This example will access the lastFM API, grab a number like subreddit followers
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

View file

@ -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

View file

@ -2,6 +2,7 @@
#
# SPDX-License-Identifier: MIT
from os import getenv
import board
import displayio
import busio
@ -18,14 +19,19 @@ from adafruit_button import Button
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")
# 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 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."
)
# ------------- WiFi ------------- #
# If you are using a board with pre-defined ESP32 Pins:
esp32_cs = DigitalInOut(board.ESP_CS)
@ -34,8 +40,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)
# ------- Sensor Setup ------- #
# init. the temperature sensor
@ -234,10 +240,10 @@ ssl_context = adafruit_connection_manager.get_radio_ssl_context(esp)
# 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,
)

View file

@ -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_'
}

View file

@ -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"

View file

@ -2,6 +2,7 @@
#
# SPDX-License-Identifier: MIT
from os import getenv
import sys
import time
import board
@ -11,12 +12,17 @@ cwd = ("/"+__file__).rsplit('/', 1)[0] # the current working directory (where th
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 @@ 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 = []

View file

@ -7,6 +7,8 @@ This example queries the Open Weather Maps site API to find out the current
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 @@ cwd = ("/"+__file__).rsplit('/', 1)[0] # the current working directory (where th
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 @@ 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 = []

View file

@ -7,7 +7,8 @@ PyPortal Philips Hue Lighting Controller
Brent Rubell for Adafruit Industries, 2019
"""
import os
from os import getenv
import board
import displayio
@ -23,9 +24,17 @@ from adafruit_esp32spi import adafruit_esp32spi_wifimanager
# 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_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)
# 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

View file

@ -2,6 +2,7 @@
#
# SPDX-License-Identifier: MIT
from os import getenv
import time
import board
import busio
@ -13,12 +14,17 @@ from adafruit_pyportal import PyPortal
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 @@ if esp.status == adafruit_esp32spi.WL_IDLE_STATUS:
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 @@ while True:
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()

View file

@ -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 displayio
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 @@ ts = adafruit_touchscreen.Touchscreen(
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 @@ 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)
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"

View file

@ -2,6 +2,7 @@
#
# SPDX-License-Identifier: MIT
from os import getenv
import time
import gc
import board
@ -20,6 +21,21 @@ import adafruit_touchscreen
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 @@ class Clock(object):
# 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 @@ class Clock(object):
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 @@ for ap in esp.scan_networks():
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 @@ print("Connected to", str(esp.ssid, 'utf-8'), "\tRSSI:", esp.rssi)
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)

View file

@ -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',
}

View file

@ -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

View file

@ -10,6 +10,8 @@ thermometer with Adafruit IO
Author: Brent Rubell for Adafruit Industries, 2019
"""
from os import getenv
import time
import board
import neopixel
@ -27,12 +29,20 @@ import thermometer_helper
# 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_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)
# 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')

View file

@ -36,12 +36,11 @@ ALWAYS_ON = True
# 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 @@ mono_time = int(time.monotonic())
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 @@ splash.append(progress_bar)
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 @@ while ALWAYS_ON or (countdown > 0):
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 @@ while ALWAYS_ON or (countdown > 0):
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)

View file

@ -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")]
}

View file

@ -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"),
]

View file

@ -2,6 +2,7 @@
#
# SPDX-License-Identifier: MIT
from os import getenv
import time
import json
import board
@ -9,12 +10,17 @@ from adafruit_pyportal import PyPortal
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 @@ DATA_LOCATION = []
# 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")

View file

@ -2,6 +2,7 @@
#
# SPDX-License-Identifier: MIT
from os import getenv
import time
import json
import board
@ -10,12 +11,17 @@ from adafruit_pyportal import PyPortal
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 @@ else:
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)

View file

@ -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_button import Button
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 = []

View file

@ -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'
}

View file

@ -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"

View file

@ -14,11 +14,11 @@ analogin = AnalogIn(board.LIGHT)
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)

View file

@ -16,6 +16,7 @@ Licensed under the MIT license.
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_shapes.rect import Rect
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 @@ CAPTION_FONT_FILE = cwd+'/fonts/Helvetica-Bold-16.bdf'
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):

View file

@ -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',
}

View file

@ -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"

View file

@ -1 +0,0 @@
PyPortal_User_Interface/code.py 128: Line too long (117/100) (line-too-long)

View file

@ -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_'
}

View file

@ -2,7 +2,7 @@
#
# SPDX-License-Identifier: MIT
import os
from os import getenv
import time
import board
@ -21,6 +21,21 @@ from adafruit_pyportal import PyPortal
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 @@ wav_water_low = "/sounds/water-low.wav"
# 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 @@ 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)
# Initialize PyPortal Display
display = board.DISPLAY
@ -190,8 +200,8 @@ ssl_context = adafruit_connection_manager.get_radio_ssl_context(esp)
# 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)

View file

@ -10,6 +10,8 @@ Adafruit IO
Author: Brent Rubell for Adafruit Industries, 2019
"""
from os import getenv
import time
import board
import neopixel
@ -38,12 +40,20 @@ anemometer_max_volts = 2.0
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_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)
# 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)