Showing AIO data on a Pyportal
Re: Showing AIO data on a Pyportal
Re: Showing AIO data on a Pyportal
brubell wrote:Hi Axelmagnus,
Could you include the code you're attempting to use for fetching/displaying your Adafruit IO Data on the PyPortal. I'll take a look at it :)
- Brent R.
Re: Showing AIO data on a Pyportal
Re: Showing AIO data on a Pyportal
#receive_all_data
"""
Example of interacting with Adafruit IO feeds
"""
import board
import busio
from digitalio import DigitalInOut
# ESP32 SPI
from adafruit_esp32spi import adafruit_esp32spi, adafruit_esp32spi_wifimanager
# Import NeoPixel Library
import neopixel
# Import Adafruit IO HTTP Client
from adafruit_io.adafruit_io import IO_HTTP
# 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
# ESP32 Setup
try:
esp32_cs = DigitalInOut(board.ESP_CS)
esp32_ready = DigitalInOut(board.ESP_BUSY)
esp32_reset = DigitalInOut(board.ESP_RESET)
except AttributeError:
esp32_cs = DigitalInOut(board.D9)
esp32_ready = DigitalInOut(board.D10)
esp32_reset = DigitalInOut(board.D5)
spi = busio.SPI(board.SCK, board.MOSI, board.MISO)
esp = adafruit_esp32spi.ESP_SPIcontrol(spi, esp32_cs, esp32_ready, esp32_reset)
status_light = neopixel.NeoPixel(
board.NEOPIXEL, 1, brightness=0.2
) # Uncomment for Most Boards
"""Uncomment below for ItsyBitsy M4"""
# status_light = dotstar.DotStar(board.APA102_SCK, board.APA102_MOSI, 1, brightness=0.2)
wifi = adafruit_esp32spi_wifimanager.ESPSPI_WiFiManager(
esp, secrets, status_light)
# Set your Adafruit IO Username and Key in secrets.py
# (visit io.adafruit.com if you need to create an account,
# or if you need your Adafruit IO key.)
aio_username = secrets["aio_username"]
aio_key = secrets["aio_key"]
# Create an instance of the Adafruit IO HTTP client
io = IO_HTTP(aio_username, aio_key, wifi)
# List a specified feed
print("Retrieving new Adafruit IO feed...")
specified_feed = io.receive_all_data("lora_batteryvoltage")
print(specified_feed)
Auto-reload is on. Simply save files over USB to run them or enter REPL to disable.
code.py output:
Retrieving new Adafruit IO feed...
Socket missing recv_into. Using more memory to be compatible
[{'created_at': '2020-10-01T14:24:11Z', 'id': '0EJ3PQV7QPZX60NRVACWKGV1S6', 'expiration': '2020-11-30T15:24:11Z', 'created_epoch': 1601562251, 'feed_id': 1010762, 'value': '3.58', 'feed_key': 'lora-batteryvoltage'}, {'created_at': '2020-10-01T14:08:32Z', 'id': '0EJ3PEWQJEFB2JT9A1T71WT6CX', 'expiration': '2020-11-30T15:08:32Z', 'created_epoch': 1601561312, 'feed_id': 1010762, 'value': '3.58', 'feed_key': 'lora-batteryvoltage'}, {'created_at': '2020-10-01T13:49:58Z', 'id': '0EJ3P48S3DV9AFGET3YMPT27PN', 'expiration': '2020-11-30T14:49:58Z', 'created_epoch': 1601560198, 'feed_id': 1010762, 'value': '3.58', 'feed_key': 'lora-batteryvoltage'}, {'created_at': '2020-10-01T13:34:18Z', 'id': '0EJ3NV9TAG5TRV7Z2CXX4Q0HRB', 'expiration': '2020-11-30T14:34:18Z', 'created_epoch': 1601559258, 'feed_id': 1010762, 'value': '3.58', 'feed_key': 'lora-batteryvoltage'}, {'created_at': '2020-10-01T13:18:39Z', 'id': '0EJ3NJBBA957GQFXXFQKF521VT', 'expiration': '2020-11-30T14:18:39Z', 'created_epoch': 1601558319, 'feed_id': 1010762, 'value': '3.58', 'feed_key': 'lora-batteryvoltage'}, {'created_at': '2020-10-01T13:02:58Z', 'id': '0EJ3N9C71C5RKETJHYSD7T3435', 'expiration': '2020-11-30T14:02:58Z', 'created_epoch': 1601557378, 'feed_id': 1010762, 'value': '3.58', 'feed_key': 'lora-batteryvoltage'}, {'created_at': '2020-10-01T12:47:18Z', 'id': '0EJ3N0D7SG1109RK5FWP23FKSR', 'expiration': '2020-11-30T13:47:18Z', 'created_epoch': 1601556438, 'feed_id': 1010762, 'value': '3.58', 'feed_key': 'lora-batteryvoltage'}
Traceback (most recent call last):
File "code.py", line 56, in <module>
File "adafruit_io/adafruit_io.py", line 583, in receive_all_data
File "adafruit_io/adafruit_io.py", line 539, in _get
File "adafruit_requests.py", line 343, in json
File "adafruit_requests.py", line 339, in json
ValueError: syntax error in JSON
specified_feed = io.receive_all_data("lora-batteryvoltage")
Re: Showing AIO data on a Pyportal
Re: Showing AIO data on a Pyportal
Re: Showing AIO data on a Pyportal
print("Retrieving new Adafruit IO feed...")
specified_feed = io.receive_data("lora-batteryvoltage")
print(specified_feed)
Auto-reload is on. Simply save files over USB to run them or enter REPL to disable.
code.py output:
Retrieving new Adafruit IO feed...
Socket missing recv_into. Using more memory to be compatible
{'id': '0EJ55B84Q414124WFDJMMJWJMZ', 'feed_id': 1010762, 'location': None, 'lat': None, 'created_at': '2020-10-03T09:50:36Z', 'lon': None, 'expiration': '1606906236.0', 'ele': None, 'updated_at': '2020-10-03T09:50:36Z', 'value': '3.59'}
Re: Showing AIO data on a Pyportal
Re: Showing AIO data on a Pyportal
Buddahaid wrote:I've just run into this trying to get any of the Pyportal Pynt examples that use get_local_time to run. They all error out starting with socket missing recv_into.
Re: Showing AIO data on a Pyportal
2020-10-01 14 24 3.78
2020-10-01 14 08 4.58
2020-10-01 13 49 3.28
2020-10-01 13 34 3.88
2020-10-01 13 18 5.58
2020-10-01 13 02 1.68
2020-10-01 12 47 3.64
2020-10-01 14 24 3.78
2020-10-01 14 08 4.58
2020-10-01 13 49 3.28
2020-10-01 13 34 3.88
2020-10-01 13 18 5.58
2020-10-01 13 02 1.68
2020-10-01 12 47 3.64
Socket missing recv_into. Using more memory to be compatible
3.62
Traceback (most recent call last):
File "code.py", line 86, in <module>
File "adafruit_io/adafruit_io.py", line 591, in receive_data
File "adafruit_io/adafruit_io.py", line 536, in _get
File "adafruit_esp32spi/adafruit_esp32spi_wifimanager.py", line 225, in get
File "adafruit_requests.py", line 632, in get
File "adafruit_requests.py", line 540, in request
File "adafruit_requests.py", line 537, in request
File "adafruit_requests.py", line 458, in _send_request
File "adafruit_requests.py", line 449, in _send
File "adafruit_esp32spi/adafruit_esp32spi_socket.py", line 82, in send
File "adafruit_esp32spi/adafruit_esp32spi.py", line 710, in socket_write
RuntimeError: Failed to send 3 bytes (sent 0)
#receive_all_data worked once, latest request
#receive_dataa works once, then "adafruit_esp32spi/adafruit_esp32spi.py", line 710, in socket_write
#RuntimeError: Failed to send 3 bytes (sent 0)
#original adafruit_io_feeds
"""
Example of interacting with Adafruit IO feeds
"""
import board
import busio
import time
from digitalio import DigitalInOut
import displayio
from adafruit_display_shapes.sparkline import Sparkline
# ESP32 SPI
from adafruit_esp32spi import adafruit_esp32spi, adafruit_esp32spi_wifimanager
# Import NeoPixel Library
import neopixel
# Import Adafruit IO HTTP Client
from adafruit_io.adafruit_io import IO_HTTP
# Get wifi details and more from a secrets.py file
from secrets import secrets
# ESP32 Setup
try:
esp32_cs = DigitalInOut(board.ESP_CS)
esp32_ready = DigitalInOut(board.ESP_BUSY)
esp32_reset = DigitalInOut(board.ESP_RESET)
except AttributeError:
esp32_cs = DigitalInOut(board.D9)
esp32_ready = DigitalInOut(board.D10)
esp32_reset = DigitalInOut(board.D5)
spi = busio.SPI(board.SCK, board.MOSI, board.MISO)
esp = adafruit_esp32spi.ESP_SPIcontrol(spi, esp32_cs, esp32_ready, esp32_reset)
status_light = neopixel.NeoPixel(
board.NEOPIXEL, 1, brightness=0.2
) # Uncomment for Most Boards
wifi = adafruit_esp32spi_wifimanager.ESPSPI_WiFiManager(
esp, secrets, status_light)
aio_username = secrets["aio_username"]
aio_key = secrets["aio_key"]
# Create an instance of the Adafruit IO HTTP client
io = IO_HTTP(aio_username, aio_key, wifi)
display = board.DISPLAY
DISPLAY_WIDTH = board.DISPLAY.width
chart_width = 200
chart_height = 100
sparkline = Sparkline(
width=DISPLAY_WIDTH - 30,
height=chart_height ,
max_items=10,
x=0,
y=120,
color=0xFFFFFF
)
my_group = displayio.Group(max_size=20)
my_group.append(sparkline)
#display.show(my_group)
recv_all=[{'created_at': '2020-10-01T14:24:11Z', 'id': '0EJ3PQV7QPZX60NRVACWKGV1S6', 'expiration': '2020-11-30T15:24:11Z', 'created_epoch': 1601562251, 'feed_id': 1010762, 'value': '3.78', 'feed_key': 'lora-batteryvoltage'}, {'created_at': '2020-10-01T14:08:32Z', 'id': '0EJ3PEWQJEFB2JT9A1T71WT6CX', 'expiration': '2020-11-30T15:08:32Z', 'created_epoch': 1601561312, 'feed_id': 1010762, 'value': '4.58', 'feed_key': 'lora-batteryvoltage'}, {'created_at': '2020-10-01T13:49:58Z', 'id': '0EJ3P48S3DV9AFGET3YMPT27PN', 'expiration': '2020-11-30T14:49:58Z', 'created_epoch': 1601560198, 'feed_id': 1010762, 'value': '3.28', 'feed_key': 'lora-batteryvoltage'}, {'created_at': '2020-10-01T13:34:18Z', 'id': '0EJ3NV9TAG5TRV7Z2CXX4Q0HRB', 'expiration': '2020-11-30T14:34:18Z', 'created_epoch': 1601559258, 'feed_id': 1010762, 'value': '3.88', 'feed_key': 'lora-batteryvoltage'}, {'created_at': '2020-10-01T13:18:39Z', 'id': '0EJ3NJBBA957GQFXXFQKF521VT', 'expiration': '2020-11-30T14:18:39Z', 'created_epoch': 1601558319, 'feed_id': 1010762, 'value': '5.58', 'feed_key': 'lora-batteryvoltage'}, {'created_at': '2020-10-01T13:02:58Z', 'id': '0EJ3N9C71C5RKETJHYSD7T3435', 'expiration': '2020-11-30T14:02:58Z', 'created_epoch': 1601557378, 'feed_id': 1010762, 'value': '1.68', 'feed_key': 'lora-batteryvoltage'}, {'created_at': '2020-10-01T12:47:18Z', 'id': '0EJ3N0D7SG1109RK5FWP23FKSR', 'expiration': '2020-11-30T13:47:18Z', 'created_epoch': 1601556438, 'feed_id': 1010762, 'value': '3.64', 'feed_key': 'lora-batteryvoltage'},{'created_at': '2020-10-01T14:24:11Z', 'id': '0EJ3PQV7QPZX60NRVACWKGV1S6', 'expiration': '2020-11-30T15:24:11Z', 'created_epoch': 1601562251, 'feed_id': 1010762, 'value': '3.78', 'feed_key': 'lora-batteryvoltage'}, {'created_at': '2020-10-01T14:08:32Z', 'id': '0EJ3PEWQJEFB2JT9A1T71WT6CX', 'expiration': '2020-11-30T15:08:32Z', 'created_epoch': 1601561312, 'feed_id': 1010762, 'value': '4.58', 'feed_key': 'lora-batteryvoltage'}, {'created_at': '2020-10-01T13:49:58Z', 'id': '0EJ3P48S3DV9AFGET3YMPT27PN', 'expiration': '2020-11-30T14:49:58Z', 'created_epoch': 1601560198, 'feed_id': 1010762, 'value': '3.28', 'feed_key': 'lora-batteryvoltage'}, {'created_at': '2020-10-01T13:34:18Z', 'id': '0EJ3NV9TAG5TRV7Z2CXX4Q0HRB', 'expiration': '2020-11-30T14:34:18Z', 'created_epoch': 1601559258, 'feed_id': 1010762, 'value': '3.88', 'feed_key': 'lora-batteryvoltage'}, {'created_at': '2020-10-01T13:18:39Z', 'id': '0EJ3NJBBA957GQFXXFQKF521VT', 'expiration': '2020-11-30T14:18:39Z', 'created_epoch': 1601558319, 'feed_id': 1010762, 'value': '5.58', 'feed_key': 'lora-batteryvoltage'}, {'created_at': '2020-10-01T13:02:58Z', 'id': '0EJ3N9C71C5RKETJHYSD7T3435', 'expiration': '2020-11-30T14:02:58Z', 'created_epoch': 1601557378, 'feed_id': 1010762, 'value': '1.68', 'feed_key': 'lora-batteryvoltage'}, {'created_at': '2020-10-01T12:47:18Z', 'id': '0EJ3N0D7SG1109RK5FWP23FKSR', 'expiration': '2020-11-30T13:47:18Z', 'created_epoch': 1601556438, 'feed_id': 1010762, 'value': '3.84', 'feed_key': 'lora-batteryvoltage'}]
print("Retrieving new Adafruit IO feed...")
print(recv_all[0]['value'])
for index, item in enumerate(recv_all):
date, t = item['created_at'].split("T") #date and time
h, m , s= t.split(":") #hours and minutes
value=item['value']
sparkline.add_value(float(value))
print(date,h,m,float(value))
display.show(my_group)
while True:
lastdata = io.receive_data("lora-batteryvoltage")
print(lastdata['value'])
sparkline.add_value(float(lastdata['value']))
display.auto_refresh = True
time.sleep(60)
Re: Showing AIO data on a Pyportal
axelmagnus wrote:Buddahaid wrote:I've just run into this trying to get any of the Pyportal Pynt examples that use get_local_time to run. They all error out starting with socket missing recv_into.
Have you seen this:
viewtopic.php?f=60&t=169654
Re: Showing AIO data on a Pyportal
Re: Showing AIO data on a Pyportal
Re: Showing AIO data on a Pyportal