Skip to content

Commit 758f916

Browse files
authored
Merge pull request #2778 from adafruit/dhalbert-patch-14
Adafruit_IO_Power_Relay: update to settings.toml
2 parents cb3f0db + 7f94997 commit 758f916

1 file changed

Lines changed: 8 additions & 9 deletions

File tree

Adafruit_IO_Power_Relay/code.py

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
#
33
# SPDX-License-Identifier: MIT
44

5+
import os
56
import time
67
import board
78
import busio
@@ -15,12 +16,10 @@
1516

1617
### WiFi ###
1718

18-
# Get wifi details and more from a secrets.py file
19-
try:
20-
from secrets import secrets
21-
except ImportError:
22-
print("WiFi secrets are kept in secrets.py, please add them there!")
23-
raise
19+
secrets = {
20+
"ssid" : os.getenv("CIRCUITPY_WIFI_SSID"),
21+
"password" : os.getenv("CIRCUITPY_WIFI_PASSWORD"),
22+
}
2423

2524
# If you are using a board with pre-defined ESP32 Pins:
2625
esp32_cs = DigitalInOut(board.ESP_CS)
@@ -55,7 +54,7 @@
5554

5655
### Feeds ###
5756
# Set up a feed named Relay for subscribing to the relay feed on Adafruit IO
58-
feed_relay = secrets["aio_username"] + "/feeds/relay"
57+
feed_relay = os.getenv("AIO_USERNAME") + "/feeds/relay"
5958

6059
### Code ###
6160

@@ -107,8 +106,8 @@ def on_relay_msg(client, topic, value):
107106
# Set up a MiniMQTT Client
108107
client = MQTT.MQTT(
109108
broker="io.adafruit.com",
110-
username=secrets["aio_username"],
111-
password=secrets["aio_key"],
109+
username=os.getenv("AIO_USERNAME"),
110+
password=os.getenv("AIO_KEY"),
112111
socket_pool=pool,
113112
ssl_context=ssl_context,
114113
)

0 commit comments

Comments
 (0)