Skip to content

Remove secrets usage #23

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Feb 25, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 16 additions & 18 deletions examples/wsgi_simpletest.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
# SPDX-FileCopyrightText: 2021 ladyada for Adafruit Industries
# SPDX-License-Identifier: MIT

from os import getenv
import board
import busio
from digitalio import DigitalInOut
Expand All @@ -11,12 +12,9 @@
import adafruit_wsgi.esp32spi_wsgiserver as server
from adafruit_wsgi.wsgi_app import WSGIApp

# Get wifi details and more from a secrets.py file
try:
from secrets import secrets
except ImportError:
print("WiFi secrets are kept in secrets.py, please add them there!")
raise
# Get WiFi details, ensure these are setup in settings.toml
ssid = getenv("CIRCUITPY_WIFI_SSID")
password = getenv("CIRCUITPY_WIFI_PASSWORD")

# This example depends on a WSGI Server to run.
# We are using the wsgi server made for the ESP32
Expand All @@ -40,25 +38,25 @@
) # pylint: disable=line-too-long

"""Use below for Most Boards"""
status_light = neopixel.NeoPixel(
status_pixel = neopixel.NeoPixel(
board.NEOPIXEL, 1, brightness=0.2
) # Uncomment for Most Boards
"""Uncomment below for ItsyBitsy M4"""
# import adafruit_dotstar as dotstar
# status_light = dotstar.DotStar(board.APA102_SCK, board.APA102_MOSI, 1, brightness=1)
# status_pixel = dotstar.DotStar(board.APA102_SCK, board.APA102_MOSI, 1, brightness=1)

## If you want to connect to wifi with secrets:
wifi = wifimanager.ESPSPI_WiFiManager(esp, secrets, status_light, debug=True)
## If you want to connect to wifi:
wifi = wifimanager.WiFiManager(
esp, ssid, password, status_pixel=status_pixel, debug=True
)
wifi.connect()

## If you want to create a WIFI hotspot to connect to with secrets:
# secrets = {"ssid": "My ESP32 AP!", "password": "supersecret"}
# wifi = wifimanager.ESPSPI_WiFiManager(esp, secrets, status_light)
## If you want to create a WIFI hotspot to connect to:
# wifi = wifimanager.WiFiManager(esp, "My ESP32 AP!", "supersecret", status_pixel=status_pixel)
# wifi.create_ap()

## To you want to create an un-protected WIFI hotspot to connect to with secrets:"
# secrets = {"ssid": "My ESP32 AP!"}
# wifi = wifimanager.ESPSPI_WiFiManager(esp, secrets, status_light)
## To you want to create an un-protected WIFI hotspot to connect to:"
# wifi = wifimanager.WiFiManager(esp, "My ESP32 AP!", password=None, status_pixel=status_pixel)
# wifi.create_ap()

# Here we create our application, registering the
Expand All @@ -70,14 +68,14 @@
@web_app.route("/led_on/<r>/<g>/<b>")
def led_on(request, r, g, b): # pylint: disable=unused-argument
print("led on!")
status_light.fill((int(r), int(g), int(b)))
status_pixel.fill((int(r), int(g), int(b)))
return ("200 OK", [], "led on!")


@web_app.route("/led_off")
def led_off(request): # pylint: disable=unused-argument
print("led off!")
status_light.fill(0)
status_pixel.fill(0)
return ("200 OK", [], "led off!")


Expand Down
34 changes: 15 additions & 19 deletions examples/wsgi_static_files_server.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
# SPDX-License-Identifier: MIT

import os
from os import getenv
import board
import busio
from digitalio import DigitalInOut
Expand All @@ -16,12 +17,9 @@
# being copied to the root of the circuitpython filesystem.
# This is where our static assets like html, js, and css live.

# Get wifi details and more from a secrets.py file
try:
from secrets import secrets
except ImportError:
print("WiFi secrets are kept in secrets.py, please add them there!")
raise
# Get WiFi details, ensure these are setup in settings.toml
ssid = getenv("CIRCUITPY_WIFI_SSID")
password = getenv("CIRCUITPY_WIFI_PASSWORD")

try:
import json as json_module
Expand Down Expand Up @@ -49,25 +47,23 @@
print("MAC addr actual:", [hex(i) for i in esp.MAC_address_actual])

# Use below for Most Boards
status_light = neopixel.NeoPixel(
status_pixel = neopixel.NeoPixel(
board.NEOPIXEL, 1, brightness=0.2
) # Uncomment for Most Boards
# Uncomment below for ItsyBitsy M4
# import adafruit_dotstar as dotstar
# status_light = dotstar.DotStar(board.APA102_SCK, board.APA102_MOSI, 1, brightness=1)
# status_pixel = dotstar.DotStar(board.APA102_SCK, board.APA102_MOSI, 1, brightness=1)

## If you want to connect to wifi with secrets:
wifi = wifimanager.ESPSPI_WiFiManager(esp, secrets, status_light)
## If you want to connect to wifi:
wifi = wifimanager.WiFiManager(esp, ssid, password, status_pixel=status_pixel)
wifi.connect()

## If you want to create a WIFI hotspot to connect to with secrets:
# secrets = {"ssid": "My ESP32 AP!", "password": "supersecret"}
# wifi = wifimanager.ESPSPI_WiFiManager(esp, secrets, status_light)
## If you want to create a WIFI hotspot to connect to:
# wifi = wifimanager.WiFiManager(esp, "My ESP32 AP!", "supersecret", status_pixel=status_pixel)
# wifi.create_ap()

## To you want to create an un-protected WIFI hotspot to connect to with secrets:"
# secrets = {"ssid": "My ESP32 AP!"}
# wifi = wifimanager.ESPSPI_WiFiManager(esp, secrets, status_light)
## To you want to create an un-protected WIFI hotspot to connect to:"
# wifi = wifimanager.WiFiManager(esp, "My ESP32 AP!", password=None, status_pixel=status_pixel)
# wifi.create_ap()


Expand Down Expand Up @@ -181,21 +177,21 @@ def _get_content_type(self, file): # pylint: disable=no-self-use
# Our HTTP Request handlers
def led_on(environ): # pylint: disable=unused-argument
print("led on!")
status_light.fill((0, 0, 100))
status_pixel.fill((0, 0, 100))
return web_app.serve_file("static/index.html")


def led_off(environ): # pylint: disable=unused-argument
print("led off!")
status_light.fill(0)
status_pixel.fill(0)
return web_app.serve_file("static/index.html")


def led_color(environ): # pylint: disable=unused-argument
json = json_module.loads(environ["wsgi.input"].getvalue())
print(json)
rgb_tuple = (json.get("r"), json.get("g"), json.get("b"))
status_light.fill(rgb_tuple)
status_pixel.fill(rgb_tuple)
return ("200 OK", [], [])


Expand Down