Skip to content

Commit eebcd41

Browse files
Merge pull request #2 from jasonlshelton/Add_Push_IO
Add push io
2 parents 77cd194 + eb23859 commit eebcd41

File tree

1 file changed

+25
-11
lines changed

1 file changed

+25
-11
lines changed

adafruit_pyportal.py

+25-11
Original file line numberDiff line numberDiff line change
@@ -654,11 +654,11 @@ def image_converter_url(image_url, width, height, color_depth=16):
654654
width, height,
655655
color_depth, image_url)
656656

657-
def io_push(self, feed, data):
657+
def io_push(self, feed_key, data):
658658
# pylint: disable=line-too-long
659659
"""Push data to an adafruit.io feed
660660
661-
:param str feed: Name of feed to push data to.
661+
:param str feed_key: Name of feed to push data to.
662662
:param data: data to send to feed
663663
664664
"""
@@ -668,18 +668,32 @@ def io_push(self, feed, data):
668668
aio_username = secrets['aio_username']
669669
aio_key = secrets['aio_key']
670670
except KeyError:
671-
raise KeyError("\n\n")
671+
raise KeyError("Adafruit IO secrets are kept in secrets.py, please add them there!\n\n")
672672

673673
wifi = adafruit_esp32spi_wifimanager.ESPSPI_WiFiManager(self._esp, secrets, None)
674-
io_connect = RESTClient(aio_username, aio_key, wifi)
674+
io_client = RESTClient(aio_username, aio_key, wifi)
675675

676-
try:
677-
feed_id = io_connect.get_feed(feed)
678-
except AdafruitIO_RequestError:
679-
# If no feed exists, create one
680-
feed_id = io_connect.create_new_feed(feed)
681-
682-
io_connect.send_data(feed_id['key'], data)
676+
while True:
677+
try:
678+
feed_id = io_client.get_feed(feed_key)
679+
except AdafruitIO_RequestError:
680+
# If no feed exists, create one
681+
feed_id = io_client.create_new_feed(feed_key)
682+
except RuntimeError as exception:
683+
print("An error occured, retrying! 1 -", exception)
684+
continue
685+
break
686+
687+
while True:
688+
try:
689+
io_client.send_data(feed_id['key'], data)
690+
except RuntimeError as exception:
691+
print("An error occured, retrying! 2 -", exception)
692+
continue
693+
except NameError as exception:
694+
print(feed_id['key'], data, exception)
695+
continue
696+
break
683697

684698
def fetch(self, refresh_url=None):
685699
"""Fetch data from the url we initialized with, perfom any parsing,

0 commit comments

Comments
 (0)