|
53 | 53 | import adafruit_touchscreen
|
54 | 54 | import neopixel
|
55 | 55 |
|
56 |
| -from adafruit_esp32spi import adafruit_esp32spi |
| 56 | +from adafruit_esp32spi import adafruit_esp32spi, adafruit_esp32spi_wifimanager |
57 | 57 | import adafruit_esp32spi.adafruit_esp32spi_requests as requests
|
58 | 58 | try:
|
59 | 59 | from adafruit_display_text.text_area import TextArea # pylint: disable=unused-import
|
|
69 | 69 | import rtc
|
70 | 70 | import supervisor
|
71 | 71 |
|
| 72 | +from adafruit_io.adafruit_io import RESTClient, AdafruitIO_RequestError |
| 73 | + |
72 | 74 | try:
|
73 | 75 | from secrets import secrets
|
74 | 76 | except ImportError:
|
@@ -252,6 +254,9 @@ def __init__(self, *, url=None, headers=None, json_path=None, regexp_path=None,
|
252 | 254 | if url and not self._uselocal:
|
253 | 255 | self._connect_esp()
|
254 | 256 |
|
| 257 | + if self._debug: |
| 258 | + print("My IP address is", self._esp.pretty_ip(self._esp.ip_address)) |
| 259 | + |
255 | 260 | # set the default background
|
256 | 261 | self.set_background(self._default_bg)
|
257 | 262 | board.DISPLAY.show(self.splash)
|
@@ -649,6 +654,33 @@ def image_converter_url(image_url, width, height, color_depth=16):
|
649 | 654 | width, height,
|
650 | 655 | color_depth, image_url)
|
651 | 656 |
|
| 657 | + def io_push(self, feed, data): |
| 658 | + # pylint: disable=line-too-long |
| 659 | + """Push data to an adafruit.io feed |
| 660 | +
|
| 661 | + :param str feed: Name of feed to push data to. |
| 662 | + :param data: data to send to feed |
| 663 | +
|
| 664 | + """ |
| 665 | + # pylint: enable=line-too-long |
| 666 | + |
| 667 | + try: |
| 668 | + aio_username = secrets['aio_username'] |
| 669 | + aio_key = secrets['aio_key'] |
| 670 | + except KeyError: |
| 671 | + raise KeyError("\n\n") |
| 672 | + |
| 673 | + wifi = adafruit_esp32spi_wifimanager.ESPSPI_WiFiManager(self._esp, secrets, None) |
| 674 | + io_connect = RESTClient(aio_username, aio_key, wifi) |
| 675 | + |
| 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) |
| 683 | + |
652 | 684 | def fetch(self, refresh_url=None):
|
653 | 685 | """Fetch data from the url we initialized with, perfom any parsing,
|
654 | 686 | and display text or graphics. This function does pretty much everything
|
|
0 commit comments