Code Monkey home page Code Monkey logo

aws-sdk-arduino's Introduction

Version 1 of the Experimental AWS SDK for Arduino

An experimental SDK for contacting AWS Services on Arduino-compatible devices. Currently it supports Amazon DynamoDB, Amazon Kinesis and Amazon SNS. More services coming soon.

All Amazon DynamoDB operations are supported. The code for creating, serializing, and deserializing Kinesis input and output objects is included, but the devices that the experimental SDK has been tested on do not have readily available HTTPS support. This code has been included so it can be used by those who want to do further experimenting with Kinesis and HTTPS.

The SDK is extensible to non-Arduino-compatible devices by implementing the interfaces in DeviceIndependentInterfaces.cpp/.h. See SparkAWSImplementations.cpp/.h and EdisonAWSImplementations.cpp/.h for examples of this.

Folder Structure

* /common contains all the common source code
* /sparkcore contains Spark IO Core device-specific implementations
* /edison contains Intel Edison device-specfic implementations
* /galileo contains Intel Galileo device-specific implementations
* /mediatek contains MediaTek LinkIt One device-specific implementations

Depending on the device that you are working, Simply copy the those device-specific implementations to the Common directory so you can test out your samples using Arduino IDE.

Happy experimenting!

Getting Started with the Samples

Trying the samples is a good way to get started with using the SDK.

Getting the samples working has the following steps: setting up the DynamoDB table, importing the SDK and copying over the sample, creating the keys.h and keys.cpp files, and setting up the hardware. These steps are outlined for the samples for both the Spark core and Intel Galileo, so be sure you are following only the directions corresponding to the device and sample you are using.

If you are using a device other than Spark or Galileo, you may want to read through these steps anyway before implementing the interfaces in DeviceIndependentInterfaces.cpp/.h for your device.

Step 1: Setting up the DynamoDB Table

For either device you will need to set up a DynamoDB table with the same name, hash key, and range key as in the sample you are using. These values are defined as constants in the sample, i.e. HASH_KEY_NAME and TABLE_NAME.

You can follow the steps below to get the tables set up with the right values, chosing the right set of instructions based on which sample you are using.

Table used by SparkGetItemSample and GalileoSample:

  • Log into the AWS Console and navigate to DynamoDB.
  • Click on the "Create Table" button.
  • Enter "AWSArduinoSDKDemo" as the Table Name, "DemoName" as the Hash Attribute Name, and "id" as the Range Attribute Name. Be sure to mark DemoName as String and id as Number.
  • For this example, we won't add indexes, so just press continue on the Add Indexes (optional) page.
  • Just one Read Capacity Unit and one Write Capacity Unit will be enough for this demo. Press continue with these values.
  • Uncheck Use Basic Alarms and continue again.
  • Check that the information is correct on the Review page, then create the table!
  • After the table has finished creating, double click on it to explore it. Here you should press the New Item button and create an item with the following values:
    • "DemoName": String, "Colors"
    • "id": Number, "1"
    • "R", Number "255"
    • "G", Number "255"
    • "B", Number "255"

Table used by SparkPutItemSample:

  • Log into the AWS Console and navigate to DynamoDB.
  • Click on the "Create Table" button.
  • Enter "AWSArduinoSDKTests" as the Table Name, "device" as the Hash Attribute Name, and "Time" as the Range Attribute Name. Be sure to mark both as String.
  • For this example, we won't add indexes, so just press continue on the Add Indexes (optional) page.
  • Just one Read Capacity Unit and one Write Capacity Unit will be enough for this demo. Press continue with these values.
  • Uncheck Use Basic Alarms and continue again.
  • Check that the information is correct on the Review page, then create the table!

Step 2: Importing SDK and Copying Sample

This step is different for the Spark Core and Intel Galileo.

Connected Maraca Sample (Edison/SparkCore/MediaTek)

follow the step by step guide: http://bit.ly/aws-iot-hackseries

Intel Galileo/Edison Sample

