Merge pull request #2995 from justmobilize/secrets-cleanup-f-i
Secrets Cleanup: F and I
This commit is contained in:
commit
bedfa656d8
24 changed files with 302 additions and 233 deletions
|
|
@ -1,6 +1,7 @@
|
|||
# SPDX-FileCopyrightText: 2022 Liz Clark for Adafruit Industries
|
||||
# SPDX-License-Identifier: MIT
|
||||
|
||||
from os import getenv
|
||||
import time
|
||||
import json
|
||||
import supervisor
|
||||
|
|
@ -17,20 +18,24 @@ import adafruit_connection_manager
|
|||
from adafruit_display_text import bitmap_label, wrap_text_to_lines
|
||||
from adafruit_bitmap_font import bitmap_font
|
||||
from adafruit_azureiot import IoTCentralDevice
|
||||
import adafruit_bme680
|
||||
import adafruit_max1704x
|
||||
import adafruit_bme680
|
||||
#from adafruit_lc709203f import LC709203F, PackSize
|
||||
|
||||
# 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."
|
||||
)
|
||||
|
||||
print("Connecting to WiFi...")
|
||||
wifi.radio.connect(secrets["ssid"], secrets["password"])
|
||||
wifi.radio.connect(ssid, password)
|
||||
|
||||
print("Connected to WiFi!")
|
||||
|
||||
|
|
@ -75,7 +80,7 @@ minute = cal[4]
|
|||
#
|
||||
# Next create a device using the device template, and select Connect to get the
|
||||
# device connection details.
|
||||
# Add the connection details to your secrets.py file, using the following values:
|
||||
# Add the connection details to your settings.toml file, using the following values:
|
||||
#
|
||||
# 'id_scope' - the devices ID scope
|
||||
# 'device_id' - the devices device id
|
||||
|
|
@ -100,7 +105,7 @@ bme680.sea_level_pressure = 1013.25
|
|||
esp = None
|
||||
pool = socketpool.SocketPool(wifi.radio)
|
||||
device = IoTCentralDevice(
|
||||
pool, ssl_context, secrets["id_scope"], secrets["device_id"], secrets["device_primary_key"]
|
||||
pool, ssl_context, getenv("id_scope"), getenv("device_id"), getenv("device_primary_key")
|
||||
)
|
||||
|
||||
print("Connecting to Azure IoT Central...")
|
||||
|
|
|
|||
|
|
@ -2,6 +2,7 @@
|
|||
#
|
||||
# SPDX-License-Identifier: MIT
|
||||
|
||||
from os import getenv
|
||||
import time
|
||||
import ssl
|
||||
import microcontroller
|
||||
|
|
@ -38,23 +39,26 @@ pir = digitalio.DigitalInOut(board.D6)
|
|||
pir.direction = digitalio.Direction.INPUT
|
||||
motion = Debouncer(pir)
|
||||
|
||||
try:
|
||||
from secrets import secrets
|
||||
except ImportError:
|
||||
print("WiFi and Adafruit IO credentials 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")
|
||||
|
||||
# Add your Adafruit IO Username and Key to secrets.py
|
||||
# (visit io.adafruit.com if you need to create an account,
|
||||
# or if you need to obtain your Adafruit IO key.)
|
||||
aio_username = secrets["aio_username"]
|
||||
aio_key = secrets["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."
|
||||
)
|
||||
|
||||
# WiFi
|
||||
try:
|
||||
print("Connecting to %s" % secrets["ssid"])
|
||||
wifi.radio.connect(secrets["ssid"], secrets["password"])
|
||||
print("Connected to %s!" % secrets["ssid"])
|
||||
print(f"Connecting to {ssid}")
|
||||
wifi.radio.connect(ssid, password)
|
||||
print(f"Connected to {ssid}!")
|
||||
# Wi-Fi connectivity fails with error messages, not specific errors, so this except is broad.
|
||||
except Exception as e: # pylint: disable=broad-except
|
||||
print("Failed to connect to WiFi. Error:", e, "\nBoard will restart in 5 seconds.")
|
||||
|
|
@ -67,8 +71,8 @@ pool = socketpool.SocketPool(wifi.radio)
|
|||
# Initialize a new MQTT Client object
|
||||
mqtt_client = MQTT.MQTT(
|
||||
broker="io.adafruit.com",
|
||||
username=secrets["aio_username"],
|
||||
password=secrets["aio_key"],
|
||||
username=aio_username,
|
||||
password=aio_key,
|
||||
socket_pool=pool,
|
||||
ssl_context=ssl.create_default_context(),
|
||||
)
|
||||
|
|
|
|||
|
|
@ -12,6 +12,7 @@ Uses:
|
|||
Either the Feather or the Airlift Featherwing should have stacking headers for the display.
|
||||
"""
|
||||
|
||||
from os import getenv
|
||||
import time
|
||||
import board
|
||||
from adafruit_lc709203f import LC709203F
|
||||
|
|
@ -30,18 +31,25 @@ import terminalio
|
|||
from adafruit_display_text import label
|
||||
import adafruit_displayio_ssd1306
|
||||
|
||||
# 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."
|
||||
)
|
||||
|
||||
displayio.release_displays()
|
||||
|
||||
### WiFi ###
|
||||
|
||||
# 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.D13)
|
||||
esp32_ready = DigitalInOut(board.D11)
|
||||
|
|
@ -50,10 +58,10 @@ esp32_reset = DigitalInOut(board.D12)
|
|||
spi = busio.SPI(board.SCK, board.MOSI, board.MISO)
|
||||
esp = adafruit_esp32spi.ESP_SPIcontrol(spi, esp32_cs, esp32_ready, esp32_reset)
|
||||
"""Use below for Most Boards"""
|
||||
status_light = neopixel.NeoPixel(
|
||||
status_pixel = neopixel.NeoPixel(
|
||||
board.NEOPIXEL, 1, brightness=0.2
|
||||
) # Uncomment for Most Boards
|
||||
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.
|
||||
# pylint: disable=unused-argument
|
||||
|
|
@ -81,8 +89,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=secrets["aio_username"],
|
||||
password=secrets["aio_key"],
|
||||
username=aio_username,
|
||||
password=aio_key,
|
||||
socket_pool=pool,
|
||||
ssl_context=ssl_context,
|
||||
)
|
||||
|
|
|
|||
|
|
@ -14,6 +14,7 @@ This isn't necessary, but it makes it easier to connect the sensor to the Microc
|
|||
either the Feather or the AirLift Featherwing has stacking headers.
|
||||
"""
|
||||
|
||||
from os import getenv
|
||||
import board
|
||||
import busio
|
||||
import adafruit_connection_manager
|
||||
|
|
@ -25,14 +26,22 @@ from adafruit_io.adafruit_io import IO_MQTT
|
|||
from digitalio import DigitalInOut, Direction, Pull
|
||||
from adafruit_debouncer import Debouncer
|
||||
|
||||
### WiFi ###
|
||||
# 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")
|
||||
|
||||
# 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, 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."
|
||||
)
|
||||
|
||||
### WiFi ###
|
||||
|
||||
switch_pin = DigitalInOut(board.D10)
|
||||
switch_pin.direction = Direction.INPUT
|
||||
|
|
@ -47,10 +56,10 @@ esp32_reset = DigitalInOut(board.D12)
|
|||
spi = busio.SPI(board.SCK, board.MOSI, board.MISO)
|
||||
esp = adafruit_esp32spi.ESP_SPIcontrol(spi, esp32_cs, esp32_ready, esp32_reset)
|
||||
"""Use below for Most Boards"""
|
||||
status_light = neopixel.NeoPixel(
|
||||
status_pixel = neopixel.NeoPixel(
|
||||
board.NEOPIXEL, 1, brightness=0.2
|
||||
) # Uncomment for Most Boards
|
||||
wifi = adafruit_esp32spi_wifimanager.ESPSPI_WiFiManager(esp, secrets, status_light)
|
||||
wifi = adafruit_esp32spi_wifimanager.WiFiManager(esp, ssid, password, status_pixel=status_pixel)
|
||||
|
||||
# Connect to WiFi
|
||||
print("Connecting to WiFi...")
|
||||
|
|
@ -63,8 +72,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=secrets["aio_username"],
|
||||
password=secrets["aio_key"],
|
||||
username=aio_username,
|
||||
password=aio_key,
|
||||
socket_pool=pool,
|
||||
ssl_context=ssl_context,
|
||||
)
|
||||
|
|
|
|||
|
|
@ -1,6 +1,7 @@
|
|||
# SPDX-FileCopyrightText: 2021 Eva Herrada for Adafruit Industries
|
||||
# SPDX-License-Identifier: MIT
|
||||
|
||||
from os import getenv
|
||||
import time
|
||||
import ssl
|
||||
import displayio
|
||||
|
|
@ -15,6 +16,21 @@ import adafruit_minimqtt.adafruit_minimqtt as MQTT
|
|||
from adafruit_io.adafruit_io import IO_MQTT
|
||||
from adafruit_dash_display import Hub
|
||||
|
||||
# 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."
|
||||
)
|
||||
|
||||
# Set up navigation buttons
|
||||
up = DigitalInOut(board.BUTTON_UP)
|
||||
up.direction = Direction.INPUT
|
||||
|
|
@ -31,14 +47,6 @@ down.pull = Pull.DOWN
|
|||
back = touchio.TouchIn(board.CAP7)
|
||||
submit = touchio.TouchIn(board.CAP8)
|
||||
|
||||
# Check for secrets.py. Note: for this project, your secrets.py needs an adafruit io api key as
|
||||
# well as the wifi information
|
||||
try:
|
||||
from secrets import secrets
|
||||
except ImportError:
|
||||
print("WiFi secrets are kept in secrets.py, please add them there!")
|
||||
raise
|
||||
|
||||
# Make the rgb group for setting rgb hex values for NeoPixels
|
||||
rgb_group = displayio.Group()
|
||||
R_label = Label(
|
||||
|
|
@ -174,15 +182,9 @@ def pub_lamp(lamp):
|
|||
|
||||
display = board.DISPLAY
|
||||
|
||||
# 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"])
|
||||
print(f"Connecting to {ssid}")
|
||||
wifi.radio.connect(ssid, password)
|
||||
print(f"Connected to {ssid}!")
|
||||
|
||||
# Create a socket pool
|
||||
pool = socketpool.SocketPool(wifi.radio)
|
||||
|
|
@ -190,8 +192,8 @@ pool = socketpool.SocketPool(wifi.radio)
|
|||
# Initialize a new MQTT Client object
|
||||
mqtt_client = MQTT.MQTT(
|
||||
broker="io.adafruit.com",
|
||||
username=secrets["aio_username"],
|
||||
password=secrets["aio_key"],
|
||||
username=aio_username,
|
||||
password=aio_key,
|
||||
socket_pool=pool,
|
||||
ssl_context=ssl.create_default_context(),
|
||||
)
|
||||
|
|
|
|||
|
|
@ -7,6 +7,7 @@ NeoPixel remote control using PyPortal Titano.
|
|||
Colors used are taken from Adafruit_CircuitPython_LED_Animation library
|
||||
"""
|
||||
|
||||
from os import getenv
|
||||
import time
|
||||
import math
|
||||
import board
|
||||
|
|
@ -26,6 +27,21 @@ import neopixel
|
|||
# Import Adafruit IO HTTP Client
|
||||
from adafruit_io.adafruit_io import IO_HTTP, AdafruitIO_RequestError
|
||||
|
||||
# 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."
|
||||
)
|
||||
|
||||
ts = adafruit_touchscreen.Touchscreen(
|
||||
board.TOUCH_XL,
|
||||
board.TOUCH_XR,
|
||||
|
|
@ -92,30 +108,17 @@ rect = Rect(0, 0, 160, 320, fill=0x000000)
|
|||
group.append(rect)
|
||||
print(len(group))
|
||||
|
||||
# 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
|
||||
|
||||
# PyPortal ESP32 Setup
|
||||
esp32_cs = DigitalInOut(board.ESP_CS)
|
||||
esp32_ready = DigitalInOut(board.ESP_BUSY)
|
||||
esp32_reset = DigitalInOut(board.ESP_RESET)
|
||||
spi = busio.SPI(board.SCK, board.MOSI, board.MISO)
|
||||
esp = adafruit_esp32spi.ESP_SPIcontrol(spi, esp32_cs, esp32_ready, esp32_reset)
|
||||
status_light = neopixel.NeoPixel(board.NEOPIXEL, 1, brightness=0.2)
|
||||
wifi = adafruit_esp32spi_wifimanager.ESPSPI_WiFiManager(esp, secrets, status_light)
|
||||
|
||||
# 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)
|
||||
io = IO_HTTP(aio_username, aio_key, wifi)
|
||||
|
||||
try:
|
||||
# Get the 'temperature' feed from Adafruit IO
|
||||
|
|
|
|||
|
|
@ -15,6 +15,7 @@ If your Feather board has STEMMA QT, you'll need one of these:
|
|||
But if it doesn't, use stacking headers on either the Feather or the AirLift FeatherWing
|
||||
"""
|
||||
|
||||
from os import getenv
|
||||
import board
|
||||
import busio
|
||||
import adafruit_connection_manager
|
||||
|
|
@ -25,14 +26,22 @@ import adafruit_minimqtt.adafruit_minimqtt as MQTT
|
|||
from adafruit_io.adafruit_io import IO_MQTT
|
||||
from digitalio import DigitalInOut
|
||||
|
||||
### WiFi ###
|
||||
# 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")
|
||||
|
||||
# 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, 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."
|
||||
)
|
||||
|
||||
### WiFi ###
|
||||
|
||||
# Change the first number to the pin the data line is plugged in to and the second number
|
||||
# to the number of pixels
|
||||
|
|
@ -46,10 +55,10 @@ esp32_reset = DigitalInOut(board.D12)
|
|||
spi = busio.SPI(board.SCK, board.MOSI, board.MISO)
|
||||
esp = adafruit_esp32spi.ESP_SPIcontrol(spi, esp32_cs, esp32_ready, esp32_reset)
|
||||
"""Use below for Most Boards"""
|
||||
status_light = neopixel.NeoPixel(
|
||||
status_pixel = neopixel.NeoPixel(
|
||||
board.NEOPIXEL, 1, brightness=0.2
|
||||
) # Uncomment for Most Boards
|
||||
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.
|
||||
# pylint: disable=unused-argument
|
||||
|
|
@ -82,8 +91,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=secrets["aio_username"],
|
||||
password=secrets["aio_key"],
|
||||
username=aio_username,
|
||||
password=aio_key,
|
||||
socket_pool=pool,
|
||||
ssl_context=ssl_context,
|
||||
)
|
||||
|
|
|
|||
|
|
@ -17,6 +17,7 @@ humidity feel) and turns a relay on or off based on that. This relay could have
|
|||
a box fan connected to it.
|
||||
"""
|
||||
|
||||
from os import getenv
|
||||
import board
|
||||
import busio
|
||||
import adafruit_connection_manager
|
||||
|
|
@ -27,14 +28,22 @@ import adafruit_minimqtt.adafruit_minimqtt as MQTT
|
|||
from adafruit_io.adafruit_io import IO_MQTT
|
||||
from digitalio import DigitalInOut, Direction
|
||||
|
||||
### WiFi ###
|
||||
# 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")
|
||||
|
||||
# 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, 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."
|
||||
)
|
||||
|
||||
### WiFi ###
|
||||
|
||||
RELAY = DigitalInOut(board.D10)
|
||||
RELAY.direction = Direction.OUTPUT
|
||||
|
|
@ -47,10 +56,10 @@ esp32_reset = DigitalInOut(board.D12)
|
|||
spi = busio.SPI(board.SCK, board.MOSI, board.MISO)
|
||||
esp = adafruit_esp32spi.ESP_SPIcontrol(spi, esp32_cs, esp32_ready, esp32_reset)
|
||||
"""Use below for Most Boards"""
|
||||
status_light = neopixel.NeoPixel(
|
||||
status_pixel = neopixel.NeoPixel(
|
||||
board.NEOPIXEL, 1, brightness=0.2
|
||||
) # Uncomment for Most Boards
|
||||
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.
|
||||
# pylint: disable=unused-argument
|
||||
|
|
@ -81,8 +90,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=secrets["aio_username"],
|
||||
password=secrets["aio_key"],
|
||||
username=aio_username,
|
||||
password=aio_key,
|
||||
socket_pool=pool,
|
||||
ssl_context=ssl_context,
|
||||
)
|
||||
|
|
|
|||
|
|
@ -12,6 +12,8 @@ Uses:
|
|||
OR
|
||||
* https://www.adafruit.com/product/2935
|
||||
"""
|
||||
|
||||
from os import getenv
|
||||
import board
|
||||
import busio
|
||||
import adafruit_connection_manager
|
||||
|
|
@ -22,14 +24,22 @@ import adafruit_minimqtt.adafruit_minimqtt as MQTT
|
|||
from adafruit_io.adafruit_io import IO_MQTT
|
||||
from digitalio import DigitalInOut, Direction
|
||||
|
||||
### WiFi ###
|
||||
# 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")
|
||||
|
||||
# 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, 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."
|
||||
)
|
||||
|
||||
### WiFi ###
|
||||
|
||||
# If you are using a Relay FeatherWing, make sure this pin corresponds to the pin shorted on the
|
||||
# bottom of the Relay FeatherWing
|
||||
|
|
@ -44,10 +54,10 @@ esp32_reset = DigitalInOut(board.D12)
|
|||
spi = busio.SPI(board.SCK, board.MOSI, board.MISO)
|
||||
esp = adafruit_esp32spi.ESP_SPIcontrol(spi, esp32_cs, esp32_ready, esp32_reset)
|
||||
"""Use below for Most Boards"""
|
||||
status_light = neopixel.NeoPixel(
|
||||
status_pixel = neopixel.NeoPixel(
|
||||
board.NEOPIXEL, 1, brightness=0.2
|
||||
) # Uncomment for Most Boards
|
||||
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.
|
||||
# pylint: disable=unused-argument
|
||||
|
|
@ -75,8 +85,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=secrets["aio_username"],
|
||||
password=secrets["aio_key"],
|
||||
username=aio_username,
|
||||
password=aio_key,
|
||||
socket_pool=pool,
|
||||
ssl_context=ssl_context,
|
||||
)
|
||||
|
|
|
|||
|
|
@ -14,6 +14,7 @@ Uses:
|
|||
* https://www.adafruit.com/product/4399
|
||||
"""
|
||||
|
||||
from os import getenv
|
||||
import ssl
|
||||
import socketpool
|
||||
import wifi
|
||||
|
|
@ -25,33 +26,30 @@ import busio
|
|||
import board
|
||||
import adafruit_sht4x
|
||||
|
||||
### WiFi ###
|
||||
# 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")
|
||||
|
||||
# Add a secrets.py to your filesystem that has a dictionary called secrets with "ssid" and
|
||||
# "password" keys with your WiFi credentials. DO NOT share that file or commit it into Git or other
|
||||
# source control.
|
||||
# pylint: disable=no-name-in-module,wrong-import-order
|
||||
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."
|
||||
)
|
||||
|
||||
### WiFi ###
|
||||
|
||||
magtag = MagTag()
|
||||
|
||||
try:
|
||||
from secrets import secrets
|
||||
except ImportError:
|
||||
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"]
|
||||
|
||||
|
||||
connected = False
|
||||
try:
|
||||
print("Connecting to %s" % secrets["ssid"])
|
||||
wifi.radio.connect(secrets["ssid"], secrets["password"])
|
||||
print("Connected to %s!" % secrets["ssid"])
|
||||
print(f"Connecting to {ssid}")
|
||||
wifi.radio.connect(ssid, password)
|
||||
print(f"Connected to {ssid}!")
|
||||
|
||||
# Create a socket pool
|
||||
pool = socketpool.SocketPool(wifi.radio)
|
||||
|
|
@ -59,8 +57,8 @@ try:
|
|||
# Initialize a new MQTT Client object
|
||||
mqtt_client = MQTT.MQTT(
|
||||
broker="io.adafruit.com",
|
||||
username=secrets["aio_username"],
|
||||
password=secrets["aio_key"],
|
||||
username=aio_username,
|
||||
password=aio_key,
|
||||
socket_pool=pool,
|
||||
ssl_context=ssl.create_default_context(),
|
||||
)
|
||||
|
|
|
|||
|
|
@ -1,2 +0,0 @@
|
|||
FunHouse_LIFX/code.py 117: Comparison to literal (literal-comparison)
|
||||
FunHouse_LIFX/code.py 136: Comparison to literal (literal-comparison)
|
||||
|
|
@ -1,21 +1,28 @@
|
|||
# SPDX-FileCopyrightText: 2021 John Park for Adafruit Industries
|
||||
# SPDX-License-Identifier: MIT
|
||||
# FunHouse PIR Motion Sensor for LIFX light bulbs
|
||||
|
||||
from os import getenv
|
||||
import time
|
||||
import ssl
|
||||
import socketpool
|
||||
import wifi
|
||||
import adafruit_requests
|
||||
from adafruit_funhouse import FunHouse
|
||||
from displayio import CIRCUITPYTHON_TERMINAL
|
||||
import adafruit_lifx
|
||||
from adafruit_funhouse import FunHouse
|
||||
|
||||
# Get wifi details and more from a secrets.py file
|
||||
try:
|
||||
from secrets import secrets
|
||||
except ImportError:
|
||||
print("WiFi and API 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."
|
||||
)
|
||||
|
||||
# choose colors here. Note formatting differences.
|
||||
default_bulb_color = "#002010"
|
||||
|
|
@ -24,13 +31,13 @@ tripped_bulb_color = "#440044"
|
|||
tripped_led_color = 0x440044
|
||||
|
||||
# Set up ESP32-S2 and adafruit_requests session
|
||||
wifi.radio.connect(ssid=secrets["ssid"], password=secrets["password"])
|
||||
wifi.radio.connect(ssid, password)
|
||||
pool = socketpool.SocketPool(wifi.radio)
|
||||
http_session = adafruit_requests.Session(pool, ssl.create_default_context())
|
||||
|
||||
# Add your LIFX Personal Access token to secrets.py
|
||||
# Add your LIFX Personal Access token to settings.toml
|
||||
# (to obtain a token, visit: https://cloud.lifx.com/settings)
|
||||
lifx_token = secrets["lifx_token"]
|
||||
lifx_token = getenv("lifx_token")
|
||||
|
||||
# Set this to your LIFX light separator label
|
||||
# https://api.developer.lifx.com/docs/selectors
|
||||
|
|
@ -115,7 +122,7 @@ while True:
|
|||
time.sleep(0.5)
|
||||
|
||||
# when sensor is tripped, set the color x amount of time
|
||||
if running_state is True and funhouse.peripherals.pir_sensor and pir_state is 0:
|
||||
if running_state is True and funhouse.peripherals.pir_sensor and pir_state == 0:
|
||||
funhouse.peripherals.dotstars.fill(tripped_led_color)
|
||||
funhouse.set_text("tripped", running_label)
|
||||
lifx.set_color(
|
||||
|
|
@ -134,7 +141,7 @@ while True:
|
|||
|
||||
# return to default color
|
||||
elif (
|
||||
running_state is True and not funhouse.peripherals.pir_sensor and pir_state is 1
|
||||
running_state is True and not funhouse.peripherals.pir_sensor and pir_state == 1
|
||||
):
|
||||
funhouse.peripherals.dotstars.fill(default_led_color)
|
||||
funhouse.set_text("sensing...", running_label)
|
||||
|
|
|
|||
|
|
@ -1,5 +0,0 @@
|
|||
IoT_Environment_Sensor/gps.py 22: Class 'Gps' inherits from object, can be safely removed from bases in python3 (useless-object-inheritance)
|
||||
IoT_Environment_Sensor/air_quality.py 24: Class 'AirQualitySensor' inherits from object, can be safely removed from bases in python3 (useless-object-inheritance)
|
||||
IoT_Environment_Sensor/aio.py 41: Class 'AIO' inherits from object, can be safely removed from bases in python3 (useless-object-inheritance)
|
||||
IoT_Environment_Sensor/aio.py 120: Consider explicitly re-raising using the 'from' keyword (raise-missing-from)
|
||||
IoT_Environment_Sensor/aio.py 142: Consider explicitly re-raising using the 'from' keyword (raise-missing-from)
|
||||
|
|
@ -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 gc
|
||||
import board
|
||||
|
|
@ -37,14 +38,22 @@ TIME_SERVICE_STRFTIME = '&fmt=%25Y-%25m-%25d+%25H%3A%25M%3A%25S.%25L+%25j+%25u+%
|
|||
|
||||
|
||||
|
||||
# Get wifi details and more from a settings.py file
|
||||
try:
|
||||
from secrets import secrets
|
||||
except ImportError:
|
||||
logger.critical('WiFi settings are kept in settings.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")
|
||||
|
||||
class AIO(object):
|
||||
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."
|
||||
)
|
||||
|
||||
class AIO:
|
||||
|
||||
def __init__(self):
|
||||
try:
|
||||
|
|
@ -76,16 +85,16 @@ class AIO(object):
|
|||
logger.debug("Connecting...")
|
||||
while not self._esp.is_connected:
|
||||
try:
|
||||
self._esp.connect_AP(secrets['ssid'], secrets['password'])
|
||||
self._esp.connect_AP(ssid, password)
|
||||
except RuntimeError as e:
|
||||
logger.error("could not connect to AP, retrying: %s", e)
|
||||
continue
|
||||
|
||||
def post(self, feed, payload):
|
||||
api_url = 'https://io.adafruit.com/api/v2/{0}/feeds/{1}/data'.format(secrets['aio_username'], feed)# pylint: disable=line-too-long
|
||||
api_url = f'https://io.adafruit.com/api/v2/{aio_username}/feeds/{feed}/data'
|
||||
logger.info('POSTing to %s', api_url)
|
||||
logger.info('payload: %s', str(payload))
|
||||
auth_header = {'X-AIO-KEY':secrets['aio_key']}
|
||||
auth_header = {'X-AIO-KEY': aio_key}
|
||||
self.connect()
|
||||
r = None
|
||||
tries = 0
|
||||
|
|
@ -119,13 +128,8 @@ class AIO(object):
|
|||
"""
|
||||
# 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['timezone']
|
||||
location = getenv('timezone')
|
||||
if location:
|
||||
logger.debug('Getting time for timezone %s', location)
|
||||
api_url = (TIME_SERVICE + "&tz=%s") % (aio_username, aio_key, location)
|
||||
|
|
@ -144,8 +148,8 @@ class AIO(object):
|
|||
year_day = int(times[2])
|
||||
week_day = int(times[3])
|
||||
is_dst = None # no way to know yet
|
||||
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
|
||||
except KeyError as exc:
|
||||
raise KeyError("Was unable to lookup the time, try setting timezone in your settings.toml according to http://worldtimeapi.org/timezones") from exc # pylint: disable=line-too-long
|
||||
year, month, mday = [int(x) for x in the_date.split('-')]
|
||||
the_time = the_time.split('.')[0]
|
||||
hours, minutes, seconds = [int(x) for x in the_time.split(':')]
|
||||
|
|
|
|||
|
|
@ -27,7 +27,7 @@ logger = logging.getLogger('main')
|
|||
if not logger.hasHandlers():
|
||||
logger.addHandler(logging.StreamHandler())
|
||||
|
||||
class AirQualitySensor (object):
|
||||
class AirQualitySensor:
|
||||
|
||||
def __init__(self, uart):
|
||||
self._uart = uart
|
||||
|
|
|
|||
|
|
@ -21,9 +21,9 @@ import board
|
|||
import busio
|
||||
import air_quality
|
||||
import gps
|
||||
import adafruit_bme280
|
||||
import aio
|
||||
import adafruit_logging as logging
|
||||
import adafruit_bme280
|
||||
|
||||
logger = logging.getLogger('main')
|
||||
if not logger.hasHandlers():
|
||||
|
|
|
|||
|
|
@ -25,7 +25,7 @@ logger = logging.getLogger('main')
|
|||
if not logger.hasHandlers():
|
||||
logger.addHandler(logging.StreamHandler())
|
||||
|
||||
class Gps(object):
|
||||
class Gps:
|
||||
|
||||
def __init__(self, uart):
|
||||
self._gps = adafruit_gps.GPS(uart, debug=False)
|
||||
|
|
|
|||
|
|
@ -1,14 +0,0 @@
|
|||
# SPDX-FileCopyrightText: 2019 Dave Astels 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": b"My_SSID",
|
||||
"password": b"My_WIFI_Password",
|
||||
"timezone": "Area/City",
|
||||
"aio_username": "my_username",
|
||||
"aio_key": "my_key",
|
||||
}
|
||||
12
IoT_Environment_Sensor/settings.toml
Normal file
12
IoT_Environment_Sensor/settings.toml
Normal file
|
|
@ -0,0 +1,12 @@
|
|||
# SPDX-FileCopyrightText: 2019 Dave Astels 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
|
||||
|
|
@ -1 +0,0 @@
|
|||
IoT_NeoPixel_Sign/code.py 47: Using the global statement (global-statement)
|
||||
|
|
@ -2,6 +2,7 @@
|
|||
#
|
||||
# SPDX-License-Identifier: MIT
|
||||
|
||||
from os import getenv
|
||||
import ssl
|
||||
import board
|
||||
import neopixel
|
||||
|
|
@ -12,20 +13,26 @@ from adafruit_io.adafruit_io import IO_HTTP
|
|||
from adafruit_pixel_framebuf import PixelFramebuffer
|
||||
# adafruit_circuitpython_adafruitio usage with native wifi networking
|
||||
|
||||
# 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."
|
||||
)
|
||||
|
||||
# Neopixel matrix configuration
|
||||
PIXEL_PIN = board.IO6
|
||||
PIXEL_WIDTH = 12
|
||||
PIXEL_HEIGHT = 12
|
||||
|
||||
# secrets.py has SSID/password and adafruit.io
|
||||
try:
|
||||
from secrets import secrets
|
||||
except ImportError:
|
||||
print("WiFi secrets are kept in secrets.py, please add them there!")
|
||||
raise
|
||||
AIO_USERNAME = secrets["aio_username"]
|
||||
AIO_KEY = secrets["aio_key"]
|
||||
|
||||
# LED matrix creation
|
||||
PIXELS = neopixel.NeoPixel(
|
||||
PIXEL_PIN, PIXEL_WIDTH * PIXEL_HEIGHT, brightness=0.5, auto_write=False,
|
||||
|
|
@ -48,7 +55,7 @@ CURRENT_COLOR = 0xFFFFFF
|
|||
|
||||
# Helper function to get updated data from Adafruit.io
|
||||
def update_data():
|
||||
global CURRENT_TEXT, CURRENT_COLOR
|
||||
global CURRENT_TEXT, CURRENT_COLOR # pylint: disable=global-statement
|
||||
print("Updating data from Adafruit IO")
|
||||
try:
|
||||
quote_feed = IO.get_feed(QUOTE_FEED)
|
||||
|
|
@ -63,15 +70,15 @@ def update_data():
|
|||
|
||||
|
||||
# Connect to WiFi
|
||||
print("Connecting to %s" % secrets["ssid"])
|
||||
wifi.radio.connect(secrets["ssid"], secrets["password"])
|
||||
print("Connected to %s!" % secrets["ssid"])
|
||||
print(f"Connecting to {ssid}")
|
||||
wifi.radio.connect(ssid, password)
|
||||
print(f"Connected to {ssid}!")
|
||||
|
||||
# Setup Adafruit IO connection
|
||||
POOL = socketpool.SocketPool(wifi.radio)
|
||||
REQUESTS = adafruit_requests.Session(POOL, ssl.create_default_context())
|
||||
pool = socketpool.SocketPool(wifi.radio)
|
||||
requests = adafruit_requests.Session(pool, ssl.create_default_context())
|
||||
# Initialize an Adafruit IO HTTP API object
|
||||
IO = IO_HTTP(AIO_USERNAME, AIO_KEY, REQUESTS)
|
||||
IO = IO_HTTP(aio_username, aio_key, requests)
|
||||
|
||||
|
||||
while True:
|
||||
|
|
|
|||
|
|
@ -2,6 +2,7 @@
|
|||
#
|
||||
# SPDX-License-Identifier: MIT
|
||||
|
||||
from os import getenv
|
||||
import time
|
||||
import board
|
||||
import displayio
|
||||
|
|
@ -9,17 +10,22 @@ from adafruit_matrixportal.matrixportal import MatrixPortal
|
|||
from adafruit_matrixportal.matrix import Matrix
|
||||
import adafruit_imageload
|
||||
|
||||
# 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
|
||||
|
||||
print("Party Parrot Twitter Matrix")
|
||||
|
||||
# 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."
|
||||
)
|
||||
|
||||
# import your bearer token
|
||||
bear = secrets['bearer_token']
|
||||
bear = getenv('bearer_token')
|
||||
|
||||
# query URL for tweets. looking for hashtag partyparrot sent to a specific username
|
||||
DATA_SOURCE = 'https://api.twitter.com/2/tweets/search/recent?query=#partyparrot to:blitzcitydiy'
|
||||
|
|
|
|||
|
|
@ -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' : 'insert your network name here',
|
||||
'password' : 'insert your network password here',
|
||||
'timezone' : "America/New_York", # http://worldtimeapi.org/timezones
|
||||
'twitter_api_key' : 'insert your twitter api key here',
|
||||
'twitter_secret_key' : 'insert your twitter secret key here',
|
||||
'bearer_token' : 'insert your bearer token here'
|
||||
}
|
||||
13
IoT_Party_Parrot/settings.toml
Normal file
13
IoT_Party_Parrot/settings.toml
Normal file
|
|
@ -0,0 +1,13 @@
|
|||
# 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"
|
||||
timezone="America/New_York" # http://worldtimeapi.org/timezones
|
||||
twitter_api_key="insert your twitter api key here"
|
||||
twitter_secret_key="insert your twitter secret key here"
|
||||
bearer_token="insert your bearer token here"
|
||||
Loading…
Reference in a new issue