Archives for Amazon Web Service API

ESP8266 Amazon Web Service (AWS) API

Using AWS Cloud services for the Internet of Things back-end can 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 free-tier level of usage. And the larger systems, with many sensor and control devices can take advantage of the reliability and virtually unlimited scalability that AWS offers.

If you have an urgent need for an AWS API for the ESP8266 right now, I have placed it on GitHub here.

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.

But there was a problem.

I could not find an API targeted for the ESP8266 in the AWS SDK. Yet the solution was right there….within the SDK. All that had to 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.

My first step was to build and test the sample code for the Spark Core (now known as “Particle”). 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 working Spark Core/AWS sample application up and running. Code changes included:

AWSClient2.cpp         
Change: Declarations missing for AWS_DATE_LEN2, AWS_TIME_LEN2 and HASH_HEX_LEN2

AmazonDynamoDBClient.h
Change: Added "MinimalList<MinimalString > SS;" to the class "AttributeValue"

After correcting the SDK code, the compile completed successful. And the subsequent testing on my device confirmed the functionality of the API, interfacing flawlessly with AWS.

The next step was to compile this SDK code with the Arduino IDE for ESP8266.

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  Esp8266AWSImplementations.h/.cpp files.

The most significant thing missing from the ESP8266 base library was a time server. The function “updateCurTime()” was added to the Esp8266AWSImplementations.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 “http GET” 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.

I also revised the AWS demo program (designed for the 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’s loop() function.

This is what the demo sketch does:

setup()
- connects to your local Wifi and initializes an AWS database client.
- a web server is also started, but is not used for this demo sketch
 
loop()
- first gets the current RGB values from a dynamoDB table
- then sets the dynamoDB table RGB values to an increment of the value from the 'get'

The next step

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 power outages and system crashes.

Here are just a few applications that come to mind for AWS Cloud IoT systems for the DIY explorer:

  1. 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 interval. 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.
  2. 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.
  3. 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 it’s source.

Conclusion

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 for 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 AWS Cloud.

I hope you find this information useful.

Loading

Share This:
FacebooktwitterredditpinterestlinkedintumblrFacebooktwitterredditpinterestlinkedintumblr