|  | 
| 3 | 3 | # SPDX-License-Identifier: MIT | 
| 4 | 4 | 
 | 
| 5 | 5 | import os | 
|  | 6 | +from os import getenv | 
| 6 | 7 | import board | 
| 7 | 8 | import busio | 
| 8 | 9 | from digitalio import DigitalInOut | 
|  | 
| 16 | 17 | # being copied to the root of the circuitpython filesystem. | 
| 17 | 18 | # This is where our static assets like html, js, and css live. | 
| 18 | 19 | 
 | 
| 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") | 
| 25 | 23 | 
 | 
| 26 | 24 | try: | 
| 27 | 25 |     import json as json_module | 
|  | 
| 49 | 47 | print("MAC addr actual:", [hex(i) for i in esp.MAC_address_actual]) | 
| 50 | 48 | 
 | 
| 51 | 49 | # Use below for Most Boards | 
| 52 |  | -status_light = neopixel.NeoPixel( | 
|  | 50 | +status_pixel = neopixel.NeoPixel( | 
| 53 | 51 |     board.NEOPIXEL, 1, brightness=0.2 | 
| 54 | 52 | )  # Uncomment for Most Boards | 
| 55 | 53 | # Uncomment below for ItsyBitsy M4 | 
| 56 | 54 | # 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) | 
| 58 | 56 | 
 | 
| 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) | 
| 61 | 59 | wifi.connect() | 
| 62 | 60 | 
 | 
| 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) | 
| 66 | 63 | # wifi.create_ap() | 
| 67 | 64 | 
 | 
| 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) | 
| 71 | 67 | # wifi.create_ap() | 
| 72 | 68 | 
 | 
| 73 | 69 | 
 | 
| @@ -181,21 +177,21 @@ def _get_content_type(self, file):  # pylint: disable=no-self-use | 
| 181 | 177 | # Our HTTP Request handlers | 
| 182 | 178 | def led_on(environ):  # pylint: disable=unused-argument | 
| 183 | 179 |     print("led on!") | 
| 184 |  | -    status_light.fill((0, 0, 100)) | 
|  | 180 | +    status_pixel.fill((0, 0, 100)) | 
| 185 | 181 |     return web_app.serve_file("static/index.html") | 
| 186 | 182 | 
 | 
| 187 | 183 | 
 | 
| 188 | 184 | def led_off(environ):  # pylint: disable=unused-argument | 
| 189 | 185 |     print("led off!") | 
| 190 |  | -    status_light.fill(0) | 
|  | 186 | +    status_pixel.fill(0) | 
| 191 | 187 |     return web_app.serve_file("static/index.html") | 
| 192 | 188 | 
 | 
| 193 | 189 | 
 | 
| 194 | 190 | def led_color(environ):  # pylint: disable=unused-argument | 
| 195 | 191 |     json = json_module.loads(environ["wsgi.input"].getvalue()) | 
| 196 | 192 |     print(json) | 
| 197 | 193 |     rgb_tuple = (json.get("r"), json.get("g"), json.get("b")) | 
| 198 |  | -    status_light.fill(rgb_tuple) | 
|  | 194 | +    status_pixel.fill(rgb_tuple) | 
| 199 | 195 |     return ("200 OK", [], []) | 
| 200 | 196 | 
 | 
| 201 | 197 | 
 | 
|  | 
0 commit comments