{"id":681,"date":"2015-07-06T17:44:31","date_gmt":"2015-07-07T00:44:31","guid":{"rendered":"http:\/\/internetofhomethings.com\/homethings\/?p=681"},"modified":"2015-10-07T13:33:52","modified_gmt":"2015-10-07T20:33:52","slug":"saving-non-volatile-max-value-thingspeak-channel-data-with-more-than-8-fields","status":"publish","type":"post","link":"https:\/\/internetofhomethings.com\/homethings\/?p=681","title":{"rendered":"ThingSpeak Channel Data With More Than 8 Fields"},"content":{"rendered":"<p><a href=\"http:\/\/internetofhomethings.com\/homethings\/wp-content\/uploads\/2015\/07\/thingspeakchannel.jpg\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-large wp-image-689\" src=\"http:\/\/internetofhomethings.com\/homethings\/wp-content\/uploads\/2015\/07\/thingspeakchannel-1024x619.jpg\" alt=\"thingspeakchannel\" width=\"620\" height=\"375\" srcset=\"https:\/\/internetofhomethings.com\/homethings\/wp-content\/uploads\/2015\/07\/thingspeakchannel-1024x619.jpg 1024w, https:\/\/internetofhomethings.com\/homethings\/wp-content\/uploads\/2015\/07\/thingspeakchannel-300x181.jpg 300w, https:\/\/internetofhomethings.com\/homethings\/wp-content\/uploads\/2015\/07\/thingspeakchannel.jpg 1030w\" sizes=\"auto, (max-width: 620px) 100vw, 620px\" \/><\/a><\/p>\n<p>Are you using ThingSpeak to capture and save your IoT device data points? Ever felt constrained by the 8 field channels limit?<\/p>\n<p>I was.<\/p>\n<p>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 &#8220;note to self&#8221;, and perhaps others who may stumble\u00a0upon this issue&#8230;<\/p>\n<h3 style=\"text-align: center;\"><strong>A Simple Solution<\/strong><\/h3>\n<p style=\"text-align: left;\">First of all, as noted, I needed more than 8 fields in my channel&#8217;s data set. But a ThingSpeak channel is limited to 8 fields.<\/p>\n<p style=\"text-align: left;\">Hmm, what to do?<\/p>\n<p style=\"text-align: left;\">While you are limited to 8 data fields, a channel is not constrained by it&#8217;s own channel data. So the answer is right there&#8230;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&#8217;s &#8220;plug-in&#8221; webpages, you have just doubled the number of \u00a0entries 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.<\/p>\n<pre>\/\/ set your channel IDs here\r\nvar channel_id1 = 12345;\r\nvar channel_id2 = 12346;\r\nvar channel_id3 = 12347;\r\n\/\/ set your channel read api keys here\r\nvar api_key1 = '9XXQ4X79WQJC72SZ';\r\nvar api_key2 = '2KJQ2Q82YTPA23CQ';\r\nvar api_key3 = '5SWQ9F87UULD86NB';\r\n\r\nfunction getData() {\r\n\/\/Get Data Set 1\r\n$.getJSON('https:\/\/api.thingspeak.com\/channels\/' + channel_id1 + '\/feed\/last.json?api_key=' + api_key1, function(data1) {\r\n    \/\/Get Data Set 2\r\n    $.getJSON('https:\/\/api.thingspeak.com\/channels\/' + channel_id2 + '\/feed\/last.json?api_key=' + api_key2, function(data2) {\r\n         \/\/Get Data Set 3\r\n         $.getJSON('https:\/\/api.thingspeak.com\/channels\/' + channel_id3 + '\/feed\/last.json?api_key=' + api_key3, function(data3) {\r\n             \/\/Do something with the data here\r\n\r\n             \/\/Save the maximum of data1.field2 and data3.field4 in data3.field4\r\n             if(data1.field2 &gt; data3.field4) {\r\n                 maxvalURL = \"https:\/\/api.thingspeak.com\/update?key=\" + api_key3 + \"&amp;field4=\" + data1.field2;\r\n                 $.post(maxvalURL);\r\n             }\r\n         });\r\n    });\r\n});\r\n<\/pre>\n<p>Note the nested jQuery &#8220;$.getJSON&#8221; to retrieve the ThingSpeak channel data. All processing needs to be performed inside the inner nest in order to keep the values in scope.<\/p>\n<p>And then there was the need to capture a value that could reset, potentially anytime. In my case, one of the\u00a0requirements\u00a0was to save a\u00a0maximum value. This value represents the device run time since it last reset. It\u00a0provides a measure of the systems reliability. In the above code example:<\/p>\n<p>current-run-time-since-last-reset = data1.field2;<\/p>\n<p>saved-max-time-since-last-reset = data3.field4;<\/p>\n<p>Instead of retrieving a constantly growing array\u00a0of values from a ThingSpeak field and then\u00a0evaluating the array for\u00a0the maximum value, the current max value is compared against the last run time value stored. This simple running &#8220;max value&#8221;\u00a0algorithm runs faster\u00a0and\u00a0requires minimal code.<\/p>\n<h3 style=\"text-align: center;\"><strong>Conclusion<\/strong><\/h3>\n<p>Scalable ThingSpeak data sets. This short post should serve as a reference&#8230;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.<\/p>\n<p>I hope you find this information useful&#8230;<\/p>\n","protected":false},"excerpt":{"rendered":"<p>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 &hellip;<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1,19],"tags":[30,46],"class_list":["post-681","post","type-post","status-publish","format-standard","hentry","category-alltheposts","category-internet-of-things","tag-thingspeak","tag-thingspeak-8-fields"],"_links":{"self":[{"href":"https:\/\/internetofhomethings.com\/homethings\/index.php?rest_route=\/wp\/v2\/posts\/681","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/internetofhomethings.com\/homethings\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/internetofhomethings.com\/homethings\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/internetofhomethings.com\/homethings\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/internetofhomethings.com\/homethings\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=681"}],"version-history":[{"count":9,"href":"https:\/\/internetofhomethings.com\/homethings\/index.php?rest_route=\/wp\/v2\/posts\/681\/revisions"}],"predecessor-version":[{"id":1031,"href":"https:\/\/internetofhomethings.com\/homethings\/index.php?rest_route=\/wp\/v2\/posts\/681\/revisions\/1031"}],"wp:attachment":[{"href":"https:\/\/internetofhomethings.com\/homethings\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=681"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/internetofhomethings.com\/homethings\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=681"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/internetofhomethings.com\/homethings\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=681"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}