Skip to content

Commit

Permalink
Merge pull request #1 from jasonlshelton/Add_Push_IO
Browse files Browse the repository at this point in the history
Add push io
  • Loading branch information
jasonlshelton authored May 1, 2019
2 parents 3da6b3c + 989d77c commit 77cd194
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 2 deletions.
34 changes: 33 additions & 1 deletion adafruit_pyportal.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@
import adafruit_touchscreen
import neopixel

from adafruit_esp32spi import adafruit_esp32spi
from adafruit_esp32spi import adafruit_esp32spi, adafruit_esp32spi_wifimanager
import adafruit_esp32spi.adafruit_esp32spi_requests as requests
try:
from adafruit_display_text.text_area import TextArea # pylint: disable=unused-import
Expand All @@ -69,6 +69,8 @@
import rtc
import supervisor

from adafruit_io.adafruit_io import RESTClient, AdafruitIO_RequestError

try:
from secrets import secrets
except ImportError:
Expand Down Expand Up @@ -252,6 +254,9 @@ def __init__(self, *, url=None, headers=None, json_path=None, regexp_path=None,
if url and not self._uselocal:
self._connect_esp()

if self._debug:
print("My IP address is", self._esp.pretty_ip(self._esp.ip_address))

# set the default background
self.set_background(self._default_bg)
board.DISPLAY.show(self.splash)
Expand Down Expand Up @@ -649,6 +654,33 @@ def image_converter_url(image_url, width, height, color_depth=16):
width, height,
color_depth, image_url)

def io_push(self, feed, data):
# pylint: disable=line-too-long
"""Push data to an adafruit.io feed
:param str feed: Name of feed to push data to.
:param data: data to send to feed
"""
# pylint: enable=line-too-long

try:
aio_username = secrets['aio_username']
aio_key = secrets['aio_key']
except KeyError:
raise KeyError("\n\n")

wifi = adafruit_esp32spi_wifimanager.ESPSPI_WiFiManager(self._esp, secrets, None)
io_connect = RESTClient(aio_username, aio_key, wifi)

try:
feed_id = io_connect.get_feed(feed)
except AdafruitIO_RequestError:
# If no feed exists, create one
feed_id = io_connect.create_new_feed(feed)

io_connect.send_data(feed_id['key'], data)

def fetch(self, refresh_url=None):
"""Fetch data from the url we initialized with, perfom any parsing,
and display text or graphics. This function does pretty much everything
Expand Down
2 changes: 1 addition & 1 deletion docs/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
autodoc_mock_imports = ["rtc", "supervisor", "pulseio", "audioio", "displayio", "neopixel",
"microcontroller", "adafruit_touchscreen", "adafruit_bitmap_font",
"adafruit_display_text", "adafruit_esp32spi", "secrets",
"adafruit_sdcard", "storage"]
"adafruit_sdcard", "storage", "adafruit_io"]


intersphinx_mapping = {'python': ('https://docs.python.org/3.4', None),'BusDevice': ('https://circuitpython.readthedocs.io/projects/busdevice/en/latest/', None),'CircuitPython': ('https://circuitpython.readthedocs.io/en/latest/', None)}
Expand Down

0 comments on commit 77cd194

Please sign in to comment.