With Galileo or Edison, you should be using the Arduino IDE from Intel as it includes Galileo and Edison libraries. Link to Intel-Arduino IDE.

Make an AWSArduinoSDK directory in the Arduino IDE's libraries directory (e.g. ~/Arduino/libraries/AWSArduinoSDK).

Move all of the files from the SDK's src/common directory into the AWSArduinoSDK directory. Import the library.

Create a new sketch with the Arduino IDE and copy and paste the sample code into it.

Spark IO Core Sample

This assumes you already have your Spark set up and are able to program it with Spark Build. If you do not, head over to Spark's website.

Open up the Spark Build web page and create a new app. Name it whatever you would like.

Copy the contents of the sample you are using into the .ino file of your new app.

Next you need to import the SDK. Because the Spark Build IDE isn't local to your machine, you can't just cp the files over. Instead use the "+" tab in the top right corner of the Spark Build page to create a new file for each .cpp/.h file in the src/ directory, except GalileoAWSImplementations and AmazonKinesisClient. Then copy and paste the contents of each file.

Step 3: Creating keys.h and keys.cpp

You will need to create and add keys.h and keys.cpp into the AWSArduinoSDK directory you made. These files define the awsKeyID and awsSecKey values used by the sketch, the files may be structured as following:

// keys.h
#ifndef KEYS_H_
#define KEYS_H_

extern const char* awsKeyID;  // Declare these variables to 
extern const char* awsSecKey; // be accessible by the sketch

#endif
// keys.cpp
#include "keys.h"

const char* awsKeyID = "YOUR AWS KEY ID HERE";
const char* awsSecKey = "YOUR AWS SECRET KEY HERE";

Add these files as you added the source files. That is: with Spark, use the "+" button, and with Galileo, move them to the AWSArduinoSDK directory under Arduino's libraries directory.

Step 4: Setting up Hardware

To use the samples you must have the correct breadboard wiring. The samples use different wiring, but use the following rules to create them:

Buttons: Connect buttons by wiring one leg of the button to the 3v or 5v pin. Connect one leg to ground with a resistor, and also wire it to the pin that is reading the value.

RGB LED: For the multicolored LED, wire the cathode (the longest leg) to ground, then connect the remaining 3 legs to the corresponding input pins with a resistor.

Spark Core

Both spark samples use just one button connected to the D2 pin.

Intel Galileo

This sample uses five buttons and a RGB LED.

The RGB LED has the red leg connected to pin 6, the green leg connected to pin 9, and the blue leg connected to pin 10.

Buttons:

  • Button for performing PutItem should be connected to pin 2
  • Button for performing GetItem should be connected to pin 4
  • Button for changing red color value should be connected to pin 7
  • Button for changing green color value should be connected to pin 8
  • Button for changing blue color value should be connected to pin 12

For Galileo/Edison, after the wiring is finished, you should be able to connect it to power, connect it to your computer via usb, and compile and upload the code with the Arduino IDE. Be sure to refer to the comments in the samples for help.

For Spark, after the wiring is finished, you should be able to connect it to your computer via USB, and Flash the code. Be sure to refer to the comments in the samples for help.

aws-sdk-arduino's People

Contributors

afitzgibbon avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

aws-sdk-arduino's Issues

const int HASH_HEX_LEN ERROR

I am running this on Intel Galileo Gen 2.
But I am getting an error 'const int HASH_HEX_LEN' previously defined here' .

Kindly, suggest what I am doing wrong.

Does this really work on an Arduino?

Hello,

This appears to be EXACTLY what we have been looking for ... but I'm a little confused by the naming and examples.

Will this run on a Arduino? Is there a sample for the Arduino?

I see examples for other platforms ... but not the Arduino ... or am I missing something?

Getting Exception (3) while trying to send data

Basic Infos

Hardware

Hardware: ESP8266
Core Version: 1.0.0

Description

I am getting Exception (3) when I try to send data to a AWS server. I have made sure that my credentials are ok, so I have to ask you for help. I get this exception after about two tries to send the data (two loops) and then my program ends.

