Skip to content

Commit 4502430

Browse files
authored
Merge pull request #176 from justmobilize/remove-secrets
Remove secrets
2 parents 9d1317e + 8ab073c commit 4502430

File tree

1 file changed

+7
-12
lines changed

1 file changed

+7
-12
lines changed

examples/wiznet5k_aio_post.py

Lines changed: 7 additions & 12 deletions
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 time
56
import board
67
import busio
@@ -9,12 +10,10 @@
910
import adafruit_requests
1011
from adafruit_wiznet5k.adafruit_wiznet5k import WIZNET5K
1112

12-
# Get Adafruit.io details from a secrets.py file
13-
try:
14-
from secrets import secrets
15-
except ImportError:
16-
print("WiFi secrets are kept in secrets.py, please add them there!")
17-
raise
13+
# Get Adafruit IO keys, ensure these are setup in settings.toml
14+
# (visit io.adafruit.com if you need to create an account, or if you need your Adafruit IO key.)
15+
aio_username = getenv("ADAFRUIT_AIO_USERNAME")
16+
aio_key = getenv("ADAFRUIT_AIO_KEY")
1817

1918
cs = DigitalInOut(board.D10)
2019
spi_bus = busio.SPI(board.SCK, MOSI=board.MOSI, MISO=board.MISO)
@@ -34,13 +33,9 @@
3433
feed = "test"
3534
payload = {"value": data}
3635
response = requests.post(
37-
"http://io.adafruit.com/api/v2/"
38-
+ secrets["aio_username"]
39-
+ "/feeds/"
40-
+ feed
41-
+ "/data",
36+
f"http://io.adafruit.com/api/v2/{aio_username}/feeds/{feed}/data",
4237
json=payload,
43-
headers={"X-AIO-KEY": secrets["aio_key"]},
38+
headers={"X-AIO-KEY": aio_key},
4439
)
4540
print(response.json())
4641
response.close()

0 commit comments

Comments
 (0)