I'm trying to read data from an existing channel on Thingspeak using a Python Code running on a Raspberry Pi in order to automate some devices connected to the Pi but I'm having problems finding the proper library and function that facilitates these readings.
Help anyone ?
CheerLights is a project where devices read data from the ThingSpeak channel 1417. That might point you in the right direction.
Also, this library looks to be API complete. You can read and write to ThingSpeak channels.
The problem is that there are zero examples with the lib.
What version of Python are you using?
Basic example using standard python libraries, fetching last update from a given channel. (also at https://gist.github.com/rw950431/d186bb72f7d531b76a0b in case the forum mucks up the indentation)
See https://au.mathworks.com/help/thingspeak/get-a-channel-feed.html for other variants.
CHANNEL_ID=<your channel id>
conn = urllib2.urlopen("http://api.thingspeak.com/channels/%s/feeds/last.json?api_key=%s" \
response = conn.read()
print "http status code=%s" % (conn.getcode())
if __name__ == '__main__':
If you wish to read data continuously you have 2 options
1. Wrap the above code in a loop that continually re-reads the data after a delay (at least 15 seconds, possibly more depending on your data).
2. If you have an internet-accessible device set it up as a HTTP server and set up a thingspeak react to push the data out to your device. This will (obviously) require much different code to the above.
Unfortunately, no matter how nicely everyone asks, thingspeak does not yet support MQTT or similar pub/sub protocols that would make this task very easy.
Most Users Ever Online: 114
Currently Browsing this Page:
Guest Posters: 1
Administrators: Hans, lee