ThingSpeak Channel Data With More Than 8 Fields

thingspeakchannel

Are you using ThingSpeak to capture and save your IoT device data points? Ever felt constrained by the 8 field channels limit?

I was.

All 8 of my channel fields were in use. None could be deleted. And I needed to save one additional value. But the solution was quite simple and straight-forward. This short post will serve as a reference “note to self”, and perhaps others who may stumble upon this issue…

A Simple Solution

First of all, as noted, I needed more than 8 fields in my channel’s data set. But a ThingSpeak channel is limited to 8 fields.

Hmm, what to do?

While you are limited to 8 data fields, a channel is not constrained by it’s own channel data. So the answer is right there…just add another channel and you get another group of 8 data fields. Since the additional data fields can be accessed from any of the master channel’s “plug-in” webpages, you have just doubled the number of  entries in a single record, from 8 to 16. There is really no limit to how many channels that can be added, scaling the data set upward by 8 fields for each channel added.

// set your channel IDs here
var channel_id1 = 12345;
var channel_id2 = 12346;
var channel_id3 = 12347;
// set your channel read api keys here
var api_key1 = '9XXQ4X79WQJC72SZ';
var api_key2 = '2KJQ2Q82YTPA23CQ';
var api_key3 = '5SWQ9F87UULD86NB';

function getData() {
//Get Data Set 1
$.getJSON('https://api.thingspeak.com/channels/' + channel_id1 + '/feed/last.json?api_key=' + api_key1, function(data1) {
    //Get Data Set 2
    $.getJSON('https://api.thingspeak.com/channels/' + channel_id2 + '/feed/last.json?api_key=' + api_key2, function(data2) {
         //Get Data Set 3
         $.getJSON('https://api.thingspeak.com/channels/' + channel_id3 + '/feed/last.json?api_key=' + api_key3, function(data3) {
             //Do something with the data here

             //Save the maximum of data1.field2 and data3.field4 in data3.field4
             if(data1.field2 > data3.field4) {
                 maxvalURL = "https://api.thingspeak.com/update?key=" + api_key3 + "&field4=" + data1.field2;
                 $.post(maxvalURL);
             }
         });
    });
});

Note the nested jQuery “$.getJSON” to retrieve the ThingSpeak channel data. All processing needs to be performed inside the inner nest in order to keep the values in scope.

And then there was the need to capture a value that could reset, potentially anytime. In my case, one of the requirements was to save a maximum value. This value represents the device run time since it last reset. It provides a measure of the systems reliability. In the above code example:

current-run-time-since-last-reset = data1.field2;

saved-max-time-since-last-reset = data3.field4;

Instead of retrieving a constantly growing array of values from a ThingSpeak field and then evaluating the array for the maximum value, the current max value is compared against the last run time value stored. This simple running “max value” algorithm runs faster and requires minimal code.

Conclusion

Scalable ThingSpeak data sets. This short post should serve as a reference…a reminder of just how simple and obvious it is to expand your sensor data beyond the 8-field limit imposed on a ThingSpeak channel.

I hope you find this information useful…

Share This:
Facebooktwittergoogle_plusredditpinterestlinkedintumblrFacebooktwittergoogle_plusredditpinterestlinkedintumblr
Social tagging: >

8 Responses to ThingSpeak Channel Data With More Than 8 Fields

  1. Peter says:

    I’m also struggling with updating my data from greenhouse to ThingSpeak.
    I have 15 fields that I need to update to 2 channels.
    Is it possible to share the a complete sketch?
    I have an Arduino with ESP connecting to wifi.

    • facebook-profile-picture InternetOfHomeThings says:

      I am sending some Thingspeak code that uses two sets of 8 channels for an example to your email address. Not sure what you are having issues with. Hope this example helps.

  2. Steve says:

    Thanks for this. I was wondering just how useful the service would be if the limit were eight sensors but I guess you can have as many as you want. The only limit being how often each channel can be updated. Makes sense.

    • facebook-profile-picture InternetOfHomeThings says:

      Channels updates are limited to one update every 15 seconds. But if you have 15 channels, you can update one every second and have a total of 8 X 15 = 120 data points/sensors updated every 15 seconds.

      I like to use mySQL database on my host server when lots of data is involved. php scripts are needed, of course.

  3. Peter says:

    Great solution. do you perhaps also know a way to upload a”dynamic ” api key from thingspeak to a nodemcu ? I’m looking for a way to write one basic code to my nodemcu and have other people fill in the api key later. But they will not be using an ide like arduino ide. Hope someone knowsa workaround.

    • facebook-profile-picture InternetOfHomeThings says:

      Thanks for your comment Peter.

      This post which provides a method to set configurable parameters via an ESP8266 Webpage might be of interest to you as you seek a solution to dynamically setting a Thingspeak API key. I would consider it simply another configurable parameter that would be saved in the ESP8266 EEPROM.

      As far not using the Arduino IDE or the EspressIf SDK, well, I have to say that I have long ago abandoned using the NodeMCU LUA interpreted interface. For me, it was way too restrictive; flaky, crashed a lot, did not provide sufficient memory, and more reasons not to every look back and use it again.

      But if that is your fancy, it should not be difficult to find (with a google search) a NodeMcu LUA API to read/write to the ESP8266 EEPROM. Good luck with your project!

  4. Antony Amalraj Morais says:

    $.getJason is not working for me..
    Ive been using GET Command in my program..
    but the programs outputs only field values of one channel..even after giving a considerable delay between the fetching of data between two channels..
    Please help me out as its my final year project work..

    • facebook-profile-picture InternetOfHomeThings says:

      I hope your final project worked out!

      While it is not possible to understand why it was not working as you intended without looking at your code, it is important to note the following from my post:

      "Note the nested jQuery "$.getJSON" to retrieve the ThingSpeak channel data. All processing needs to be performed inside the inner nest in order to keep the values in scope."

Leave a Reply