I’m a master student and I’m working on a project using emoncms.org.
I have multiples feeder that monitor energy from a lab of my university for example. It is perfectly set up and every ~20 second I have a new value.
I need to write a python script that get the value from the website API.
So I tried some stuff but it’s not working:
import requests
incoming_data = requests.get(“https://emoncms.org/feed/value.json?id=369348”)
print(incoming_data)
parsed_data = incoming_data.json()
print(parsed_data)
incoming data return: <Response [406]>
and parsed_data return: URI not acceptable. No controller 'feed'. (value/)
If you want to call any of the following actions when you’re not logged in you can authenticate with an API key:
Append on the URL of your request: &apikey=APIKEY
Use POST parameter: “apikey=APIKEY”
Add the HTTP header: “Authorization: Bearer APIKEY”
API keys
There are two types of api key the write apikey and read apikey giving read & write access or read-only access. Login or create an account to obtain these keys.
Using a programatical loop you can read (via API) the [Interval] time for a given feed and and test that against the [current] system time. This will tell you when the data has been updated (and will also inform when the feed update is late for use as a timing alarm.)
I don’t want to sidetrack the current post but, Is it possible to read the feed update interval via mqtt? I use the API for monitoring feeds that miss updates, but mqtt might be more efficient.
So the feeder that I’m looking give this answer:
{‘time’: 1587153369, ‘value’: ‘224.8’}
So there is the ‘time’ value, when this value change it’s mean that the data as been updated, but in my python script I don’t know how to proceed:
Oh thanks, I modify the loop like this and it work:
inc_value = requests.get(url, headers = {‘Authorization’: ‘Bearer 5a8fc3b42672113c669318f6a0356cc6’})