Upload data to ThingSpeak

I have been using sparkfun’s Phant server for data upload and retrieval for a few years since they started the service. The service was easy to use and was free. Several months back they discontinued the service, unfortunately. I started looking for suitable alternatives.

Sparkfun recommended three, ThingSpeak, Cayenne, and Blynk. I went ahead and did some research on these services. My goal is to be able to log data online and later retrieve them and possibly visualize them using google charts, like before. I am not at the moment interested in automating my home with actuators or smart phone apps to turn on and off my hall lights. Here are my findings and why I decided that ThingSpeak was the best fit. If you are logging data for later processing or visualization, read on.

ThingSpeak.com

This service is provided by the company behind Matlab. I am not a fan of expensive commercial data manipulation tools such as Matlab but they do have a fair amount of business between universities and industry so their service might be a safer way to go against sudden discontinuation of service such as sparkfun. Basically you create a data stream and send data to the stream. It’s very similar to sparkfun. You can also retrieve your data, possibly good for running your data through google chart. They also provide some basic graphs and matlab analysis tools that I have yet tried.

There are two types of application programming interfaces (APIs) you can use: a REST API, and an MQTT API.

The REST API is based on HTTP so it’s very similar to existing services elsewhere. You use HTTP GET or POST command to send data using an API key, like a private key with sparkfun. Your data are limited to up eight values per data point. If you need more, then you need to create more streams. They also have a bulk update feature that you can use to send multiple sets of data instead of one set of data. This method allows a device to collect data and sleep in between data points. Then when it collects a fair amount of data, it connects to the Internet and sends all data in one shot. It saves power and network bandwidth. You can also create and modify the properties of streams with this API.

With the MQTT API, the underlying protocol is TCP/IP. There is no acknowledgement of data received and it is intended for low-powered devices to just wake up, take data, send it out, and go back to sleep. From my tests, data sent via this method were lost over 50% of the time. Unless future holds differently, I am not recommending this API.

Getting start is easy with ThingSpeak. Just set up an account and follow their tutorial to create a new data stream. Then the following bash code should get you started posting code:

[code language=”bash”]

curl "https://api.thingspeak.com/update/?api_key=your_appkey&field1=1.23&field2=2.34"

[/code]

You can post any number of field values between 1 and 8. You will receive a zero as a positive response. Then you will see your results like the plot on the top of this page.

I have updated my Python data logging code to use ThingSpeak.com instead of the now discontinued data.sparkfun.com. The plot in this post is from Thingspeak.com. Here is a link to the data stream:

https://thingspeak.com/channels/359964

Leave a Reply

%d