{"id":5469,"date":"2014-08-08T09:00:07","date_gmt":"2014-08-08T13:00:07","guid":{"rendered":"https:\/\/blogs.mathworks.com\/pick\/?p=5469"},"modified":"2018-02-15T16:56:53","modified_gmt":"2018-02-15T21:56:53","slug":"thingspeak-support-for-matlab","status":"publish","type":"post","link":"https:\/\/blogs.mathworks.com\/pick\/2014\/08\/08\/thingspeak-support-for-matlab\/","title":{"rendered":"ThingSpeak Support for MATLAB"},"content":{"rendered":"<div class=\"content\">\r\n\r\n<a href=\"https:\/\/www.mathworks.com\/matlabcentral\/answers\/contributors\/3208495\">Sean<\/a>'s pick this week is <a href=\"https:\/\/www.mathworks.com\/matlabcentral\/fileexchange\/46714-thingspeak-support-from-matlab--r2013a-r2014a-\">ThingSpeak Support for MATLAB<\/a> by <a href=\"https:\/\/www.mathworks.com\/matlabcentral\/fileexchange\/authors\/473889\">MathWorks' Internet of Things Team<\/a>.\r\n\r\n&nbsp;\r\n<h3>Contents<\/h3>\r\n<div>\r\n<ul>\r\n \t<li><a href=\"#1\">The Internet of Things<\/a><\/li>\r\n \t<li><a href=\"#2\">Powerade<\/a><\/li>\r\n \t<li><a href=\"#3\">Download the Data<\/a><\/li>\r\n \t<li><a href=\"#4\">Visualize<\/a><\/li>\r\n \t<li><a href=\"#6\">Comments<\/a><\/li>\r\n<\/ul>\r\n<\/div>\r\n<h3>The Internet of Things<a name=\"1\"><\/a><\/h3>\r\nUp until recently, I'd heard the phrase the \"internet of things\" thrown around only a few times and didn't really know what\r\nit meant. So I spoke with our Marketing Manager for the Maker Movement, <a href=\"https:\/\/blogs.mathworks.com\/community\/2013\/07\/09\/anamorphic-3d-printing\/\">Paul Kassebaum<\/a>, to get a better understanding. Paul describes it briefly as \"The confluence of technologies in communication (the internet\r\nas we know it), the energy internet (or energy from sensors, etc.) and the logistics internet (the ability to use this information\r\nfor logistics).\"\r\n\r\nThis week's pick uses all three. It allows you to pull data directly into MATLAB from <a href=\"https:\/\/thingspeak.com\/\">ThingSpeak<\/a>, a platform and cloud service where data can be uploaded from sensors and low cost hardware. After pulling this data, you\r\ncan use it for whatever research, design or logistics you want.\r\n<h3>Powerade<a name=\"2\"><\/a><\/h3>\r\nI saw <a href=\"https:\/\/www.mathworks.com\/\/matlabcentral\/fileexchange\/47038\">this<\/a> submission on File Exchange that described measuring soda consumption here at MathWorks. \r\n\r\nThis made a challenge for me: Could I gather a few people together, drink as much Powerade as possible at 4pm Eastern Time\r\non August 5th, and create an outlier data point?\r\n\r\nWe had a few detractors, like <a href=\"https:\/\/blogs.mathworks.com\/loren\/\">Loren<\/a>, who did not properly appreciate the health benefits of this type of social gathering.\r\n\r\n<img decoding=\"async\" src=\"https:\/\/blogs.mathworks.com\/images\/pick\/Sean\/mainthingspeak\/poweradeparty.PNG\" hspace=\"5\" vspace=\"5\" \/>\r\n\r\nTo passerbyers, it probably looked like we were part of some obscure MATLAB cult. Let's see how we did:\r\n<h3>Download the Data<a name=\"3\"><\/a><\/h3>\r\n<pre style=\"background: #F9F7F3; padding: 10px; border: 1px solid #c8c8c8;\"><span style=\"color: #228b22;\">% Grab the data for July 6th through August 6th.<\/span>\r\n[drinkData, timeStamps] = thingSpeakFetch(7040,<span style=\"color: #a020f0;\">'DateRange'<\/span>,{<span style=\"color: #a020f0;\">'06-July-2014'<\/span>,<span style=\"color: #a020f0;\">'06-August-2014'<\/span>});\r\nPowerade = drinkData(:,3); <span style=\"color: #228b22;\">% Third channel is Powerade<\/span>\r\n\r\n<span style=\"color: #228b22;\">% Index into the party hour<\/span>\r\nidxParty = hour(timeStamps)==16 &amp; day(timeStamps) == 5 &amp; month(timeStamps)==8;<\/pre>\r\n<h3>Visualize<a name=\"4\"><\/a><\/h3>\r\n<pre style=\"background: #F9F7F3; padding: 10px; border: 1px solid #c8c8c8;\">scatter(timeStamps(idxParty),Powerade(idxParty),400,<span style=\"color: #a020f0;\">'MarkerFaceColor'<\/span>,[0.03 0.6 0.8],<span style=\"color: #a020f0;\">'MarkerEdgeColor'<\/span>,[0.03 0.6 0.8]);\r\nhold <span style=\"color: #a020f0;\">on<\/span>\r\nscatter(timeStamps,Powerade,15,<span style=\"color: #a020f0;\">'MarkerFaceColor'<\/span>,[0.5 0 0],<span style=\"color: #a020f0;\">'MarkerEdgeColor'<\/span>,[0.5 0 0]);\r\ndatetick(<span style=\"color: #a020f0;\">'x'<\/span>,<span style=\"color: #a020f0;\">'mmmdd'<\/span>,<span style=\"color: #a020f0;\">'keepticks'<\/span>,<span style=\"color: #a020f0;\">'keeplimits'<\/span>);\r\nlegend(<span style=\"color: #a020f0;\">'Powerade Party'<\/span>,<span style=\"color: #a020f0;\">'Powerade Consumption'<\/span>,<span style=\"color: #a020f0;\">'location'<\/span>,<span style=\"color: #a020f0;\">'northwest'<\/span>)<\/pre>\r\n<img decoding=\"async\" src=\"https:\/\/blogs.mathworks.com\/images\/pick\/Sean\/mainthingspeak\/mainthingspeak_01.png\" hspace=\"5\" vspace=\"5\" \/>\r\n\r\nSo it does look like we were able to create a Powerade Consumption outlier. Go Team!\r\n<h3>Comments<a name=\"6\"><\/a><\/h3>\r\nGive it a try and let us know what you think <a href=\"https:\/\/blogs.mathworks.com\/pick\/?p=5469#respond\">here<\/a> or leave a <a href=\"https:\/\/www.mathworks.com\/matlabcentral\/fileexchange\/46714-thingspeak-support-from-matlab--r2013a-r2014a-#comments\">comment<\/a> for our Internet of Things team.\r\n\r\n<script language=\"JavaScript\">\r\n<!--\r\n\r\n    function grabCode_753ca525e18a4f85aa908f1db8f630e3() {\r\n        \/\/ Remember the title so we can use it in the new page\r\n        title = document.title;\r\n\r\n        \/\/ Break up these strings so that their presence\r\n        \/\/ in the Javascript doesn't mess up the search for\r\n        \/\/ the MATLAB code.\r\n        t1='753ca525e18a4f85aa908f1db8f630e3 ' + '##### ' + 'SOURCE BEGIN' + ' #####';\r\n        t2='##### ' + 'SOURCE END' + ' #####' + ' 753ca525e18a4f85aa908f1db8f630e3';\r\n    \r\n        b=document.getElementsByTagName('body')[0];\r\n        i1=b.innerHTML.indexOf(t1)+t1.length;\r\n        i2=b.innerHTML.indexOf(t2);\r\n \r\n        code_string = b.innerHTML.substring(i1, i2);\r\n        code_string = code_string.replace(\/REPLACE_WITH_DASH_DASH\/g,'--');\r\n\r\n        \/\/ Use \/x3C\/g instead of the less-than character to avoid errors \r\n        \/\/ in the XML parser.\r\n        \/\/ Use '\\x26#60;' instead of '<' so that the XML parser\r\n        \/\/ doesn't go ahead and substitute the less-than character. \r\n        code_string = code_string.replace(\/\\x3C\/g, '\\x26#60;');\r\n\r\n        author = 'Sean de Wolski';\r\n        copyright = 'Copyright 2014 The MathWorks, Inc.';\r\n\r\n        w = window.open();\r\n        d = w.document;\r\n        d.write('<\/p>\r\n<pre>\\n');\r\n        d.write(code_string);\r\n\r\n        \/\/ Add author and copyright lines at the bottom if specified.\r\n        if ((author.length > 0) || (copyright.length > 0)) {\r\n            d.writeln('');\r\n            d.writeln('%%');\r\n            if (author.length > 0) {\r\n                d.writeln('% _' + author + '_');\r\n            }\r\n            if (copyright.length > 0) {\r\n                d.writeln('% _' + copyright + '_');\r\n            }\r\n        }\r\n\r\n        d.write('<\/pre>\r\n<p>\\n');\r\n      \r\n      d.title = title + ' (MATLAB code)';\r\n      d.close();\r\n      }   \r\n      \r\n-->\r\n<\/script>\r\n<p style=\"text-align: right; font-size: xx-small; font-weight: lighter; font-style: italic; color: gray;\">\r\n<a><span style=\"font-size: x-small; font-style: italic;\">Get\r\nthe MATLAB code\r\n<noscript>(requires JavaScript)<\/noscript><\/span><\/a>\r\n\r\nPublished with MATLAB\u00ae R2014a<\/p>\r\n\r\n<\/div>\r\n<!--\r\n753ca525e18a4f85aa908f1db8f630e3 ##### SOURCE BEGIN #####\r\n%% The Internet of Things and ThingSpeak\r\n%\r\n% <https:\/\/www.mathworks.com\/matlabcentral\/answers\/contributors\/3208495 Sean>'s pick this week is\r\n% <https:\/\/www.mathworks.com\/matlabcentral\/fileexchange\/46714-thingspeak-support-from-matlab--r2013a-r2014a- ThingSpeak Support for MATLAB> by\r\n% <https:\/\/www.mathworks.com\/matlabcentral\/fileexchange\/authors\/473889 MathWorks' Internet of Things Team>.\r\n%\r\n\r\n%% The Internet of Things\r\n%\r\n% Up until recently, I'd heard the phrase the \"internet of things\" thrown\r\n% around only a few times and didn't really know what it meant. So I spoke\r\n% with our Marketing Manager for the Maker Movement,\r\n% <https:\/\/blogs.mathworks.com\/community\/2013\/07\/09\/anamorphic-3d-printing\/ % Paul Kassebaum>, to get a better understanding.  Paul describes it\r\n% briefly as \"The confluence of technologies in communication (the internet\r\n% as we know it), the energy internet (or energy from sensors, etc.) and the\r\n% logistics internet (the ability to use this information for logistics).\"\r\n%\r\n% This week's pick uses all three.  It allows you to pull data directly\r\n% into MATLAB from <https:\/\/thingspeak.com\/ ThingSpeak>, a platform\r\n% and cloud service where data can be uploaded from sensors and low cost\r\n% hardware.  After pulling this data, you can use it for whatever research,\r\n% design or logistics you want.\r\n\r\n%% Powerade\r\n%\r\n% I saw\r\n% <http:\/\/makerzone.mathworks.com\/resources\/arduino\/soda-machine-analyzer\/ % this> blog post on our Maker Zone blog that described measuring soda\r\n% consumption here at MathWorks.  They posted the\r\n% <https:\/\/www.mathworks.com\/matlabcentral\/fileexchange\/47038-analyzing-soda-drinking-behavior-using-thingspeak-and-matlab file> on the\r\n% FEX as well.\r\n%\r\n% This made a challenge for me: Could I gather a few people together, drink\r\n% as much Powerade as possible at 4pm Eastern Time on August 5th, and\r\n% create an outlier data point?\r\n%\r\n% We had a few detractors, like <https:\/\/blogs.mathworks.com\/loren\/ Loren>,\r\n% who did not properly appreciate the health benefits of this type of\r\n% social gathering.\r\n%\r\n% <<poweradeparty.PNG>>\r\n%\r\n% To passerbyers, it probably looked like we were part of some obscure\r\n% MATLAB cult.  Let's see how we did:\r\n%\r\n\r\n%% Download the Data\r\n\r\n% Grab the data for July 6th through August 6th.\r\n[drinkData, timeStamps] = thingSpeakFetch(7040,'DateRange',{'06-July-2014','06-August-2014'});\r\nPowerade = drinkData(:,3); % Third channel is Powerade\r\n\r\n% Index into the party hour\r\nidxParty = hour(timeStamps)==16 & day(timeStamps) == 5 & month(timeStamps)==8;\r\n\r\n%% Visualize\r\n\r\nscatter(timeStamps(idxParty),Powerade(idxParty),400,'MarkerFaceColor',[0.03 0.6 0.8],'MarkerEdgeColor',[0.03 0.6 0.8]);\r\nhold on\r\nscatter(timeStamps,Powerade,15,'MarkerFaceColor',[0.5 0 0],'MarkerEdgeColor',[0.5 0 0]);\r\ndatetick('x','mmmdd','keepticks','keeplimits');\r\nlegend('Powerade Party','Powerade Consumption','location','northwest')\r\n\r\n%%\r\n% So it does look like we were able to create a Powerade Consumption\r\n% outlier.  Go Team!\r\n\r\n%% Comments\r\n%\r\n% Give it a try and let us know what you think\r\n% <https:\/\/blogs.mathworks.com\/pick\/?p=5469#respond here> or leave a\r\n% <https:\/\/www.mathworks.com\/matlabcentral\/fileexchange\/46714-thingspeak-support-from-matlab--r2013a-r2014a-#comments % comment> for our Internet of Things team.\r\n%\r\n\r\n##### SOURCE END ##### 753ca525e18a4f85aa908f1db8f630e3\r\n-->","protected":false},"excerpt":{"rendered":"<div class=\"overview-image\"><img decoding=\"async\"  class=\"img-responsive\" src=\"https:\/\/blogs.mathworks.com\/images\/pick\/Sean\/mainthingspeak\/poweradeparty.PNG\" onError=\"this.style.display ='none';\" \/><\/div><p>\r\n\r\nSean's pick this week is ThingSpeak Support for MATLAB by MathWorks' Internet of Things Team.\r\n\r\n&nbsp;\r\nContents\r\n\r\n\r\n \tThe Internet of Things\r\n \tPowerade\r\n \tDownload the Data\r\n \tVisualize\r\n... <a class=\"read-more\" href=\"https:\/\/blogs.mathworks.com\/pick\/2014\/08\/08\/thingspeak-support-for-matlab\/\">read more >><\/a><\/p>","protected":false},"author":87,"featured_media":0,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":[],"categories":[32,30,16],"tags":[],"_links":{"self":[{"href":"https:\/\/blogs.mathworks.com\/pick\/wp-json\/wp\/v2\/posts\/5469"}],"collection":[{"href":"https:\/\/blogs.mathworks.com\/pick\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/blogs.mathworks.com\/pick\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/blogs.mathworks.com\/pick\/wp-json\/wp\/v2\/users\/87"}],"replies":[{"embeddable":true,"href":"https:\/\/blogs.mathworks.com\/pick\/wp-json\/wp\/v2\/comments?post=5469"}],"version-history":[{"count":9,"href":"https:\/\/blogs.mathworks.com\/pick\/wp-json\/wp\/v2\/posts\/5469\/revisions"}],"predecessor-version":[{"id":9472,"href":"https:\/\/blogs.mathworks.com\/pick\/wp-json\/wp\/v2\/posts\/5469\/revisions\/9472"}],"wp:attachment":[{"href":"https:\/\/blogs.mathworks.com\/pick\/wp-json\/wp\/v2\/media?parent=5469"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/blogs.mathworks.com\/pick\/wp-json\/wp\/v2\/categories?post=5469"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/blogs.mathworks.com\/pick\/wp-json\/wp\/v2\/tags?post=5469"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}