0

Retrieve dynamic values from the feed instead of 'last_value
Moderators: adafruit_support_bill, adafruit

Please be positive and constructive with your questions and comments.

Retrieve dynamic values from the feed instead of 'last_value

by dmtech on Sat Jul 27, 2019 11:59 am

I got my Pyportal to display a zapier feed which is awesome using one of your tutorials.

Using the sample code, right now it is always displaying last value, I think from the variable:

FEED_VALUE_LOCATION = ['last_value']

I've searched online and I'm not sure how to 'do math' on that string which is also an array value. I want to show on the portal the last 3 (or as many as would fit) entries; how can I reference those? ['last_value']-1 doesn't work.

dmtech
 
Posts: 2
Joined: Sat Jun 22, 2019 6:59 pm

Re: Retrieve dynamic values from the feed instead of 'last_v

by brubell on Mon Jul 29, 2019 6:47 pm

The sample code from the tutorial will display the current value, since it makes a call to Create Data(https://io.adafruit.com/api/docs/#create-data).

You would need to query the Get Previous Data (https://io.adafruit.com/api/docs/#get-previous-data) API endpoint or a query to the Adafruit IO API with an X-Pagination-Start and X-Pagination end header (https://io.adafruit.com/api/docs/?python#pagination).

You may be able to change the URL where it is requesting data from:
Code: Select all | TOGGLE FULL SIZE
DATA_SOURCE = "https://io.adafruit.com/api/v2/{0}/feeds/{1}?X-AIO-Key={2}".format(IO_USER,
                                                                                  IO_FEED, IO_KEY)

to

Code: Select all | TOGGLE FULL SIZE
DATA_SOURCE = "https://io.adafruit.com/api/v2/{0}/feeds/{1}/data/last?X-AIO-Key={2}".format(IO_USER,
                                                                                  IO_FEED, IO_KEY)


or

Code: Select all | TOGGLE FULL SIZE
DATA_SOURCE = "https://io.adafruit.com/api/v2/{0}/feeds/{1}/data/next?X-AIO-Key={2}".format(IO_USER,
                                                                                  IO_FEED, IO_KEY)

brubell
 
Posts: 471
Joined: Fri Jul 17, 2015 10:33 pm

Please be positive and constructive with your questions and comments.