Skip to content

Add push io #1

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 4 commits into from
May 1, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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