Below is my stack trace.

Settings in IDE

Module: Generic ESP8266 Module
Flash Size: 512k
CPU Frequency: 80Mhz
Flash Mode: qio
Flash Frequency: 40Mhz
Upload Using: SERIAL
Reset Method: ck

Sketch

Sketch with dummy credentials:

#include <ESP8266WiFi.h>
#include <ESP8266AWSImplementations.h>
#include <AmazonIOTClient.h>



Esp8266HttpClient httpClient;
Esp8266DateTimeProvider dateTimeProvider;


AmazonIOTClient iotClient;
ActionError actionError;

const char* ssid = "ssid";
const char* password = "password";

void initWLAN()
{
  WiFi.begin(ssid, password);
  while (WiFi.status() != WL_CONNECTED)
  {
    delay(500);
  }
}

void initAWS()
{
  iotClient.setAWSRegion("us-west-2");
  iotClient.setAWSEndpoint("amazonaws.com");
  iotClient.setAWSDomain("az3y9qqx4lf51.iot.us-west-2.amazonaws.com");
  iotClient.setAWSPath("/things/ESP8266/shadow");
  iotClient.setAWSKeyID("my key");
  iotClient.setAWSSecretKey("secret key");
  iotClient.setHttpClient(&httpClient);
  iotClient.setDateTimeProvider(&dateTimeProvider);
}

void setup() {
  Serial.begin(115200);
  delay(10);
  Serial.println("begin");
  initWLAN();
  Serial.println("wlan initialized");
  initAWS();
  Serial.println("iot initialized");
}

void loop()
{
  char shadow[100];
  strcpy(shadow, "{\"state\":{\"reported\":{\"test_value1\":123, \"test_value2\":234}}}");
  
  Serial.println("Trying to send data");
  Serial.print(shadow);
  
  char* result = iotClient.update_shadow(shadow, actionError);
  Serial.print(result);
  
  delay(2000);
}

Debug Messages

This is my stack trace in the EspDecoder


