Skip to content

Commit 36e6c8e

Browse files
author
brentru
committed
add adafruitio_00_publish.py
1 parent f056b83 commit 36e6c8e

File tree

1 file changed

+35
-0
lines changed

1 file changed

+35
-0
lines changed
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
"""
2+
'adafruitio_00_publish.py'
3+
==========================
4+
Publishes an incrementing
5+
value to a feed
6+
7+
Author(s): Brent Rubell, Todd Treece for Adafruit Industries
8+
"""
9+
import time
10+
# Import Adafruit IO REST client.
11+
from Adafruit_IO import Client, Feed
12+
13+
# holds the count for the feed
14+
run_count = 0
15+
16+
# Set to your Adafruit IO key.
17+
ADAFRUIT_IO_USERNAME = 'YOUR_AIO_USERNAME'
18+
ADAFRUIT_IO_KEY = 'YOUR_AIO_KEY'
19+
20+
# Create an instance of the REST client.
21+
aio = Client(ADAFRUIT_IO_USERNAME, ADAFRUIT_IO_KEY)
22+
23+
# Create a new feed named 'counter'
24+
feed = Feed(name="Counter")
25+
response = aio.create_feed(feed)
26+
27+
28+
while True:
29+
print('sending count: ', run_count)
30+
run_count += 1
31+
aio.send_data('counter', run_count)
32+
# Adafruit IO is rate-limited for publishing
33+
# so we'll need a delay for calls to aio.send_data()
34+
time.sleep(3)
35+

0 commit comments

Comments
 (0)