|
2 | 2 | # |
3 | 3 | # SPDX-License-Identifier: MIT |
4 | 4 |
|
| 5 | +from os import getenv |
5 | 6 | import board |
6 | 7 | import displayio |
7 | 8 | import busio |
|
18 | 19 | import adafruit_touchscreen |
19 | 20 | import adafruit_minimqtt.adafruit_minimqtt as MQTT |
20 | 21 |
|
21 | | -# ------------- WiFi ------------- # |
| 22 | +# Get WiFi details, ensure these are setup in settings.toml |
| 23 | +ssid = getenv("CIRCUITPY_WIFI_SSID") |
| 24 | +password = getenv("CIRCUITPY_WIFI_PASSWORD") |
| 25 | + |
| 26 | +if None in [ssid, password]: |
| 27 | + raise RuntimeError( |
| 28 | + "WiFi settings are kept in settings.toml, " |
| 29 | + "please add them there. The settings file must contain " |
| 30 | + "'CIRCUITPY_WIFI_SSID', 'CIRCUITPY_WIFI_PASSWORD', " |
| 31 | + "at a minimum." |
| 32 | + ) |
22 | 33 |
|
23 | | -# Get wifi details and more from a secrets.py file |
24 | | -try: |
25 | | - from secrets import secrets |
26 | | -except ImportError: |
27 | | - print("WiFi secrets are kept in secrets.py, please add them there!") |
28 | | - raise |
| 34 | +# ------------- WiFi ------------- # |
29 | 35 |
|
30 | 36 | # If you are using a board with pre-defined ESP32 Pins: |
31 | 37 | esp32_cs = DigitalInOut(board.ESP_CS) |
|
34 | 40 |
|
35 | 41 | spi = busio.SPI(board.SCK, board.MOSI, board.MISO) |
36 | 42 | esp = adafruit_esp32spi.ESP_SPIcontrol(spi, esp32_cs, esp32_ready, esp32_reset) |
37 | | -status_light = neopixel.NeoPixel(board.NEOPIXEL, 1, brightness=0.2) |
38 | | -wifi = adafruit_esp32spi_wifimanager.ESPSPI_WiFiManager(esp, secrets, status_light) |
| 43 | +status_pixel = neopixel.NeoPixel(board.NEOPIXEL, 1, brightness=0.2) |
| 44 | +wifi = adafruit_esp32spi_wifimanager.WiFiManager(esp, ssid, password, status_pixel=status_pixel) |
39 | 45 |
|
40 | 46 | # ------- Sensor Setup ------- # |
41 | 47 | # init. the temperature sensor |
@@ -234,10 +240,10 @@ def message(client, topic, message): |
234 | 240 |
|
235 | 241 | # Set up a MiniMQTT Client |
236 | 242 | client = MQTT.MQTT( |
237 | | - broker=secrets["broker"], |
| 243 | + broker=getenv("mqtt_broker"), |
238 | 244 | port=1883, |
239 | | - username=secrets["user"], |
240 | | - password=secrets["pass"], |
| 245 | + username=getenv("mqtt_username"), |
| 246 | + password=getenv("mqtt_password"), |
241 | 247 | socket_pool=pool, |
242 | 248 | ssl_context=ssl_context, |
243 | 249 | ) |
|
0 commit comments