0x4010020c: _umm_free at C:\Users\alexr\AppData\Local\Arduino15\packages\esp8266\hardware\esp8266\2.4.0\cores\esp8266\umm_malloc/umm_malloc.c line 1291
0x40100690: free at C:\Users\alexr\AppData\Local\Arduino15\packages\esp8266\hardware\esp8266\2.4.0\cores\esp8266\umm_malloc/umm_malloc.c line 1737
0x40206490: operator delete[](void*) at C:\Users\alexr\AppData\Local\Arduino15\packages\esp8266\hardware\esp8266\2.4.0\cores\esp8266/abi.cpp line 84
0x40204095: MinimalString::innerDelete() at C:\Users\alexr\Documents\Arduino\libraries\common/AWSFoundationalTypes.cpp line 49
0x402040f9: MinimalString::operator=(MinimalString const&) at C:\Users\alexr\Documents\Arduino\libraries\common/AWSFoundationalTypes.cpp line 49
0x4020647c: operator delete(void*) at C:\Users\alexr\AppData\Local\Arduino15\packages\esp8266\hardware\esp8266\2.4.0\cores\esp8266/abi.cpp line 84
0x40203f50: AWSClient4::createRequest(MinimalString&) at C:\Users\alexr\Documents\Arduino\libraries\common/AWSClient4.cpp line 197
0x4021fe0d: SHA256_Final at crypto/sha256.c line 273 (discriminator 3)
0x4021c26c: hmac_sha256_v at crypto/hmac.c line 165
0x4021c2b8: ax_hmac_sha256 at crypto/hmac.c line 133
0x40216165: p_hash_sha256 at ssl/tls1.c line 2007
:  (inlined by) prf at ssl/tls1.c line 951
0x40103215: lmacProcessTXStartData at ?? line ?
0x40103212: lmacProcessTXStartData at ?? line ?
0x4010213e: wDev_ProcessFiq at ?? line ?
0x40100ece: pp_post at ?? line ?
0x401042b0: lmacTxFrame at ?? line ?
0x401034cf: lmacRecycleMPDU at ?? line ?
0x40103932: lmacRecycleMPDU at ?? line ?
0x40103416: lmacProcessTxSuccess at ?? line ?
0x40102297: wDev_ProcessFiq at ?? line ?
0x40101f94: wDev_ProcessFiq at ?? line ?
0x4021a4ba: pgm_read_byte at ssl/os_port.h line 107
:  (inlined by) AES_encrypt at crypto/aes.c line 375
:  (inlined by) AES_cbc_encrypt at crypto/aes.c line 288
0x4021a3be: AES_cbc_encrypt at crypto/aes.c line 283
0x4024867e: sleep_reset_analog_rtcreg_8266 at ?? line ?
0x402485d0: sleep_reset_analog_rtcreg_8266 at ?? line ?
0x4021ae5a: bi_free at crypto/bigint.c line 672
0x4021adf8: bi_depermanent at crypto/bigint.c line 672
0x4010020c: _umm_free at C:\Users\alexr\AppData\Local\Arduino15\packages\esp8266\hardware\esp8266\2.4.0\cores\esp8266\umm_malloc/umm_malloc.c line 1291
0x4010020c: _umm_free at C:\Users\alexr\AppData\Local\Arduino15\packages\esp8266\hardware\esp8266\2.4.0\cores\esp8266\umm_malloc/umm_malloc.c line 1291
0x40100690: free at C:\Users\alexr\AppData\Local\Arduino15\packages\esp8266\hardware\esp8266\2.4.0\cores\esp8266\umm_malloc/umm_malloc.c line 1737
0x4021af18: bi_terminate at crypto/bigint.c line 672
0x4010020c: _umm_free at C:\Users\alexr\AppData\Local\Arduino15\packages\esp8266\hardware\esp8266\2.4.0\cores\esp8266\umm_malloc/umm_malloc.c line 1291
0x4010020c: _umm_free at C:\Users\alexr\AppData\Local\Arduino15\packages\esp8266\hardware\esp8266\2.4.0\cores\esp8266\umm_malloc/umm_malloc.c line 1291
0x4010020c: _umm_free at C:\Users\alexr\AppData\Local\Arduino15\packages\esp8266\hardware\esp8266\2.4.0\cores\esp8266\umm_malloc/umm_malloc.c line 1291
0x40100690: free at C:\Users\alexr\AppData\Local\Arduino15\packages\esp8266\hardware\esp8266\2.4.0\cores\esp8266\umm_malloc/umm_malloc.c line 1737
0x4020647c: operator delete(void*) at C:\Users\alexr\AppData\Local\Arduino15\packages\esp8266\hardware\esp8266\2.4.0\cores\esp8266/abi.cpp line 84
0x40203668: SSLContext::unref() at C:\Users\alexr\AppData\Local\Arduino15\packages\esp8266\hardware\esp8266\2.4.0\libraries\ESP8266WiFi\src/WiFiClientSecure.cpp line 110
0x40203692: WiFiClientSecure::~WiFiClientSecure() at C:\Users\alexr\AppData\Local\Arduino15\packages\esp8266\hardware\esp8266\2.4.0\libraries\ESP8266WiFi\src/WiFiClientSecure.cpp line 415
0x402044a9: Esp8266HttpClient::send(char const*, char const*, int) at C:\Users\alexr\Documents\Arduino\libraries\common/ESP8266AWSImplentations.cpp line 54
0x402069a8: Print::write(unsigned char const*, unsigned int) at C:\Users\alexr\AppData\Local\Arduino15\packages\esp8266\hardware\esp8266\2.4.0\cores\esp8266/Print.cpp line 38
0x401004d8: malloc at C:\Users\alexr\AppData\Local\Arduino15\packages\esp8266\hardware\esp8266\2.4.0\cores\esp8266\umm_malloc/umm_malloc.c line 1668
0x40206468: operator new[](unsigned int) at C:\Users\alexr\AppData\Local\Arduino15\packages\esp8266\hardware\esp8266\2.4.0\cores\esp8266/abi.cpp line 84
0x40204199: AmazonIOTClient::update_shadow(MinimalString, ActionError&) at C:\Users\alexr\Documents\Arduino\libraries\common/AmazonIOTClient.cpp line 19
0x4020226a: loop at C:\Users\alexr\Documents\Arduino\ESP8266AWSIoTDemo-master\ESP8266AWSIoTDemo/ESP8266AWSIoTDemo.ino line 74
0x402025f8: ESP8266WiFiSTAClass::status() at C:\Users\alexr\AppData\Local\Arduino15\packages\esp8266\hardware\esp8266\2.4.0\libraries\ESP8266WiFi\src/ESP8266WiFiSTA.cpp line 483
0x40205e1c: Print::println() at C:\Users\alexr\AppData\Local\Arduino15\packages\esp8266\hardware\esp8266\2.4.0\cores\esp8266/Print.h line 93
0x40205e40: Print::println(char const*) at C:\Users\alexr\AppData\Local\Arduino15\packages\esp8266\hardware\esp8266\2.4.0\cores\esp8266/Print.h line 93
0x40206565: esp_schedule at C:\Users\alexr\AppData\Local\Arduino15\packages\esp8266\hardware\esp8266\2.4.0\cores\esp8266/core_esp8266_main.cpp line 57
0x40206590: loop_wrapper at C:\Users\alexr\AppData\Local\Arduino15\packages\esp8266\hardware\esp8266\2.4.0\cores\esp8266/core_esp8266_main.cpp line 57
0x40100718: cont_norm at C:\Users\alexr\AppData\Local\Arduino15\packages\esp8266\hardware\esp8266\2.4.0\cores\esp8266/cont.S line 109

