Skip to content

Commit 55be280

Browse files
author
brentru
committed
add Adafruit IO example!
1 parent dab3551 commit 55be280

File tree

1 file changed

+39
-0
lines changed

1 file changed

+39
-0
lines changed

examples/wiznet5k_aio_post.py

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
import time
2+
import board
3+
import busio
4+
from digitalio import DigitalInOut
5+
from adafruit_wiznet5k.adafruit_wiznet5k import WIZNET5K
6+
import adafruit_wiznet5k.adafruit_wiznet5k_socket as socket
7+
import adafruit_requests as requests
8+
9+
# Get Adafruit.io details from a secrets.py file
10+
try:
11+
from secrets import secrets
12+
except ImportError:
13+
print("WiFi secrets are kept in secrets.py, please add them there!")
14+
raise
15+
16+
cs = DigitalInOut(board.D10)
17+
spi_bus = busio.SPI(board.SCK, MOSI=board.MOSI, MISO=board.MISO)
18+
19+
# Initialize ethernet interface with DHCP
20+
eth = WIZNET5K(spi_bus, cs)
21+
requests.set_socket(socket, eth)
22+
23+
counter = 0
24+
25+
while True:
26+
print("Posting data...", end='')
27+
data = counter
28+
feed = 'test'
29+
payload = {'value':data}
30+
response = requests.post(
31+
"http://io.adafruit.com/api/v2/"+secrets['aio_username']+"/feeds/"+feed+"/data",
32+
json=payload,
33+
headers={"X-AIO-KEY":secrets['aio_key']})
34+
print(response.json())
35+
response.close()
36+
counter = counter + 1
37+
print("OK")
38+
response = None
39+
time.sleep(15)

0 commit comments

Comments
 (0)