I'm trying to display my data from AdafruitIO to my PyPortal. I would love it to be graphical, but I think text based is a good place to start. So, I had some code modified by a wonderful Adafruit admin for this to even work on my Portal.... but it is returning cryptic data that I can't figure out.
The data is a from an SGP30, so it has eCO2 and TVOC. The code is as such:
Code: Select all
import time
import board
import busio
from digitalio import DigitalInOut
import neopixel
from adafruit_esp32spi import adafruit_esp32spi
from adafruit_esp32spi import adafruit_esp32spi_wifimanager
print("ESP32 SPI webclient test")
# Get wifi details and more from a secrets.py file
try:
from secrets import secrets
except ImportError:
print("WiFi secrets are kept in secrets.py, please add them there!")
raise
# If you are using a board with pre-defined ESP32 Pins:
esp32_cs = DigitalInOut(board.ESP_CS)
esp32_ready = DigitalInOut(board.ESP_BUSY)
esp32_reset = DigitalInOut(board.ESP_RESET)
spi = busio.SPI(board.SCK, board.MOSI, board.MISO)
esp = adafruit_esp32spi.ESP_SPIcontrol(spi, esp32_cs, esp32_ready, esp32_reset)
"""Use below for Most Boards"""
status_light = neopixel.NeoPixel(
board.NEOPIXEL, 1, brightness=0.2
) # Uncomment for Most Boards
wifi = adafruit_esp32spi_wifimanager.ESPSPI_WiFiManager(esp, secrets, status_light)
counter = 0
while True:
try:
print("Posting data...", end="")
data = counter
feed = "rx"
payload = {"value": data}
response = wifi.post(
"https://io.adafruit.com/api/v2/"
+ secrets["aio_username"]
+ "/feeds/"
+ feed
+ "/data",
json=payload,
headers={"X-AIO-KEY": secrets["aio_key"]},
)
print(response.json())
response.close()
counter = counter + 1
print("OK")
except (ValueError, RuntimeError) as e:
print("Failed to get data, retrying\n", e)
wifi.reset()
continue
response = None
time.sleep(15)
OK
Posting data...{'created_at': '2021-03-12T22:08:39Z', 'id': '0EP6ADG8E1ERK0X61Y88991DEB', 'expiration': '2021-04-11T21:08:39Z', 'created_epoch': 1615586919, 'feed_id': 1437718, 'value': '5', 'feed_key': 'rx'}
I have no idea what any of that is or even where to begin to parse it.
If you want to see my feeds page I'm trying to display, it is: https://io.adafruit.com/oldblackcrow/feeds/rx
Anyone know what's going on? Thanks so much!