{"id":3388,"date":"2019-07-09T08:31:16","date_gmt":"2019-07-09T13:31:16","guid":{"rendered":"https:\/\/blogs.mathworks.com\/loren\/?p=3388"},"modified":"2019-07-09T08:31:16","modified_gmt":"2019-07-09T13:31:16","slug":"internet-of-things-how-to-get-started","status":"publish","type":"post","link":"https:\/\/blogs.mathworks.com\/loren\/2019\/07\/09\/internet-of-things-how-to-get-started\/","title":{"rendered":"Internet of Things &#8211; How to Get Started"},"content":{"rendered":"\r\n<div class=\"content\"><!--introduction--><p>I'm sure you've heard of IoT, Internet of Things. And people talk about connected devices, and getting the data from them to use in applications. I want to show you a very simple example to spark some ideas in each of you.<\/p><!--\/introduction--><h3>Contents<\/h3><div><ul><li><a href=\"#219bfb31-d9f9-4406-b39b-1e4fd0794db3\">Example<\/a><\/li><li><a href=\"#c8fcc086-b71b-4679-9f07-466406c05bbb\">IoT<\/a><\/li><\/ul><\/div><h4>Example<a name=\"219bfb31-d9f9-4406-b39b-1e4fd0794db3\"><\/a><\/h4><p>IoT allows you access or serve data that is not local to users who want to use it.  We have the <a href=\"https:\/\/www.mathworks.com\/products\/thingspeak.html\">ThingSpeak<\/a> portion of our website that you can use to access and analyze live streamed data in the cloud. And we recently added the ability to access these same channels of information directly from a MATLAB session when you have internet access. Here's an example of <a href=\"https:\/\/thingspeak.com\/channels\/12397\">some simple weather day<\/a> you can access, including windspeed (mph), humidity, and temperature (F). The first thing I'll do is grab these 3 channels of information for 3 days.<\/p><pre class=\"codeinput\">data = thingSpeakRead(12397,<span class=\"string\">'Fields'<\/span>,2:4,<span class=\"string\">'NumDays'<\/span>,3,<span class=\"string\">'OutputFormat'<\/span>, <span class=\"keyword\">...<\/span>\r\n       <span class=\"string\">'TimeTable'<\/span>);\r\n<\/pre><p>Let's preview the data with <tt><a href=\"https:\/\/www.mathworks.com\/help\/matlab\/ref\/topkrows.html\">topkrows<\/a><\/tt>.<\/p><pre class=\"codeinput\">topkrows(data,8)\r\n<\/pre><pre class=\"codeoutput\">ans =\r\n  8&times;3 timetable\r\n         Timestamps         WindSpeedmph    Humidity    TemperatureF\r\n    ____________________    ____________    ________    ____________\r\n    09-Jul-2019 09:29:03        3.3            36           82.4    \r\n    09-Jul-2019 09:28:02        4.2            37           82.3    \r\n    09-Jul-2019 09:27:01          5            37           82.3    \r\n    09-Jul-2019 09:25:59        2.8            37           82.2    \r\n    09-Jul-2019 09:24:58        2.9            37           82.1    \r\n    09-Jul-2019 09:23:58        4.3            37           82.1    \r\n    09-Jul-2019 09:22:55        2.8            37           82.1    \r\n    09-Jul-2019 09:21:54        2.8            37           81.9    \r\n<\/pre><p>I asked for the data to be returned in a <tt><a href=\"https:\/\/www.mathworks.com\/help\/matlab\/ref\/timetable.html\">timetable<\/a><\/tt>. How many points did I collect?<\/p><pre class=\"codeinput\">numDataPoints = height(data)\r\n<\/pre><pre class=\"codeoutput\">numDataPoints =\r\n        4228\r\n<\/pre><p>Let's look at the data now.  It's interesting to compare the trends of the data we chose to view.  I'm using a <tt><a href=\"https:\/\/www.mathworks.com\/help\/matlab\/ref\/stackedplot.html\">stackedplot<\/a><\/tt><\/p><pre class=\"codeinput\">h = stackedplot(data);\r\n<\/pre><img decoding=\"async\" vspace=\"5\" hspace=\"5\" src=\"https:\/\/blogs.mathworks.com\/images\/loren\/2019\/iotDemo_01.png\" alt=\"\"> <h4>IoT<a name=\"c8fcc086-b71b-4679-9f07-466406c05bbb\"><\/a><\/h4><p>If you are interested in learning more about IoT with MATLAB, I highly recommend reading <a href=\"https:\/\/blogs.mathworks.com\/iot\/\">Hans's blog<\/a>.<\/p><p>Let me know how you might take advantage of ThingSpeak <a href=\"https:\/\/blogs.mathworks.com\/loren\/?p=3388#respond\">here<\/a>.<\/p><script language=\"JavaScript\"> <!-- \r\n    function grabCode_fff60df087284d05b677a85192926e57() {\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='fff60df087284d05b677a85192926e57 ' + '##### ' + 'SOURCE BEGIN' + ' #####';\r\n        t2='##### ' + 'SOURCE END' + ' #####' + ' fff60df087284d05b677a85192926e57';\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        copyright = 'Copyright 2019 The MathWorks, Inc.';\r\n\r\n        w = window.open();\r\n        d = w.document;\r\n        d.write('<pre>\\n');\r\n        d.write(code_string);\r\n\r\n        \/\/ Add copyright line at the bottom if specified.\r\n        if (copyright.length > 0) {\r\n            d.writeln('');\r\n            d.writeln('%%');\r\n            if (copyright.length > 0) {\r\n                d.writeln('% _' + copyright + '_');\r\n            }\r\n        }\r\n\r\n        d.write('<\/pre>\\n');\r\n\r\n        d.title = title + ' (MATLAB code)';\r\n        d.close();\r\n    }   \r\n     --> <\/script><p style=\"text-align: right; font-size: xx-small; font-weight:lighter;   font-style: italic; color: gray\"><br><a href=\"javascript:grabCode_fff60df087284d05b677a85192926e57()\"><span style=\"font-size: x-small;        font-style: italic;\">Get \r\n      the MATLAB code <noscript>(requires JavaScript)<\/noscript><\/span><\/a><br><br>\r\n      Published with MATLAB&reg; R2019a<br><\/p><\/div><!--\r\nfff60df087284d05b677a85192926e57 ##### SOURCE BEGIN #####\r\n%% Internet of Things - How to Get Started\r\n% I'm sure you've heard of IoT, Internet of Things. And people talk about\r\n% connected devices, and getting the data from them to use in applications.\r\n% I want to show you a very simple example to spark some ideas in each of\r\n% you.\r\n%% Example\r\n% IoT allows you access or serve data that is not local to users who want\r\n% to use it.  We have the\r\n% <https:\/\/www.mathworks.com\/products\/thingspeak.html ThingSpeak> portion\r\n% of our website that you can use to access and analyze live streamed data\r\n% in the cloud. And we recently added the ability to access these same\r\n% channels of information directly from a MATLAB session when you have\r\n% internet access. Here's an example of\r\n% <https:\/\/thingspeak.com\/channels\/12397 some simple weather day> you can\r\n% access, including windspeed (mph), humidity, and temperature (F). The\r\n% first thing I'll do is grab these 3 channels of information for 3 days.\r\ndata = thingSpeakRead(12397,'Fields',2:4,'NumDays',3,'OutputFormat', ...\r\n       'TimeTable');\r\n%%\r\n% Let's preview the data with\r\n% |<https:\/\/www.mathworks.com\/help\/matlab\/ref\/topkrows.html topkrows>|.\r\ntopkrows(data,8)\r\n%%\r\n% I asked for the data to be returned in a\r\n% |<https:\/\/www.mathworks.com\/help\/matlab\/ref\/timetable.html timetable>|.\r\n% How many points did I collect?\r\nnumDataPoints = height(data)\r\n%% \r\n% Let's look at the data now.  It's interesting to compare the trends of\r\n% the data we chose to view.  I'm using a\r\n% |<https:\/\/www.mathworks.com\/help\/matlab\/ref\/stackedplot.html\r\n% stackedplot>|\r\nh = stackedplot(data);\r\n%% IoT\r\n% If you are interested in learning more about IoT with MATLAB, I highly\r\n% recommend reading <https:\/\/blogs.mathworks.com\/iot\/ Hans's blog>.\r\n%\r\n% Let me know how you might take advantage of ThingSpeak\r\n% <https:\/\/blogs.mathworks.com\/loren\/?p=3388#respond here>.\r\n\r\n\r\n##### SOURCE END ##### fff60df087284d05b677a85192926e57\r\n-->","protected":false},"excerpt":{"rendered":"<div class=\"overview-image\"><img decoding=\"async\"  class=\"img-responsive\" src=\"https:\/\/blogs.mathworks.com\/images\/loren\/2019\/iotDemo_01.png\" onError=\"this.style.display ='none';\" \/><\/div><!--introduction--><p>I'm sure you've heard of IoT, Internet of Things. And people talk about connected devices, and getting the data from them to use in applications. I want to show you a very simple example to spark some ideas in each of you.... <a class=\"read-more\" href=\"https:\/\/blogs.mathworks.com\/loren\/2019\/07\/09\/internet-of-things-how-to-get-started\/\">read more >><\/a><\/p>","protected":false},"author":39,"featured_media":0,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":[],"categories":[80],"tags":[],"_links":{"self":[{"href":"https:\/\/blogs.mathworks.com\/loren\/wp-json\/wp\/v2\/posts\/3388"}],"collection":[{"href":"https:\/\/blogs.mathworks.com\/loren\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/blogs.mathworks.com\/loren\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/blogs.mathworks.com\/loren\/wp-json\/wp\/v2\/users\/39"}],"replies":[{"embeddable":true,"href":"https:\/\/blogs.mathworks.com\/loren\/wp-json\/wp\/v2\/comments?post=3388"}],"version-history":[{"count":2,"href":"https:\/\/blogs.mathworks.com\/loren\/wp-json\/wp\/v2\/posts\/3388\/revisions"}],"predecessor-version":[{"id":3392,"href":"https:\/\/blogs.mathworks.com\/loren\/wp-json\/wp\/v2\/posts\/3388\/revisions\/3392"}],"wp:attachment":[{"href":"https:\/\/blogs.mathworks.com\/loren\/wp-json\/wp\/v2\/media?parent=3388"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/blogs.mathworks.com\/loren\/wp-json\/wp\/v2\/categories?post=3388"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/blogs.mathworks.com\/loren\/wp-json\/wp\/v2\/tags?post=3388"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}