{"id":739,"date":"2015-08-10T16:37:11","date_gmt":"2015-08-10T23:37:11","guid":{"rendered":"http:\/\/internetofhomethings.com\/homethings\/?p=739"},"modified":"2015-11-11T12:08:14","modified_gmt":"2015-11-11T20:08:14","slug":"esp8266-amazon-web-service-aws-api","status":"publish","type":"post","link":"https:\/\/internetofhomethings.com\/homethings\/?p=739","title":{"rendered":"ESP8266 Amazon Web Service (AWS) API"},"content":{"rendered":"<p>Using AWS Cloud services for\u00a0the Internet of Things back-end\u00a0can be beneficial for applications of all sizes, small to very large. Small and simple DIY home projects can leverage the power of AWS services while staying within the no-cost\u00a0free-tier level of usage. And the larger systems, with many sensor and control\u00a0devices can take advantage of the reliability and virtually unlimited scalability that AWS offers.<img loading=\"lazy\" decoding=\"async\" class=\"aligncenter wp-image-748 size-medium\" src=\"http:\/\/internetofhomethings.com\/homethings\/wp-content\/uploads\/2015\/08\/cloud_computing_1439393768-300x238.png\" alt=\"\" width=\"300\" height=\"238\" srcset=\"https:\/\/internetofhomethings.com\/homethings\/wp-content\/uploads\/2015\/08\/cloud_computing_1439393768-300x238.png 300w, https:\/\/internetofhomethings.com\/homethings\/wp-content\/uploads\/2015\/08\/cloud_computing_1439393768.png 640w\" sizes=\"auto, (max-width: 300px) 100vw, 300px\" \/><\/p>\n<p><strong><span style=\"color: red;\">If you have an urgent need for an AWS API for the ESP8266 right now, I have placed it\u00a0on GitHub<\/span><\/strong> <strong><a href=\"https:\/\/github.com\/internetofhomethings\/AWS-ESP8266-API\" target=\"_blank\">here<\/a><\/strong>.<\/p>\n<p>My initial interest was in some simple home automation projects. And I was planning to use the ultra-cheap ESP8266 to push my sensor readings up to the AWS database storage services and the receive control commands from the AWS Lambda service.<\/p>\n<p>But there was a problem.<\/p>\n<p>I could not find an API targeted for the ESP8266\u00a0in the <a href=\"https:\/\/github.com\/awslabs\/aws-sdk-arduino\" target=\"_blank\">AWS SDK<\/a>. Yet the solution was right there&#8230;.within the SDK. All that had\u00a0to be done was to adapt one of the currently supported micro-controller APIs for use with the ESP8266. After reviewing the APIs offered, the one that had the most in common with the ESP8266 was the Spark Core API.<\/p>\n<p>My first step was to build and test the sample code for the Spark Core (now known as &#8220;Particle&#8221;). Fortunately, I had a Spark Core device available for this purpose. While there were a few issues with the SDK library which caused the compile process to fail, it did not take long to get\u00a0working Spark Core\/AWS sample application up and running. Code changes included:<\/p>\n<pre>AWSClient2.cpp         \r\nChange: Declarations missing for AWS_DATE_LEN2, AWS_TIME_LEN2 and HASH_HEX_LEN2\r\n\r\nAmazonDynamoDBClient.h\r\nChange: Added \"MinimalList&lt;MinimalString &gt; SS;\" to the class \"AttributeValue\"\r\n<\/pre>\n<p>After correcting the SDK code, the compile completed successful. And the subsequent\u00a0testing on\u00a0my device\u00a0confirmed the functionality of the API, interfacing flawlessly with AWS.<\/p>\n<p>The next step was to compile this SDK code with the Arduino IDE for ESP8266.<\/p>\n<p>Since both the Spark Core and the Arduino IDE for ESP8266 used the sketch\/library model, the structure of the API did not have to be revised. The device specific library code was put in the \u00a0Esp8266AWSImplementations.h\/.cpp files.<\/p>\n<p>The most significant thing missing from the ESP8266 base library was a time server. The function &#8220;updateCurTime()&#8221; was added to the\u00a0Esp8266AWSImplementations.cpp file to fill that void. That function attempts to retrieve the current time in JSON format from a yahoo timeserver. While the timeserver URL works properly from a web browser, an error is returned from the ESP8266 &#8220;http GET&#8221; request. But, fortunately, the http error response includes the current GMT time. Since that is what is needed for the AWS API, it is simply scraped off the response string and used to build an AWS request.<\/p>\n<p>I also revised the AWS demo program (designed for\u00a0the Spark Core) to eliminate the need for a switch trigger. Instead of initiating an AWS request from the change in state of a switch, the AWS API interface is tested continuously in the sketch&#8217;s loop() function.<\/p>\n<p>This is what the demo sketch\u00a0does:<\/p>\n<pre>setup()\r\n- connects to your local Wifi and initializes an AWS database client.\r\n- a web server is also started, but is not used for this demo sketch\r\n\u00a0\r\nloop()\r\n- first gets the current RGB values from a dynamoDB table\r\n- then sets the dynamoDB table RGB values to an increment of the value from the 'get'<\/pre>\n<h3 style=\"text-align: center;\"><strong>The next step<\/strong><\/h3>\n<p>With this framework, you can exploit the low cost implementation of AWS Cloud-based IoT systems of all sizes. Sure, many applications can be handled locally within the confines of your network enabled ESP8266. But that solution has limited scalability, and is subject down-time associated with\u00a0power outages and system crashes.<\/p>\n<p>Here are just a few applications that come to mind for AWS Cloud IoT systems for the DIY explorer:<\/p>\n<ol>\n<li>Home Security: Apply some redundancy to your local system by pushing your sensor values and even camera images up to the AWS Cloud at a consistent\u00a0interval. Then, apply ITTT (if this then that) logic running on your AWS account to take action (send text or email or phone someone or sound an alarm) when a sensor detects an intruder, power outage (sensor updates stopped), fire, smoke, water leak, ect.<\/li>\n<li>Hot attic: When an attic sensor (sent to the AWS Cloud) exceeds a trigger temperature, the AWS Cloud sends a command to your local ESP8266 to turn on a fan to vent the heat.<\/li>\n<li>Water usage: If the water flow meter readings (sent to AWS regularly from an ESP8266) senses unusual water flow, a signal is sent by the AWS Cloud to an ESP8266 based control valve to shut the water off. This sort of thing can be scaled to distribute the monitoring and control to each and every valve and faucet in the house, so that the problem is isolated to\u00a0it&#8217;s source.<\/li>\n<\/ol>\n<h3 style=\"text-align: center;\"><strong>Conclusion<\/strong><\/h3>\n<p>There are many more IoT applications that can marry the ESP8266 with the AWS Cloud computing resources. Almost anything you can imagine can now become a reality; and\u00a0for a tiny fraction of the cost needed just a short time ago. The API presented here brings the low-cost network enabled sensor\/control power of the ESP8266 SoC to the all encompassing\u00a0AWS Cloud.<\/p>\n<p>I hope you find this information useful.<\/p>\n<p><a href=\"http:\/\/internetofhomethings.com\/homethings\/wp-content\/uploads\/2015\/08\/IoT_1439408875.jpg\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-medium wp-image-754\" src=\"http:\/\/internetofhomethings.com\/homethings\/wp-content\/uploads\/2015\/08\/IoT_1439408875-300x199.jpg\" alt=\"\" width=\"300\" height=\"199\" srcset=\"https:\/\/internetofhomethings.com\/homethings\/wp-content\/uploads\/2015\/08\/IoT_1439408875-300x199.jpg 300w, https:\/\/internetofhomethings.com\/homethings\/wp-content\/uploads\/2015\/08\/IoT_1439408875.jpg 640w\" sizes=\"auto, (max-width: 300px) 100vw, 300px\" \/><\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<p>Using AWS Cloud services for\u00a0the Internet of Things back-end\u00a0can be beneficial for applications of all sizes, small to very large. Small and simple DIY home projects can leverage the power &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,10,19],"tags":[50,51,49],"class_list":["post-739","post","type-post","status-publish","format-standard","hentry","category-alltheposts","category-esp8266","category-internet-of-things","tag-amazon-web-service-api","tag-esp8266-api-to-aws-cloud-services","tag-esp8266-aws-api"],"_links":{"self":[{"href":"https:\/\/internetofhomethings.com\/homethings\/index.php?rest_route=\/wp\/v2\/posts\/739","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=739"}],"version-history":[{"count":14,"href":"https:\/\/internetofhomethings.com\/homethings\/index.php?rest_route=\/wp\/v2\/posts\/739\/revisions"}],"predecessor-version":[{"id":832,"href":"https:\/\/internetofhomethings.com\/homethings\/index.php?rest_route=\/wp\/v2\/posts\/739\/revisions\/832"}],"wp:attachment":[{"href":"https:\/\/internetofhomethings.com\/homethings\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=739"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/internetofhomethings.com\/homethings\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=739"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/internetofhomethings.com\/homethings\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=739"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}