|
3 | 3 | # SPDX-License-Identifier: MIT
|
4 | 4 | import time
|
5 | 5 | import ssl
|
| 6 | +import os |
6 | 7 | from random import randint
|
7 | 8 | import microcontroller
|
8 | 9 | import socketpool
|
|
12 | 13 | import adafruit_minimqtt.adafruit_minimqtt as MQTT
|
13 | 14 | from adafruit_io.adafruit_io import IO_MQTT
|
14 | 15 |
|
15 |
| -try: |
16 |
| - from secrets import secrets |
17 |
| -except ImportError: |
18 |
| - print("WiFi and Adafruit IO credentials are kept in secrets.py - please add them there!") |
19 |
| - raise |
20 |
| - |
21 |
| -# Add your Adafruit IO Username and Key to secrets.py |
22 |
| -# (visit io.adafruit.com if you need to create an account, |
23 |
| -# or if you need to obtain your Adafruit IO key.) |
24 |
| -aio_username = secrets["aio_username"] |
25 |
| -aio_key = secrets["aio_key"] |
26 | 16 |
|
27 | 17 | # WiFi
|
28 | 18 | try:
|
29 |
| - print("Connecting to %s" % secrets["ssid"]) |
30 |
| - wifi.radio.connect(secrets["ssid"], secrets["password"]) |
31 |
| - print("Connected to %s!" % secrets["ssid"]) |
| 19 | + print("Connecting to %s" % os.getenv("WIFI_SSID")) |
| 20 | + wifi.radio.connect(os.getenv("WIFI_SSID"), os.getenv("WIFI_PASSWORD")) |
| 21 | + print("Connected to %s!" % os.getenv("WIFI_SSID")) |
32 | 22 | # Wi-Fi connectivity fails with error messages, not specific errors, so this except is broad.
|
33 | 23 | except Exception as e: # pylint: disable=broad-except
|
34 | 24 | print("Failed to connect to WiFi. Error:", e, "\nBoard will hard reset in 30 seconds.")
|
@@ -58,8 +48,8 @@ def message(client, feed_id, payload): # pylint: disable=unused-argument
|
58 | 48 | # Initialize a new MQTT Client object
|
59 | 49 | mqtt_client = MQTT.MQTT(
|
60 | 50 | broker="io.adafruit.com",
|
61 |
| - username=secrets["aio_username"], |
62 |
| - password=secrets["aio_key"], |
| 51 | + username=os.getenv("AIO_USERNAME"), |
| 52 | + password=os.getenv("AIO_KEY"), |
63 | 53 | socket_pool=pool,
|
64 | 54 | ssl_context=ssl.create_default_context(),
|
65 | 55 | )
|
|
0 commit comments