Skip to content

Commit 68b8b6e

Browse files
authored
Merge pull request #23 from justmobilize/remove-secrets-usage
Remove secrets usage
2 parents 04ed5aa + 7502ee6 commit 68b8b6e

File tree

2 files changed

+31
-37
lines changed

2 files changed

+31
-37
lines changed

examples/wsgi_simpletest.py

+16-18
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
# SPDX-FileCopyrightText: 2021 ladyada for Adafruit Industries
22
# SPDX-License-Identifier: MIT
33

4+
from os import getenv
45
import board
56
import busio
67
from digitalio import DigitalInOut
@@ -11,12 +12,9 @@
1112
import adafruit_wsgi.esp32spi_wsgiserver as server
1213
from adafruit_wsgi.wsgi_app import WSGIApp
1314

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

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

4240
"""Use below for Most Boards"""
43-
status_light = neopixel.NeoPixel(
41+
status_pixel = neopixel.NeoPixel(
4442
board.NEOPIXEL, 1, brightness=0.2
4543
) # Uncomment for Most Boards
4644
"""Uncomment below for ItsyBitsy M4"""
4745
# import adafruit_dotstar as dotstar
48-
# status_light = dotstar.DotStar(board.APA102_SCK, board.APA102_MOSI, 1, brightness=1)
46+
# status_pixel = dotstar.DotStar(board.APA102_SCK, board.APA102_MOSI, 1, brightness=1)
4947

50-
## If you want to connect to wifi with secrets:
51-
wifi = wifimanager.ESPSPI_WiFiManager(esp, secrets, status_light, debug=True)
48+
## If you want to connect to wifi:
49+
wifi = wifimanager.WiFiManager(
50+
esp, ssid, password, status_pixel=status_pixel, debug=True
51+
)
5252
wifi.connect()
5353

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

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

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

7674

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

8381

examples/wsgi_static_files_server.py

+15-19
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
# SPDX-License-Identifier: MIT
44

55
import os
6+
from os import getenv
67
import board
78
import busio
89
from digitalio import DigitalInOut
@@ -16,12 +17,9 @@
1617
# being copied to the root of the circuitpython filesystem.
1718
# This is where our static assets like html, js, and css live.
1819

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

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

5149
# Use below for Most Boards
52-
status_light = neopixel.NeoPixel(
50+
status_pixel = neopixel.NeoPixel(
5351
board.NEOPIXEL, 1, brightness=0.2
5452
) # Uncomment for Most Boards
5553
# Uncomment below for ItsyBitsy M4
5654
# import adafruit_dotstar as dotstar
57-
# status_light = dotstar.DotStar(board.APA102_SCK, board.APA102_MOSI, 1, brightness=1)
55+
# status_pixel = dotstar.DotStar(board.APA102_SCK, board.APA102_MOSI, 1, brightness=1)
5856

59-
## If you want to connect to wifi with secrets:
60-
wifi = wifimanager.ESPSPI_WiFiManager(esp, secrets, status_light)
57+
## If you want to connect to wifi:
58+
wifi = wifimanager.WiFiManager(esp, ssid, password, status_pixel=status_pixel)
6159
wifi.connect()
6260

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

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

7369

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

187183

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

193189

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

201197

0 commit comments

Comments
 (0)