diff --git a/examples/wiznet5k_aio_post.py b/examples/wiznet5k_aio_post.py index 07f7869..96525bd 100644 --- a/examples/wiznet5k_aio_post.py +++ b/examples/wiznet5k_aio_post.py @@ -1,6 +1,7 @@ # SPDX-FileCopyrightText: 2021 ladyada for Adafruit Industries # SPDX-License-Identifier: MIT +from os import getenv import time import board import busio @@ -9,12 +10,10 @@ import adafruit_requests from adafruit_wiznet5k.adafruit_wiznet5k import WIZNET5K -# Get Adafruit.io details from a secrets.py file -try: - from secrets import secrets -except ImportError: - print("WiFi secrets are kept in secrets.py, please add them there!") - raise +# Get Adafruit IO keys, ensure these are setup in settings.toml +# (visit io.adafruit.com if you need to create an account, or if you need your Adafruit IO key.) +aio_username = getenv("ADAFRUIT_AIO_USERNAME") +aio_key = getenv("ADAFRUIT_AIO_KEY") cs = DigitalInOut(board.D10) spi_bus = busio.SPI(board.SCK, MOSI=board.MOSI, MISO=board.MISO) @@ -34,13 +33,9 @@ feed = "test" payload = {"value": data} response = requests.post( - "http://io.adafruit.com/api/v2/" - + secrets["aio_username"] - + "/feeds/" - + feed - + "/data", + f"http://io.adafruit.com/api/v2/{aio_username}/feeds/{feed}/data", json=payload, - headers={"X-AIO-KEY": secrets["aio_key"]}, + headers={"X-AIO-KEY": aio_key}, ) print(response.json()) response.close()