-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #11 from todbot/master
Add support for adafruit_requests.Session
- Loading branch information
Showing
3 changed files
with
68 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
# SPDX-FileCopyrightText: 2021 ladyada for Adafruit Industries | ||
# SPDX-License-Identifier: MIT | ||
|
||
import board | ||
import busio | ||
from digitalio import DigitalInOut | ||
import wifi | ||
import socketpool | ||
import ssl | ||
import adafruit_requests | ||
import neopixel | ||
|
||
import adafruit_lifx | ||
|
||
# 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 | ||
|
||
# Set up ESP32-S2 and adafruit_requests session | ||
wifi.radio.connect(ssid=secrets["ssid"], password=secrets["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 | ||
# (to obtain a token, visit: https://cloud.lifx.com/settings) | ||
lifx_token = secrets["lifx_token"] | ||
|
||
# Set this to your LIFX light separator label | ||
# https://api.developer.lifx.com/docs/selectors | ||
lifx_light = "label:Lamp" | ||
|
||
# Initialize the LIFX API Client | ||
lifx = adafruit_lifx.LIFX(http_session, lifx_token) | ||
|
||
# List all lights | ||
lights = lifx.list_lights() | ||
|
||
# Turn on the light | ||
print("Turning on light...") | ||
lifx.toggle_light(lifx_light) | ||
|
||
# Set the light's brightness to 50% | ||
light_brightness = 0.5 | ||
lifx.set_brightness(lifx_light, light_brightness) | ||
|
||
# Cycle the light using the colors of the Python logo | ||
colors = ["yellow", "blue", "white"] | ||
for color in colors: | ||
print("Setting light to: ", color) | ||
lifx.set_color(lifx_light, power="on", color=color, brightness=light_brightness) | ||
|
||
# Turn off the light | ||
print("Turning off light...") | ||
lifx.toggle_light(lifx_light) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4,3 +4,4 @@ | |
|
||
Adafruit-Blinka | ||
Adafruit_CircuitPython_ESP32SPI | ||
adafruit_circuitpython_requests |