does someone now a way to read the last feed data within python, and then send this data bij serial to my arduino.
what i would like to do is.
I have some counters in my arduino which keeping a total amount off pulses.
after counting a puls, it is send to my raspberry pi.
but after a restart these counters are empty, now i wan't send some kind of command to emoncms.
python checks for this command and sending the correct data to my pi.
so i will rewrite pylink.py so it feeds my needs.
now the first thing i ran in to is how do i get the data from emoncms by python to my arduino.
i tryed somthing like this.
but that doesn't work
conn.request("GET", "/"+emoncmspath+"/emoncms/feed/value.json?id=14\n")
response = conn.getresponse()
print response.read()
the response i get back is only "" there should be a value.
so i need some helping hand.
Re: read last feed data and send it to arduino with python
You are missing the API key, I use something like this
import urllib
API= "*******************" # emoncms API key
def feedval(feedid):
data_url="http://***************/emoncms/feed/value.json?apikey=" + API + "&id=" + str(feedid)
# read in the data from emoncms
try:
sock = urllib.urlopen(data_url)
data_str = sock.read()
sock.close
return float(data_str)
except Exception, detail:
print "Error ", detail
print feedval(5) # print the latest value of feed 5