BatchWriteItem help

Hi,

Is anybody able to help me work out how to use BatchWriteItem on Arduino using the SDK? I've got putItem working fine, and from reading the library have worked out I need to change the following (currently shown with putItem as working, Batchwriteitem commented out:

In my header:
PutItemInput putItemInput; //BatchWriteItemInput batchWriteItemInput;
In the function:
`putItemInput.setItem(MinimalMap < AttributeValue > (itemArray, 4));
putItemInput.setTableName(TABLE_NAME);
// batchWriteItemInput.setRequestItems(MinimalMap<MinimalList > requestItems);

//perform putItem and check for errors.
PutItemOutput putItemOutput = ddbClient.putItem(putItemInput, actionError);
//BatchWriteItemOutput batchWriteItemOutput = ddbClient.batchWriteItem(batchWriteItemInput, actionError);`

For putItem, the library helps me create the necessary JSON for MinimalMap < AttributeValue > (itemArray, 4) using the following:
MinimalKeyValuePair < MinimalString, AttributeValue > att1(HASH_KEY_NAME, deviceValue); MinimalKeyValuePair < MinimalString, AttributeValue > att2(RANGE_KEY_NAME, timeValue); MinimalKeyValuePair < MinimalString, AttributeValue > att3(CATEGORY_KEY_NAME, categoryValue); MinimalKeyValuePair < MinimalString, AttributeValue > att4(DEBUG_KEY_NAME, debugValue); MinimalKeyValuePair < MinimalString, AttributeValue> itemArray[] = { att1, att2, att3, att4 };

What I can't get my head around is how to use something similar within a loop to create the MinimalMap<MinimalList > requestItems needed for batchWriteItem.

I'm learning everything as I go with the power of google, so don't really know what I'm doing - if anyone can point me in the right direction it would be much appreciated - would be great to be able to share a working BatchWriteItem example here for others.

Too large

Hi, i'm finding when i compile the dynamo put .ino with all of the cpp/h files from the src directory (including added keys.h and keys.cpp files) the resulting binary is 109k. This is too big to fit on the spark core. What have I missed? The dynamo get sample app compiles down to small enough.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.