Secrets Cleanup Q-W
This commit is contained in:
parent
071c95b5b7
commit
2642e48856
25 changed files with 308 additions and 191 deletions
|
|
@ -1 +0,0 @@
|
||||||
Minesweep/code.py 200: Simplify chained comparison between the operands (chained-comparison)
|
|
||||||
|
Before Width: | Height: | Size: 2.2 KiB After Width: | Height: | Size: 2.2 KiB |
|
|
@ -201,7 +201,7 @@ def play_a_game():
|
||||||
set_data(touch_x, touch_y, BOMBDEATH) #reveal a red bomb
|
set_data(touch_x, touch_y, BOMBDEATH) #reveal a red bomb
|
||||||
tilegrid[touch_x, touch_y] = BOMBDEATH
|
tilegrid[touch_x, touch_y] = BOMBDEATH
|
||||||
return False #lost
|
return False #lost
|
||||||
elif under_the_tile > OPEN0 and under_the_tile <= OPEN8:
|
elif OPEN0 < under_the_tile <= OPEN8:
|
||||||
tilegrid[touch_x, touch_y] = under_the_tile
|
tilegrid[touch_x, touch_y] = under_the_tile
|
||||||
elif under_the_tile == OPEN0:
|
elif under_the_tile == OPEN0:
|
||||||
tilegrid[touch_x, touch_y] = BLANK
|
tilegrid[touch_x, touch_y] = BLANK
|
||||||
|
|
@ -17,16 +17,23 @@ All text above must be included in any redistribution.
|
||||||
"""
|
"""
|
||||||
|
|
||||||
#pylint:disable=invalid-name
|
#pylint:disable=invalid-name
|
||||||
|
|
||||||
|
from os import getenv
|
||||||
import time
|
import time
|
||||||
import board
|
import board
|
||||||
from adafruit_pyportal import PyPortal
|
from adafruit_pyportal import PyPortal
|
||||||
|
|
||||||
try:
|
# Get WiFi details, ensure these are setup in settings.toml
|
||||||
from secrets import secrets
|
ssid = getenv("CIRCUITPY_WIFI_SSID")
|
||||||
except ImportError:
|
password = getenv("CIRCUITPY_WIFI_PASSWORD")
|
||||||
print("""WiFi settings are kept in secrets.py, please add them there!
|
|
||||||
the secrets dictionary must contain 'ssid' and 'password' at a minimum""")
|
if None in [ssid, password]:
|
||||||
raise
|
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 this to the username you'd like to display tweets from
|
# Set this to the username you'd like to display tweets from
|
||||||
username = 'codewisdom'
|
username = 'codewisdom'
|
||||||
|
|
@ -53,7 +60,7 @@ pyportal = PyPortal(url=url,
|
||||||
caption_color=0x808080)
|
caption_color=0x808080)
|
||||||
|
|
||||||
# Set OAuth2.0 Bearer Token
|
# Set OAuth2.0 Bearer Token
|
||||||
bearer_token = secrets['twitter_bearer_token']
|
bearer_token = getenv('twitter_bearer_token')
|
||||||
pyportal.set_headers({'Authorization': 'Bearer ' + bearer_token})
|
pyportal.set_headers({'Authorization': 'Bearer ' + bearer_token})
|
||||||
|
|
||||||
while True:
|
while True:
|
||||||
|
Before Width: | Height: | Size: 225 KiB After Width: | Height: | Size: 225 KiB |
|
|
@ -2,6 +2,7 @@
|
||||||
#
|
#
|
||||||
# SPDX-License-Identifier: MIT
|
# SPDX-License-Identifier: MIT
|
||||||
|
|
||||||
|
from os import getenv
|
||||||
import time
|
import time
|
||||||
import ssl
|
import ssl
|
||||||
import board
|
import board
|
||||||
|
|
@ -22,26 +23,26 @@ NEO_PIN = board.SCK # neopixel pin
|
||||||
NEO_CNT = 12 # neopixel count
|
NEO_CNT = 12 # neopixel count
|
||||||
# -------------------------------------------------
|
# -------------------------------------------------
|
||||||
|
|
||||||
|
# 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")
|
||||||
|
|
||||||
# Set up NeoPixels
|
# Set up NeoPixels
|
||||||
pixels = neopixel.NeoPixel(NEO_PIN, NEO_CNT)
|
pixels = neopixel.NeoPixel(NEO_PIN, NEO_CNT)
|
||||||
|
|
||||||
# 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
|
|
||||||
|
|
||||||
# Setup AIO time query URL
|
# Setup AIO time query URL
|
||||||
TIME_URL = "https://io.adafruit.com/api/v2/"
|
TIME_URL = "https://io.adafruit.com/api/v2/"
|
||||||
TIME_URL += secrets["aio_username"]
|
TIME_URL += aio_username
|
||||||
TIME_URL += "/integrations/time/strftime?x-aio-key="
|
TIME_URL += "/integrations/time/strftime?x-aio-key="
|
||||||
TIME_URL += secrets["aio_key"]
|
TIME_URL += aio_key
|
||||||
TIME_URL += "&fmt=%25Y%3A%25m%3A%25d%3A%25H%3A%25M%3A%25S"
|
TIME_URL += "&fmt=%25Y%3A%25m%3A%25d%3A%25H%3A%25M%3A%25S"
|
||||||
|
|
||||||
# Connect to local network
|
# Connect to local network
|
||||||
try:
|
try:
|
||||||
wifi.radio.connect(secrets["ssid"], secrets["password"])
|
wifi.radio.connect(ssid, password)
|
||||||
except ConnectionError:
|
except ConnectionError:
|
||||||
print("Wifi failed to connect.")
|
print("Wifi failed to connect.")
|
||||||
while True:
|
while True:
|
||||||
|
|
|
||||||
|
|
@ -2,6 +2,7 @@
|
||||||
#
|
#
|
||||||
# SPDX-License-Identifier: MIT
|
# SPDX-License-Identifier: MIT
|
||||||
|
|
||||||
|
from os import getenv
|
||||||
import time
|
import time
|
||||||
import board
|
import board
|
||||||
import rtc
|
import rtc
|
||||||
|
|
@ -25,16 +26,13 @@ NEO_CNT = 12 # neopixel count
|
||||||
# Set up NeoPixels
|
# Set up NeoPixels
|
||||||
pixels = neopixel.NeoPixel(NEO_PIN, NEO_CNT)
|
pixels = neopixel.NeoPixel(NEO_PIN, NEO_CNT)
|
||||||
|
|
||||||
# Get wifi details and more from a secrets.py file
|
# Get WiFi details, ensure these are setup in settings.toml
|
||||||
try:
|
ssid = getenv("CIRCUITPY_WIFI_SSID")
|
||||||
from secrets import secrets
|
password = getenv("CIRCUITPY_WIFI_PASSWORD")
|
||||||
except ImportError:
|
|
||||||
print("WiFi secrets are kept in secrets.py, please add them there!")
|
|
||||||
raise
|
|
||||||
|
|
||||||
# Connect to local network
|
# Connect to local network
|
||||||
try:
|
try:
|
||||||
wifi.radio.connect(secrets["ssid"], secrets["password"])
|
wifi.radio.connect(ssid, password)
|
||||||
except ConnectionError:
|
except ConnectionError:
|
||||||
print("Wifi failed to connect.")
|
print("Wifi failed to connect.")
|
||||||
while True:
|
while True:
|
||||||
|
|
|
||||||
|
|
@ -1,7 +1,8 @@
|
||||||
# SPDX-FileCopyrightText: 2022 Charlyn Gonda for Adafruit Industries
|
# SPDX-FileCopyrightText: 2022 Charlyn Gonda for Adafruit Industries
|
||||||
#
|
#
|
||||||
# SPDX-License-Identifier: MIT
|
# SPDX-License-Identifier: MIT
|
||||||
from secrets import secrets
|
|
||||||
|
from os import getenv
|
||||||
import ssl
|
import ssl
|
||||||
import busio
|
import busio
|
||||||
import board
|
import board
|
||||||
|
|
@ -16,6 +17,21 @@ from adafruit_io.adafruit_io import IO_HTTP
|
||||||
|
|
||||||
from cube import Cube
|
from cube import Cube
|
||||||
|
|
||||||
|
# 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."
|
||||||
|
)
|
||||||
|
|
||||||
# Specify pins
|
# Specify pins
|
||||||
top_cin = board.A0
|
top_cin = board.A0
|
||||||
top_din = board.A1
|
top_din = board.A1
|
||||||
|
|
@ -42,9 +58,9 @@ lis3dh = adafruit_lis3dh.LIS3DH_I2C(i2c)
|
||||||
connected = False
|
connected = False
|
||||||
while not connected:
|
while not connected:
|
||||||
try:
|
try:
|
||||||
wifi.radio.connect(secrets["ssid"], secrets["password"])
|
wifi.radio.connect(ssid, password)
|
||||||
print("Connected to %s!" % secrets["ssid"])
|
print(f"Connected to {ssid}!")
|
||||||
print("My IP address is", wifi.radio.ipv4_address)
|
print(f"My IP address is {wifi.radio.ipv4_address}")
|
||||||
connected = True
|
connected = True
|
||||||
# pylint: disable=broad-except
|
# pylint: disable=broad-except
|
||||||
except Exception as error:
|
except Exception as error:
|
||||||
|
|
@ -54,8 +70,8 @@ while not connected:
|
||||||
|
|
||||||
# Setup for http requests
|
# Setup for http requests
|
||||||
pool = socketpool.SocketPool(wifi.radio)
|
pool = socketpool.SocketPool(wifi.radio)
|
||||||
REQUESTS = adafruit_requests.Session(pool, ssl.create_default_context())
|
requests = adafruit_requests.Session(pool, ssl.create_default_context())
|
||||||
IO = IO_HTTP(secrets["aio_username"], secrets["aio_key"], REQUESTS)
|
IO = IO_HTTP(aio_username, aio_key, requests)
|
||||||
|
|
||||||
# Data for top pixels, will be updated by update_data()
|
# Data for top pixels, will be updated by update_data()
|
||||||
TOP_PIXELS_ON = []
|
TOP_PIXELS_ON = []
|
||||||
|
|
|
||||||
|
|
@ -1,6 +1,7 @@
|
||||||
# SPDX-FileCopyrightText: 2022 Liz Clark for Adafruit Industries
|
# SPDX-FileCopyrightText: 2022 Liz Clark for Adafruit Industries
|
||||||
# SPDX-License-Identifier: MIT
|
# SPDX-License-Identifier: MIT
|
||||||
|
|
||||||
|
from os import getenv
|
||||||
import json
|
import json
|
||||||
import time
|
import time
|
||||||
import digitalio
|
import digitalio
|
||||||
|
|
@ -17,18 +18,23 @@ import adafruit_ntp
|
||||||
from adafruit_display_text import bitmap_label, wrap_text_to_lines
|
from adafruit_display_text import bitmap_label, wrap_text_to_lines
|
||||||
from adafruit_bitmap_font import bitmap_font
|
from adafruit_bitmap_font import bitmap_font
|
||||||
from adafruit_azureiot import IoTHubDevice
|
from adafruit_azureiot import IoTHubDevice
|
||||||
import adafruit_bme680
|
|
||||||
from adafruit_lc709203f import LC709203F, PackSize
|
from adafruit_lc709203f import LC709203F, PackSize
|
||||||
|
import adafruit_bme680
|
||||||
|
|
||||||
# Get wifi details and more from a secrets.py file
|
# Get WiFi details, ensure these are setup in settings.toml
|
||||||
try:
|
ssid = getenv("CIRCUITPY_WIFI_SSID")
|
||||||
from secrets import secrets
|
password = getenv("CIRCUITPY_WIFI_PASSWORD")
|
||||||
except ImportError:
|
|
||||||
print("WiFi secrets are kept in secrets.py, please add them there!")
|
if None in [ssid, password]:
|
||||||
raise
|
raise RuntimeError(
|
||||||
|
"WiFi settings are kept in settings.toml, "
|
||||||
|
"please add them there. The settings file must contain "
|
||||||
|
"'CIRCUITPY_WIFI_SSID', 'CIRCUITPY_WIFI_PASSWORD', "
|
||||||
|
"at a minimum."
|
||||||
|
)
|
||||||
|
|
||||||
print("Connecting to WiFi...")
|
print("Connecting to WiFi...")
|
||||||
wifi.radio.connect(secrets["ssid"], secrets["password"])
|
wifi.radio.connect(ssid, password)
|
||||||
|
|
||||||
print("Connected to WiFi!")
|
print("Connected to WiFi!")
|
||||||
|
|
||||||
|
|
@ -47,7 +53,7 @@ else:
|
||||||
esp = None
|
esp = None
|
||||||
pool = socketpool.SocketPool(wifi.radio)
|
pool = socketpool.SocketPool(wifi.radio)
|
||||||
# Create an IoT Hub device client and connect
|
# Create an IoT Hub device client and connect
|
||||||
device = IoTHubDevice(pool, esp, secrets["device_connection_string"])
|
device = IoTHubDevice(pool, esp, getenv("device_connection_string"))
|
||||||
|
|
||||||
print("Connecting to Azure IoT Hub...")
|
print("Connecting to Azure IoT Hub...")
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -1,6 +1,7 @@
|
||||||
# SPDX-FileCopyrightText: 2022 Liz Clark for Adafruit Industries
|
# SPDX-FileCopyrightText: 2022 Liz Clark for Adafruit Industries
|
||||||
# SPDX-License-Identifier: MIT
|
# SPDX-License-Identifier: MIT
|
||||||
|
|
||||||
|
from os import getenv
|
||||||
import time
|
import time
|
||||||
import json
|
import json
|
||||||
import digitalio
|
import digitalio
|
||||||
|
|
@ -13,15 +14,20 @@ import adafruit_ntp
|
||||||
from adafruit_azureiot import IoTHubDevice
|
from adafruit_azureiot import IoTHubDevice
|
||||||
import adafruit_scd4x
|
import adafruit_scd4x
|
||||||
|
|
||||||
# Get wifi details and more from a secrets.py file
|
# Get WiFi details, ensure these are setup in settings.toml
|
||||||
try:
|
ssid = getenv("CIRCUITPY_WIFI_SSID")
|
||||||
from secrets import secrets
|
password = getenv("CIRCUITPY_WIFI_PASSWORD")
|
||||||
except ImportError:
|
|
||||||
print("WiFi secrets are kept in secrets.py, please add them there!")
|
if None in [ssid, password]:
|
||||||
raise
|
raise RuntimeError(
|
||||||
|
"WiFi settings are kept in settings.toml, "
|
||||||
|
"please add them there. The settings file must contain "
|
||||||
|
"'CIRCUITPY_WIFI_SSID', 'CIRCUITPY_WIFI_PASSWORD', "
|
||||||
|
"at a minimum."
|
||||||
|
)
|
||||||
|
|
||||||
print("Connecting to WiFi...")
|
print("Connecting to WiFi...")
|
||||||
wifi.radio.connect(secrets["ssid"], secrets["password"])
|
wifi.radio.connect(ssid, password)
|
||||||
|
|
||||||
print("Connected to WiFi!")
|
print("Connected to WiFi!")
|
||||||
|
|
||||||
|
|
@ -40,7 +46,7 @@ else:
|
||||||
esp = None
|
esp = None
|
||||||
pool = socketpool.SocketPool(wifi.radio)
|
pool = socketpool.SocketPool(wifi.radio)
|
||||||
# Create an IoT Hub device client and connect
|
# Create an IoT Hub device client and connect
|
||||||
device = IoTHubDevice(pool, esp, secrets["device_connection_string"])
|
device = IoTHubDevice(pool, esp, getenv("device_connection_string"))
|
||||||
|
|
||||||
print("Connecting to Azure IoT Hub...")
|
print("Connecting to Azure IoT Hub...")
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -5,12 +5,14 @@
|
||||||
"""
|
"""
|
||||||
Clock & sky colorbox for Adafruit MagTag: displays current time while
|
Clock & sky colorbox for Adafruit MagTag: displays current time while
|
||||||
NeoPixels provide theme lighting for the time of day. Requires WiFi
|
NeoPixels provide theme lighting for the time of day. Requires WiFi
|
||||||
internet access -- configure credentials in secrets.py. An Adafruit IO
|
internet access -- configure credentials in settings.toml. An Adafruit IO
|
||||||
user name and API key are also needed there, plus timezone and
|
user name and API key are also needed there, plus timezone and
|
||||||
geographic coords.
|
geographic coords.
|
||||||
"""
|
"""
|
||||||
|
|
||||||
# pylint: disable=import-error
|
# pylint: disable=import-error
|
||||||
|
|
||||||
|
from os import getenv
|
||||||
import time
|
import time
|
||||||
import json
|
import json
|
||||||
import board
|
import board
|
||||||
|
|
@ -18,12 +20,20 @@ import neopixel
|
||||||
from adafruit_magtag.magtag import MagTag
|
from adafruit_magtag.magtag import MagTag
|
||||||
import adafruit_fancyled.adafruit_fancyled as fancy
|
import adafruit_fancyled.adafruit_fancyled as fancy
|
||||||
|
|
||||||
# UTC offset queries require some info from the secrets table...
|
# Get WiFi details and Adafruit IO keys, ensure these are setup in settings.toml
|
||||||
try:
|
# (visit io.adafruit.com if you need to create an account, or if you need your Adafruit IO key.)
|
||||||
from secrets import secrets
|
ssid = getenv("CIRCUITPY_WIFI_SSID")
|
||||||
except ImportError:
|
password = getenv("CIRCUITPY_WIFI_PASSWORD")
|
||||||
print('Please set up secrets.py with network credentials.')
|
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."
|
||||||
|
)
|
||||||
|
|
||||||
# CONFIGURABLE SETTINGS ----------------------------------------------------
|
# CONFIGURABLE SETTINGS ----------------------------------------------------
|
||||||
|
|
||||||
|
|
@ -179,16 +189,13 @@ while True:
|
||||||
# Since time is synced only once per hour, the extra request
|
# Since time is synced only once per hour, the extra request
|
||||||
# isn't particularly burdensome.
|
# isn't particularly burdensome.
|
||||||
try:
|
try:
|
||||||
RESPONSE = MAGTAG.network.requests.get(
|
url = f"https://io.adafruit.com/api/v2/{aio_username}/integrations/time/strftime"
|
||||||
'https://io.adafruit.com/api/v2/%s/integrations/time/'
|
url += f'x-aio-key={aio_key}tz={getenv("timezone")}&fmt=%25z'
|
||||||
'strftime?x-aio-key=%s&tz=%s' % (secrets.get('aio_username'),
|
response = MAGTAG.network.requests.get(url)
|
||||||
secrets.get('aio_key'),
|
if response.status_code == 200:
|
||||||
secrets.get('timezone')) +
|
|
||||||
'&fmt=%25z')
|
|
||||||
if RESPONSE.status_code == 200:
|
|
||||||
# Arrives as sHHMM, convert to sHH:MM
|
# Arrives as sHHMM, convert to sHH:MM
|
||||||
print(RESPONSE.text)
|
print(response.text)
|
||||||
UTC_OFFSET = RESPONSE.text[:3] + ':' + RESPONSE.text[-2:]
|
UTC_OFFSET = response.text[:3] + ':' + response.text[-2:]
|
||||||
except: # pylint: disable=bare-except
|
except: # pylint: disable=bare-except
|
||||||
# If query fails, prior value is kept until next query.
|
# If query fails, prior value is kept until next query.
|
||||||
# Only changes 2X a year anyway -- worst case, if these
|
# Only changes 2X a year anyway -- worst case, if these
|
||||||
|
|
@ -217,7 +224,7 @@ while True:
|
||||||
try:
|
try:
|
||||||
URL = ('https://api.met.no/weatherapi/sunrise/2.0/.json?'
|
URL = ('https://api.met.no/weatherapi/sunrise/2.0/.json?'
|
||||||
'lat=%s&lon=%s&date=%s-%s-%s&offset=%s' %
|
'lat=%s&lon=%s&date=%s-%s-%s&offset=%s' %
|
||||||
(secrets.get('latitude'), secrets.get('longitude'),
|
(getenv('latitude'), getenv('longitude'),
|
||||||
str(NOW.tm_year), '{0:0>2}'.format(NOW.tm_mon),
|
str(NOW.tm_year), '{0:0>2}'.format(NOW.tm_mon),
|
||||||
'{0:0>2}'.format(NOW.tm_mday), UTC_OFFSET))
|
'{0:0>2}'.format(NOW.tm_mday), UTC_OFFSET))
|
||||||
print('Fetching sun data via', URL)
|
print('Fetching sun data via', URL)
|
||||||
|
|
|
||||||
|
|
@ -1,6 +1,7 @@
|
||||||
# SPDX-FileCopyrightText: 2021 Eva Herrada for Adafruit Industries
|
# SPDX-FileCopyrightText: 2021 Eva Herrada for Adafruit Industries
|
||||||
# SPDX-License-Identifier: MIT
|
# SPDX-License-Identifier: MIT
|
||||||
|
|
||||||
|
from os import getenv
|
||||||
import ssl
|
import ssl
|
||||||
import time
|
import time
|
||||||
import board
|
import board
|
||||||
|
|
@ -17,19 +18,28 @@ btn1 = digitalio.DigitalInOut(board.IO9)
|
||||||
btn1.direction = digitalio.Direction.INPUT
|
btn1.direction = digitalio.Direction.INPUT
|
||||||
btn1.pull = digitalio.Pull.DOWN
|
btn1.pull = digitalio.Pull.DOWN
|
||||||
|
|
||||||
|
# Get WiFi details and Adafruit IO keys, ensure these are setup in settings.toml
|
||||||
|
# (visit io.adafruit.com if you need to create an account, or if you need your Adafruit IO key.)
|
||||||
|
ssid = getenv("CIRCUITPY_WIFI_SSID")
|
||||||
|
password = getenv("CIRCUITPY_WIFI_PASSWORD")
|
||||||
|
aio_username = getenv("ADAFRUIT_AIO_USERNAME")
|
||||||
|
aio_key = getenv("ADAFRUIT_AIO_KEY")
|
||||||
|
|
||||||
|
if None in [ssid, password, aio_username, aio_key]:
|
||||||
|
raise RuntimeError(
|
||||||
|
"WiFi and Adafruit IO settings are kept in settings.toml, "
|
||||||
|
"please add them there. The settings file must contain "
|
||||||
|
"'CIRCUITPY_WIFI_SSID', 'CIRCUITPY_WIFI_PASSWORD', "
|
||||||
|
"'ADAFRUIT_AIO_USERNAME' and 'ADAFRUIT_AIO_KEY' at a minimum."
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
ALARM = None
|
ALARM = None
|
||||||
### WiFi ###
|
### WiFi ###
|
||||||
|
|
||||||
# Get wifi details and more from a secrets.py file
|
print(f"Connecting to {ssid}")
|
||||||
try:
|
wifi.radio.connect(ssid, password)
|
||||||
from secrets import secrets
|
print(f"Connected to {ssid}!")
|
||||||
except ImportError:
|
|
||||||
print("WiFi secrets are kept in secrets.py, please add them there!")
|
|
||||||
raise
|
|
||||||
|
|
||||||
print("Connecting to %s" % secrets["ssid"])
|
|
||||||
wifi.radio.connect(secrets["ssid"], secrets["password"])
|
|
||||||
print("Connected to %s!" % secrets["ssid"])
|
|
||||||
|
|
||||||
# Define callback functions which will be called when certain events happen.
|
# Define callback functions which will be called when certain events happen.
|
||||||
# pylint: disable=unused-argument
|
# pylint: disable=unused-argument
|
||||||
|
|
@ -78,8 +88,8 @@ pool = socketpool.SocketPool(wifi.radio)
|
||||||
# Initialize a new MQTT Client object
|
# Initialize a new MQTT Client object
|
||||||
mqtt_client = MQTT.MQTT(
|
mqtt_client = MQTT.MQTT(
|
||||||
broker="io.adafruit.com",
|
broker="io.adafruit.com",
|
||||||
username=secrets["aio_username"],
|
username=aio_username,
|
||||||
password=secrets["aio_key"],
|
password=aio_key,
|
||||||
socket_pool=pool,
|
socket_pool=pool,
|
||||||
ssl_context=ssl.create_default_context(),
|
ssl_context=ssl.create_default_context(),
|
||||||
)
|
)
|
||||||
|
|
|
||||||
|
|
@ -2,6 +2,8 @@
|
||||||
# SPDX-License-Identifier: MIT
|
# SPDX-License-Identifier: MIT
|
||||||
|
|
||||||
# General imports
|
# General imports
|
||||||
|
|
||||||
|
from os import getenv
|
||||||
import gc
|
import gc
|
||||||
import time
|
import time
|
||||||
import math
|
import math
|
||||||
|
|
@ -35,6 +37,22 @@ import adafruit_minimqtt.adafruit_minimqtt as MQTT
|
||||||
import audiocore
|
import audiocore
|
||||||
import audiobusio
|
import audiobusio
|
||||||
|
|
||||||
|
# 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."
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
TIMES = {}
|
TIMES = {}
|
||||||
ENABLED = {}
|
ENABLED = {}
|
||||||
|
|
||||||
|
|
@ -59,21 +77,9 @@ days = {
|
||||||
6: "sunday",
|
6: "sunday",
|
||||||
}
|
}
|
||||||
|
|
||||||
try:
|
print(f"Connecting to {ssid}")
|
||||||
from secrets import secrets
|
wifi.radio.connect(ssid, password)
|
||||||
except ImportError:
|
print(f"Connected to {ssid}!")
|
||||||
print("WiFi secrets are kept in secrets.py, please add them there!")
|
|
||||||
raise
|
|
||||||
|
|
||||||
# Set your Adafruit IO Username and Key in secrets.py
|
|
||||||
# (visit io.adafruit.com if you need to create an account,
|
|
||||||
# or if you need your Adafruit IO key.)
|
|
||||||
aio_username = secrets["aio_username"]
|
|
||||||
aio_key = secrets["aio_key"]
|
|
||||||
|
|
||||||
print("Connecting to %s" % secrets["ssid"])
|
|
||||||
wifi.radio.connect(secrets["ssid"], secrets["password"])
|
|
||||||
print("Connected to %s!" % secrets["ssid"])
|
|
||||||
|
|
||||||
# Define callback functions which will be called when certain events happen.
|
# Define callback functions which will be called when certain events happen.
|
||||||
# pylint: disable=unused-argument
|
# pylint: disable=unused-argument
|
||||||
|
|
@ -97,7 +103,7 @@ def connected(client, userdata, flags, rc):
|
||||||
"alarm",
|
"alarm",
|
||||||
]
|
]
|
||||||
for feed in feeds:
|
for feed in feeds:
|
||||||
feed_slug = secrets["aio_username"] + "/feeds/alarm-clock." + feed
|
feed_slug = f"{aio_username}/feeds/alarm-clock." + feed
|
||||||
print("Subscribed to: alarm-clock." + feed)
|
print("Subscribed to: alarm-clock." + feed)
|
||||||
client.subscribe(feed_slug, 1)
|
client.subscribe(feed_slug, 1)
|
||||||
|
|
||||||
|
|
@ -126,7 +132,7 @@ def fade(warm_val, cool_val):
|
||||||
|
|
||||||
|
|
||||||
def get(feed_key):
|
def get(feed_key):
|
||||||
mqtt_client.publish(f'{secrets["aio_username"]}/feeds/{feed_key}/get', "\0")
|
mqtt_client.publish(f'{aio_username}/feeds/{feed_key}/get', "\0")
|
||||||
time.sleep(0.1)
|
time.sleep(0.1)
|
||||||
|
|
||||||
|
|
||||||
|
|
@ -169,7 +175,7 @@ def on_iso(client, feed_id, payload):
|
||||||
and WAIT < time.monotonic()
|
and WAIT < time.monotonic()
|
||||||
):
|
):
|
||||||
mqtt_client.publish(
|
mqtt_client.publish(
|
||||||
f"{secrets['aio_username']}/feeds/alarm-clock.alarm", "True"
|
f"{aio_username}/feeds/alarm-clock.alarm", "True"
|
||||||
)
|
)
|
||||||
get("alarm-clock.alarm")
|
get("alarm-clock.alarm")
|
||||||
gc.collect()
|
gc.collect()
|
||||||
|
|
@ -314,8 +320,8 @@ pool = socketpool.SocketPool(wifi.radio)
|
||||||
# Initialize a new MQTT Client object
|
# Initialize a new MQTT Client object
|
||||||
mqtt_client = MQTT.MQTT(
|
mqtt_client = MQTT.MQTT(
|
||||||
broker="io.adafruit.com",
|
broker="io.adafruit.com",
|
||||||
username=secrets["aio_username"],
|
username=aio_username,
|
||||||
password=secrets["aio_key"],
|
password=aio_key,
|
||||||
socket_pool=pool,
|
socket_pool=pool,
|
||||||
ssl_context=ssl.create_default_context(),
|
ssl_context=ssl.create_default_context(),
|
||||||
)
|
)
|
||||||
|
|
@ -331,51 +337,51 @@ mqtt_client.connect()
|
||||||
mqtt_client.add_topic_callback("time/ISO-8601", on_iso)
|
mqtt_client.add_topic_callback("time/ISO-8601", on_iso)
|
||||||
|
|
||||||
mqtt_client.add_topic_callback(
|
mqtt_client.add_topic_callback(
|
||||||
secrets["aio_username"] + "/feeds/alarm-clock.alarm", on_alarm
|
f"{aio_username}/feeds/alarm-clock.alarm", on_alarm
|
||||||
)
|
)
|
||||||
|
|
||||||
mqtt_client.add_topic_callback(
|
mqtt_client.add_topic_callback(
|
||||||
secrets["aio_username"] + "/feeds/alarm-clock.sunday", on_time
|
f"{aio_username}/feeds/alarm-clock.sunday", on_time
|
||||||
)
|
)
|
||||||
mqtt_client.add_topic_callback(
|
mqtt_client.add_topic_callback(
|
||||||
secrets["aio_username"] + "/feeds/alarm-clock.monday", on_time
|
f"{aio_username}/feeds/alarm-clock.monday", on_time
|
||||||
)
|
)
|
||||||
mqtt_client.add_topic_callback(
|
mqtt_client.add_topic_callback(
|
||||||
secrets["aio_username"] + "/feeds/alarm-clock.tuesday", on_time
|
f"{aio_username}/feeds/alarm-clock.tuesday", on_time
|
||||||
)
|
)
|
||||||
mqtt_client.add_topic_callback(
|
mqtt_client.add_topic_callback(
|
||||||
secrets["aio_username"] + "/feeds/alarm-clock.wednesday", on_time
|
f"{aio_username}/feeds/alarm-clock.wednesday", on_time
|
||||||
)
|
)
|
||||||
mqtt_client.add_topic_callback(
|
mqtt_client.add_topic_callback(
|
||||||
secrets["aio_username"] + "/feeds/alarm-clock.thursday", on_time
|
f"{aio_username}/feeds/alarm-clock.thursday", on_time
|
||||||
)
|
)
|
||||||
mqtt_client.add_topic_callback(
|
mqtt_client.add_topic_callback(
|
||||||
secrets["aio_username"] + "/feeds/alarm-clock.friday", on_time
|
f"{aio_username}/feeds/alarm-clock.friday", on_time
|
||||||
)
|
)
|
||||||
mqtt_client.add_topic_callback(
|
mqtt_client.add_topic_callback(
|
||||||
secrets["aio_username"] + "/feeds/alarm-clock.saturday", on_time
|
f"{aio_username}/feeds/alarm-clock.saturday", on_time
|
||||||
)
|
)
|
||||||
|
|
||||||
mqtt_client.add_topic_callback(
|
mqtt_client.add_topic_callback(
|
||||||
secrets["aio_username"] + "/feeds/alarm-clock.sunday-enable", on_enable
|
f"{aio_username}/feeds/alarm-clock.sunday-enable", on_enable
|
||||||
)
|
)
|
||||||
mqtt_client.add_topic_callback(
|
mqtt_client.add_topic_callback(
|
||||||
secrets["aio_username"] + "/feeds/alarm-clock.monday-enable", on_enable
|
f"{aio_username}/feeds/alarm-clock.monday-enable", on_enable
|
||||||
)
|
)
|
||||||
mqtt_client.add_topic_callback(
|
mqtt_client.add_topic_callback(
|
||||||
secrets["aio_username"] + "/feeds/alarm-clock.tuesday-enable", on_enable
|
f"{aio_username}/feeds/alarm-clock.tuesday-enable", on_enable
|
||||||
)
|
)
|
||||||
mqtt_client.add_topic_callback(
|
mqtt_client.add_topic_callback(
|
||||||
secrets["aio_username"] + "/feeds/alarm-clock.wednesday-enable", on_enable
|
f"{aio_username}/feeds/alarm-clock.wednesday-enable", on_enable
|
||||||
)
|
)
|
||||||
mqtt_client.add_topic_callback(
|
mqtt_client.add_topic_callback(
|
||||||
secrets["aio_username"] + "/feeds/alarm-clock.thursday-enable", on_enable
|
f"{aio_username}/feeds/alarm-clock.thursday-enable", on_enable
|
||||||
)
|
)
|
||||||
mqtt_client.add_topic_callback(
|
mqtt_client.add_topic_callback(
|
||||||
secrets["aio_username"] + "/feeds/alarm-clock.friday-enable", on_enable
|
f"{aio_username}/feeds/alarm-clock.friday-enable", on_enable
|
||||||
)
|
)
|
||||||
mqtt_client.add_topic_callback(
|
mqtt_client.add_topic_callback(
|
||||||
secrets["aio_username"] + "/feeds/alarm-clock.saturday-enable", on_enable
|
f"{aio_username}/feeds/alarm-clock.saturday-enable", on_enable
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
|
|
@ -398,7 +404,7 @@ get("alarm-clock.saturday-enable")
|
||||||
while len(TIMES) < 7 or len(ENABLED) < 7:
|
while len(TIMES) < 7 or len(ENABLED) < 7:
|
||||||
mqtt_client.loop()
|
mqtt_client.loop()
|
||||||
|
|
||||||
mqtt_client.publish(secrets["aio_username"] + "/feeds/alarm-clock.alarm", "False")
|
mqtt_client.publish(f"{aio_username}/feeds/alarm-clock.alarm", "False")
|
||||||
mqtt_client.subscribe("time/ISO-8601", 1)
|
mqtt_client.subscribe("time/ISO-8601", 1)
|
||||||
|
|
||||||
print("Starting")
|
print("Starting")
|
||||||
|
|
|
||||||
|
|
@ -8,7 +8,8 @@ Feather ESP32-S3 or S2 + TFT Featherwing 3.5" 480x320 pixels
|
||||||
Receive and display messages from the spirits.
|
Receive and display messages from the spirits.
|
||||||
"""
|
"""
|
||||||
# pylint: disable=import-error, invalid-name
|
# pylint: disable=import-error, invalid-name
|
||||||
import os
|
|
||||||
|
from os import getenv
|
||||||
import displayio
|
import displayio
|
||||||
import fourwire
|
import fourwire
|
||||||
import board
|
import board
|
||||||
|
|
@ -22,6 +23,20 @@ import adafruit_tsc2007
|
||||||
|
|
||||||
from spirit_board import SpiritBoard
|
from spirit_board import SpiritBoard
|
||||||
|
|
||||||
|
# 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."
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
# 3.5" TFT Featherwing is 480x320
|
# 3.5" TFT Featherwing is 480x320
|
||||||
|
|
@ -49,12 +64,6 @@ try:
|
||||||
ssl_context = adafruit_connection_manager.get_radio_ssl_context(wifi.radio)
|
ssl_context = adafruit_connection_manager.get_radio_ssl_context(wifi.radio)
|
||||||
requests = adafruit_requests.Session(pool, ssl_context)
|
requests = adafruit_requests.Session(pool, ssl_context)
|
||||||
|
|
||||||
# Set your Adafruit IO Username and Key in secrets.py
|
|
||||||
# (visit io.adafruit.com if you need to create an account,
|
|
||||||
# or if you need your Adafruit IO key.)
|
|
||||||
aio_username = os.getenv("AIO_USERNAME")
|
|
||||||
aio_key = os.getenv("AIO_KEY")
|
|
||||||
|
|
||||||
# Initialize an Adafruit IO HTTP API object
|
# Initialize an Adafruit IO HTTP API object
|
||||||
io = IO_HTTP(aio_username, aio_key, requests)
|
io = IO_HTTP(aio_username, aio_key, requests)
|
||||||
except (RuntimeError, TypeError) as e:
|
except (RuntimeError, TypeError) as e:
|
||||||
|
|
|
||||||
|
|
@ -9,7 +9,7 @@ Receive and display messages from the spirits.
|
||||||
"""
|
"""
|
||||||
# pylint: disable=import-error, invalid-name
|
# pylint: disable=import-error, invalid-name
|
||||||
|
|
||||||
import os
|
from os import getenv
|
||||||
import board
|
import board
|
||||||
from digitalio import DigitalInOut
|
from digitalio import DigitalInOut
|
||||||
import adafruit_connection_manager
|
import adafruit_connection_manager
|
||||||
|
|
@ -22,6 +22,21 @@ from spirit_board import SpiritBoard
|
||||||
|
|
||||||
display = board.DISPLAY
|
display = board.DISPLAY
|
||||||
|
|
||||||
|
# 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."
|
||||||
|
)
|
||||||
|
|
||||||
# Initialize the touch overlay
|
# Initialize the touch overlay
|
||||||
touchscreen = adafruit_touchscreen.Touchscreen(
|
touchscreen = adafruit_touchscreen.Touchscreen(
|
||||||
board.TOUCH_XL,
|
board.TOUCH_XL,
|
||||||
|
|
@ -43,19 +58,13 @@ esp = adafruit_esp32spi.ESP_SPIcontrol(spi, esp32_cs, esp32_ready, esp32_reset)
|
||||||
print("Connecting to AP...")
|
print("Connecting to AP...")
|
||||||
|
|
||||||
try:
|
try:
|
||||||
esp.connect_AP(os.getenv("CIRCUITPY_WIFI_SSID"), os.getenv("CIRCUITPY_WIFI_PASSWORD"))
|
esp.connect_AP(ssid, password)
|
||||||
|
|
||||||
# Initialize a requests session
|
# Initialize a requests session
|
||||||
pool = adafruit_connection_manager.get_radio_socketpool(esp)
|
pool = adafruit_connection_manager.get_radio_socketpool(esp)
|
||||||
ssl_context = adafruit_connection_manager.get_radio_ssl_context(esp)
|
ssl_context = adafruit_connection_manager.get_radio_ssl_context(esp)
|
||||||
requests = adafruit_requests.Session(pool, ssl_context)
|
requests = adafruit_requests.Session(pool, ssl_context)
|
||||||
|
|
||||||
# Set your Adafruit IO Username and Key in secrets.py
|
|
||||||
# (visit io.adafruit.com if you need to create an account,
|
|
||||||
# or if you need your Adafruit IO key.)
|
|
||||||
aio_username = os.getenv("AIO_USERNAME")
|
|
||||||
aio_key = os.getenv("AIO_KEY")
|
|
||||||
|
|
||||||
# Initialize an Adafruit IO HTTP API object
|
# Initialize an Adafruit IO HTTP API object
|
||||||
io = IO_HTTP(aio_username, aio_key, requests)
|
io = IO_HTTP(aio_username, aio_key, requests)
|
||||||
except (RuntimeError, TypeError) as e:
|
except (RuntimeError, TypeError) as e:
|
||||||
|
|
|
||||||
|
|
@ -9,7 +9,7 @@ Receive and display messages from the spirits.
|
||||||
"""
|
"""
|
||||||
# pylint: disable=import-error, invalid-name
|
# pylint: disable=import-error, invalid-name
|
||||||
|
|
||||||
import os
|
from os import getenv
|
||||||
import board
|
import board
|
||||||
from digitalio import DigitalInOut
|
from digitalio import DigitalInOut
|
||||||
import adafruit_connection_manager
|
import adafruit_connection_manager
|
||||||
|
|
@ -22,6 +22,21 @@ from spirit_board import SpiritBoard
|
||||||
|
|
||||||
display = board.DISPLAY
|
display = board.DISPLAY
|
||||||
|
|
||||||
|
# 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."
|
||||||
|
)
|
||||||
|
|
||||||
# Initialize the touch overlay
|
# Initialize the touch overlay
|
||||||
touchscreen = adafruit_touchscreen.Touchscreen(
|
touchscreen = adafruit_touchscreen.Touchscreen(
|
||||||
board.TOUCH_XL,
|
board.TOUCH_XL,
|
||||||
|
|
@ -43,19 +58,13 @@ esp = adafruit_esp32spi.ESP_SPIcontrol(spi, esp32_cs, esp32_ready, esp32_reset)
|
||||||
print("Connecting to AP...")
|
print("Connecting to AP...")
|
||||||
|
|
||||||
try:
|
try:
|
||||||
esp.connect_AP(os.getenv("CIRCUITPY_WIFI_SSID"), os.getenv("CIRCUITPY_WIFI_PASSWORD"))
|
esp.connect_AP(ssid, password)
|
||||||
|
|
||||||
# Initialize a requests session
|
# Initialize a requests session
|
||||||
pool = adafruit_connection_manager.get_radio_socketpool(esp)
|
pool = adafruit_connection_manager.get_radio_socketpool(esp)
|
||||||
ssl_context = adafruit_connection_manager.get_radio_ssl_context(esp)
|
ssl_context = adafruit_connection_manager.get_radio_ssl_context(esp)
|
||||||
requests = adafruit_requests.Session(pool, ssl_context)
|
requests = adafruit_requests.Session(pool, ssl_context)
|
||||||
|
|
||||||
# Set your Adafruit IO Username and Key in secrets.py
|
|
||||||
# (visit io.adafruit.com if you need to create an account,
|
|
||||||
# or if you need your Adafruit IO key.)
|
|
||||||
aio_username = os.getenv("AIO_USERNAME")
|
|
||||||
aio_key = os.getenv("AIO_KEY")
|
|
||||||
|
|
||||||
# Initialize an Adafruit IO HTTP API object
|
# Initialize an Adafruit IO HTTP API object
|
||||||
io = IO_HTTP(aio_username, aio_key, requests)
|
io = IO_HTTP(aio_username, aio_key, requests)
|
||||||
except (RuntimeError, TypeError) as e:
|
except (RuntimeError, TypeError) as e:
|
||||||
|
|
|
||||||
|
|
@ -1,6 +1,7 @@
|
||||||
# SPDX-FileCopyrightText: 2022 Liz Clark for Adafruit Industries
|
# SPDX-FileCopyrightText: 2022 Liz Clark for Adafruit Industries
|
||||||
# SPDX-License-Identifier: MIT
|
# SPDX-License-Identifier: MIT
|
||||||
|
|
||||||
|
from os import getenv
|
||||||
import time
|
import time
|
||||||
import ssl
|
import ssl
|
||||||
import board
|
import board
|
||||||
|
|
@ -14,6 +15,21 @@ from adafruit_io.adafruit_io import IO_HTTP, AdafruitIO_RequestError
|
||||||
from simpleio import map_range
|
from simpleio import map_range
|
||||||
from adafruit_motor import servo
|
from adafruit_motor import servo
|
||||||
|
|
||||||
|
# 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."
|
||||||
|
)
|
||||||
|
|
||||||
# select which display is running the code
|
# select which display is running the code
|
||||||
servo_one = True
|
servo_one = True
|
||||||
# servo_two = True
|
# servo_two = True
|
||||||
|
|
@ -22,18 +38,9 @@ servo_one = True
|
||||||
ANGLE_MIN = 0
|
ANGLE_MIN = 0
|
||||||
ANGLE_MAX = 180
|
ANGLE_MAX = 180
|
||||||
|
|
||||||
try:
|
print(f"Connecting to {ssid}")
|
||||||
from secrets import secrets
|
wifi.radio.connect(ssid, password)
|
||||||
except ImportError:
|
print(f"Connected to {ssid}!")
|
||||||
print("WiFi secrets are kept in secrets.py, please add them there!")
|
|
||||||
raise
|
|
||||||
# connect to adafruitio
|
|
||||||
aio_username = secrets["aio_username"]
|
|
||||||
aio_key = secrets["aio_key"]
|
|
||||||
|
|
||||||
print("Connecting to %s" % secrets["ssid"])
|
|
||||||
wifi.radio.connect(secrets["ssid"], secrets["password"])
|
|
||||||
print("Connected to %s!" % secrets["ssid"])
|
|
||||||
|
|
||||||
pool = socketpool.SocketPool(wifi.radio)
|
pool = socketpool.SocketPool(wifi.radio)
|
||||||
requests = adafruit_requests.Session(pool, ssl.create_default_context())
|
requests = adafruit_requests.Session(pool, ssl.create_default_context())
|
||||||
|
|
|
||||||
|
|
@ -1 +0,0 @@
|
||||||
Weather_Display_Matrix/weather_display_matrix.py 71: Consider merging these comparisons with "in" to "UNITS in ('imperial', 'metric')" (consider-using-in)
|
|
||||||
|
|
@ -10,6 +10,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!
|
weather for your location... and display it on a screen!
|
||||||
if you can find something that spits out JSON data, we can display it
|
if you can find something that spits out JSON data, we can display it
|
||||||
"""
|
"""
|
||||||
|
|
||||||
|
from os import getenv
|
||||||
import time
|
import time
|
||||||
import board
|
import board
|
||||||
import microcontroller
|
import microcontroller
|
||||||
|
|
@ -18,12 +20,17 @@ from adafruit_matrixportal.network import Network
|
||||||
from adafruit_matrixportal.matrix import Matrix
|
from adafruit_matrixportal.matrix import Matrix
|
||||||
import openweather_graphics # pylint: disable=wrong-import-position
|
import openweather_graphics # pylint: disable=wrong-import-position
|
||||||
|
|
||||||
# Get wifi details and more from a secrets.py file
|
# Get WiFi details, ensure these are setup in settings.toml
|
||||||
try:
|
ssid = getenv("CIRCUITPY_WIFI_SSID")
|
||||||
from secrets import secrets
|
password = getenv("CIRCUITPY_WIFI_PASSWORD")
|
||||||
except ImportError:
|
|
||||||
print("WiFi secrets are kept in secrets.py, please add them there!")
|
if None in [ssid, password]:
|
||||||
raise
|
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."
|
||||||
|
)
|
||||||
|
|
||||||
if hasattr(board, "D12"):
|
if hasattr(board, "D12"):
|
||||||
jumper = DigitalInOut(board.D12)
|
jumper = DigitalInOut(board.D12)
|
||||||
|
|
@ -62,10 +69,10 @@ print("Getting weather for {}".format(LOCATION))
|
||||||
DATA_SOURCE = (
|
DATA_SOURCE = (
|
||||||
"http://api.openweathermap.org/data/2.5/weather?q=" + LOCATION + "&units=" + UNITS
|
"http://api.openweathermap.org/data/2.5/weather?q=" + LOCATION + "&units=" + UNITS
|
||||||
)
|
)
|
||||||
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'
|
# You'll need to get a token from openweather.org, looks like 'b6907d289e10d714a6e88b30761fae22'
|
||||||
# it goes in your secrets.py file on a line such as:
|
# it goes in your settings.toml file on a line such as:
|
||||||
# 'openweather_token' : 'your_big_humongous_gigantor_token',
|
# 'openweather_token="your_big_humongous_gigantor_token"',
|
||||||
DATA_LOCATION = []
|
DATA_LOCATION = []
|
||||||
SCROLL_HOLD_TIME = 0 # set this to hold each line before finishing scroll
|
SCROLL_HOLD_TIME = 0 # set this to hold each line before finishing scroll
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -1,6 +1,7 @@
|
||||||
# SPDX-FileCopyrightText: 2021 Eva Herrada for Adafruit Industries
|
# SPDX-FileCopyrightText: 2021 Eva Herrada for Adafruit Industries
|
||||||
# SPDX-License-Identifier: MIT
|
# SPDX-License-Identifier: MIT
|
||||||
|
|
||||||
|
from os import getenv
|
||||||
import time
|
import time
|
||||||
|
|
||||||
import board
|
import board
|
||||||
|
|
@ -14,6 +15,21 @@ from adafruit_io.adafruit_io import IO_MQTT
|
||||||
from adafruit_seesaw.seesaw import Seesaw
|
from adafruit_seesaw.seesaw import Seesaw
|
||||||
import busio
|
import busio
|
||||||
|
|
||||||
|
# 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."
|
||||||
|
)
|
||||||
|
|
||||||
# Used to make sure that the Adafruit IO Trigger is only run once when the moisture value is below
|
# Used to make sure that the Adafruit IO Trigger is only run once when the moisture value is below
|
||||||
# the desired threshold, set in MIN
|
# the desired threshold, set in MIN
|
||||||
LOW = False
|
LOW = False
|
||||||
|
|
@ -28,13 +44,6 @@ i2c = board.I2C() # uses board.SCL and board.SDA
|
||||||
# i2c = board.STEMMA_I2C() # For using the built-in STEMMA QT connector on a microcontroller
|
# i2c = board.STEMMA_I2C() # For using the built-in STEMMA QT connector on a microcontroller
|
||||||
seesaw = Seesaw(i2c, addr=0x36)
|
seesaw = Seesaw(i2c, addr=0x36)
|
||||||
|
|
||||||
# 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
|
|
||||||
|
|
||||||
# Set up WiFi
|
# Set up WiFi
|
||||||
esp32_cs = DigitalInOut(board.D13)
|
esp32_cs = DigitalInOut(board.D13)
|
||||||
esp32_ready = DigitalInOut(board.D11)
|
esp32_ready = DigitalInOut(board.D11)
|
||||||
|
|
@ -42,8 +51,8 @@ esp32_reset = DigitalInOut(board.D12)
|
||||||
|
|
||||||
spi = busio.SPI(board.SCK, board.MOSI, board.MISO)
|
spi = busio.SPI(board.SCK, board.MOSI, board.MISO)
|
||||||
esp = adafruit_esp32spi.ESP_SPIcontrol(spi, esp32_cs, esp32_ready, esp32_reset)
|
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)
|
||||||
|
|
||||||
# Define callback functions which will be called when certain events happen.
|
# Define callback functions which will be called when certain events happen.
|
||||||
# pylint: disable=unused-argument
|
# pylint: disable=unused-argument
|
||||||
|
|
@ -73,8 +82,8 @@ ssl_context = adafruit_connection_manager.get_radio_ssl_context(esp)
|
||||||
# Initialize a new MQTT Client object
|
# Initialize a new MQTT Client object
|
||||||
mqtt_client = MQTT.MQTT(
|
mqtt_client = MQTT.MQTT(
|
||||||
broker="io.adafruit.com",
|
broker="io.adafruit.com",
|
||||||
username=secrets["aio_username"],
|
username=aio_username,
|
||||||
password=secrets["aio_key"],
|
password=aio_key,
|
||||||
socket_pool=pool,
|
socket_pool=pool,
|
||||||
ssl_context=ssl_context,
|
ssl_context=ssl_context,
|
||||||
)
|
)
|
||||||
|
|
|
||||||
|
|
@ -4,6 +4,7 @@
|
||||||
|
|
||||||
"""CircuitPython WiFi Mailbox Notifier"""
|
"""CircuitPython WiFi Mailbox Notifier"""
|
||||||
|
|
||||||
|
from os import getenv
|
||||||
import time
|
import time
|
||||||
import ssl
|
import ssl
|
||||||
import alarm
|
import alarm
|
||||||
|
|
@ -17,12 +18,20 @@ import microcontroller
|
||||||
import adafruit_requests
|
import adafruit_requests
|
||||||
from adafruit_io.adafruit_io import IO_HTTP
|
from adafruit_io.adafruit_io import IO_HTTP
|
||||||
|
|
||||||
# Get WiFi/Adafruit IO details from secrets.py
|
# Get WiFi details and Adafruit IO keys, ensure these are setup in settings.toml
|
||||||
try:
|
# (visit io.adafruit.com if you need to create an account, or if you need your Adafruit IO key.)
|
||||||
from secrets import secrets
|
ssid = getenv("CIRCUITPY_WIFI_SSID")
|
||||||
except ImportError:
|
password = getenv("CIRCUITPY_WIFI_PASSWORD")
|
||||||
print("Please create secrets.py and add your WiFi and AIO credentials there!")
|
aio_username = getenv("ADAFRUIT_AIO_USERNAME")
|
||||||
raise
|
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."
|
||||||
|
)
|
||||||
|
|
||||||
# Update to True if you want metadata sent to Adafruit IO. Defaults to False.
|
# Update to True if you want metadata sent to Adafruit IO. Defaults to False.
|
||||||
METADATA = False
|
METADATA = False
|
||||||
|
|
@ -81,9 +90,9 @@ def send_io_data(feed_name, value):
|
||||||
|
|
||||||
# Connect to WiFi
|
# Connect to WiFi
|
||||||
try:
|
try:
|
||||||
wifi.radio.connect(secrets["ssid"], secrets["password"])
|
wifi.radio.connect(ssid, password)
|
||||||
print("Connected to {}!".format(secrets["ssid"]))
|
print(f"Connected to {ssid}!")
|
||||||
print("IP:", wifi.radio.ipv4_address)
|
print(f"IP: {wifi.radio.ipv4_address}")
|
||||||
|
|
||||||
pool = socketpool.SocketPool(wifi.radio)
|
pool = socketpool.SocketPool(wifi.radio)
|
||||||
requests = adafruit_requests.Session(pool, ssl.create_default_context())
|
requests = adafruit_requests.Session(pool, ssl.create_default_context())
|
||||||
|
|
@ -94,9 +103,6 @@ except Exception as error: # pylint: disable=broad-except
|
||||||
time.sleep(15)
|
time.sleep(15)
|
||||||
supervisor.reload()
|
supervisor.reload()
|
||||||
|
|
||||||
# Pull your Adafruit IO username and key from secrets.py
|
|
||||||
aio_username = secrets["aio_username"]
|
|
||||||
aio_key = secrets["aio_key"]
|
|
||||||
# Initialize an Adafruit IO HTTP API object
|
# Initialize an Adafruit IO HTTP API object
|
||||||
io = IO_HTTP(aio_username, aio_key, requests)
|
io = IO_HTTP(aio_username, aio_key, requests)
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -2,6 +2,7 @@
|
||||||
#
|
#
|
||||||
# SPDX-License-Identifier: MIT
|
# SPDX-License-Identifier: MIT
|
||||||
|
|
||||||
|
from os import getenv
|
||||||
import ipaddress
|
import ipaddress
|
||||||
import wifi
|
import wifi
|
||||||
import socketpool
|
import socketpool
|
||||||
|
|
@ -10,12 +11,17 @@ import simpleio
|
||||||
import adafruit_tsc2007
|
import adafruit_tsc2007
|
||||||
import adafruit_adxl34x
|
import adafruit_adxl34x
|
||||||
|
|
||||||
# Get wifi details and host IP from a secrets.py file
|
# Get WiFi details, ensure these are setup in settings.toml
|
||||||
try:
|
ssid = getenv("CIRCUITPY_WIFI_SSID")
|
||||||
from secrets import secrets
|
password = getenv("CIRCUITPY_WIFI_PASSWORD")
|
||||||
except ImportError:
|
|
||||||
print("WiFi secrets are kept in secrets.py, please add them there!")
|
if None in [ssid, password]:
|
||||||
raise
|
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."
|
||||||
|
)
|
||||||
|
|
||||||
# I2C setup for STEMMA port
|
# I2C setup for STEMMA port
|
||||||
i2c = board.STEMMA_I2C()
|
i2c = board.STEMMA_I2C()
|
||||||
|
|
@ -56,16 +62,16 @@ last_tap = False
|
||||||
new_val = False
|
new_val = False
|
||||||
|
|
||||||
# URLs to fetch from
|
# URLs to fetch from
|
||||||
HOST = secrets["host"]
|
HOST = getenv("host")
|
||||||
PORT = 12345
|
PORT = 12345
|
||||||
TIMEOUT = 5
|
TIMEOUT = 5
|
||||||
INTERVAL = 5
|
INTERVAL = 5
|
||||||
MAXBUF = 256
|
MAXBUF = 256
|
||||||
|
|
||||||
# connect to WIFI
|
# connect to WIFI
|
||||||
print("Connecting to %s"%secrets["ssid"])
|
print(f"Connecting to {ssid}")
|
||||||
wifi.radio.connect(secrets["ssid"], secrets["password"])
|
wifi.radio.connect(ssid, password)
|
||||||
print("Connected to %s!"%secrets["ssid"])
|
print(f"Connected to {ssid}!")
|
||||||
|
|
||||||
pool = socketpool.SocketPool(wifi.radio)
|
pool = socketpool.SocketPool(wifi.radio)
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue