I tried the sample code, sending random value to table (by using putTemp()), successfully.
I added a function getTemp() in the loop, to read attribute value from the table. I tested it successfully alone (means, without putTemp()).
When I am doing both (getTemp() and putTemp()) one after other, getting error, for both function as given below,
Datetime= 201840222113051
Temperature send= 26
ERROR: Invalid requestDate must be in ISO-8601 'basic format'. Got '20184022T211305Z'. See http://en.wikipedia.org/wiki/ISO_8601
ERROR: Date must be in ISO-8601 'basic format'. Got '20184022T211305Z'. See http://en.wikipedia.org/wiki/ISO_8601
Temperature read= 0
Datetime= 201840222113051
Temperature send= 0
ERROR: Invalid requestDate must be in ISO-8601 'basic format'. Got '20184022T211305Z'. See http://en.wikipedia.org/wiki/ISO_8601
ERROR: Date must be in ISO-8601 'basic format'. Got '20184022T211305Z'. See http://en.wikipedia.org/wiki/ISO_8601
Temperature read= 0
Copied the modified sketch here,
include
include "Esp8266AWSImplementations.h"
include "AmazonDynamoDBClient.h"
include "AWSFoundationalTypes.h"
include "keys.h"
// Common AWS constants
const char AWS_REGION = "us-east-2"; //"eu-west-1"; // REPLACE with your region
const char AWS_ENDPOINT = "amazonaws.com";
// Init and connect Esp8266 WiFi to local wlan
const char pSSID = "Ali"; //"Ratheesh's iPhone"; // REPLACE with your network SSID (name)
const char pPassword = "1122334455"; // REPLACE with your network password (use for WPA, or use as key for WEP)
// Constants describing DynamoDB table and values being used
const char TABLE_NAME = "ESP8266AWSDemo";
const char HASH_KEY_NAME = "id";
const char HASH_KEY_VALUE = "ESP01"; // Our sensor ID, to be REPLACED in case of multiple sensors.
const char RANGE_KEY_NAME = "timest";
void setup() {
/ Begin serial communication. /
Serial.begin(115200);
Serial.println();
Serial.print("Attempting to connect to SSID: ");
Serial.println(pSSID);
WiFi.hostname("ESP8266");
// If pPassword is set the most secure supported mode will be automatically selected
WiFi.begin(pSSID, pPassword);
// Wait for WiFi connection
while (WiFi.status() != WL_CONNECTED) {
Serial.print(".");
delay(500);
}
Serial.println();
/* Initialize ddbClient. */
ddbClient.setAWSRegion(AWS_REGION);
ddbClient.setAWSEndpoint(AWS_ENDPOINT);
ddbClient.setAWSSecretKey(awsSecKey);
ddbClient.setAWSKeyID(awsKeyID);
ddbClient.setHttpClient(&httpClient);
ddbClient.setDateTimeProvider(&dateTimeProvider);
}
//****RRR****
void gettemp_table(int t,GetItemOutput getItemOutput){
//int value;
Serial.println("GetItem succeeded!");
/ Get the "item" from the getItem output. */
MinimalMap < AttributeValue > attributeMap = getItemOutput.getItem();
AttributeValue av;
/* Create an Item. */
AttributeValue id;
id.setS(HASH_KEY_VALUE);
AttributeValue timest;
timest.setN("20180221122243");
//////////////////////////////////////////////////////////////////////////////////////////
// Create key-value pairs out of the hash and range keys, and create a map out off them,
// which is the key.
//////////////////////////////////////////////////////////////////////////////////////////
MinimalKeyValuePair < MinimalString, AttributeValue > pair1(HASH_KEY_NAME, id);
MinimalKeyValuePair < MinimalString, AttributeValue > pair2(RANGE_KEY_NAME, timest);
MinimalKeyValuePair<MinimalString, AttributeValue> keyArray[] = { pair1, pair2 };
getItemInput.setKey(MinimalMap < AttributeValue > (keyArray, KEY_SIZE));
// Looking to get the 'temp' values
MinimalString attributesToGet[] = { "temp" };
getItemInput.setAttributesToGet(MinimalList < MinimalString > (attributesToGet, 1));
// Set Table Name
getItemInput.setTableName(TABLE_NAME);
// Perform getItem and check for errors.
GetItemOutput getItemOutput = ddbClient.getItem(getItemInput, actionError);
switch (actionError) {
case NONE_ACTIONERROR:
gettemp_table(t,getItemOutput);
break;
case INVALID_REQUEST_ACTIONERROR:
Serial.print("ERROR: ");
Serial.println(getItemOutput.getErrorMessage().getCStr());
break;
case MISSING_REQUIRED_ARGS_ACTIONERROR:
Serial.println("ERROR: Required arguments were not set for GetItemInput");
break;
case RESPONSE_PARSING_ACTIONERROR:
Serial.println("ERROR: Problem parsing http response of GetItem\n");
break;
case CONNECTION_ACTIONERROR:
Serial.println("ERROR: Connection problem");
break;
}
}
//***
void putTemp(int temp) {
/* Create an Item. */
AttributeValue id;
id.setS(HASH_KEY_VALUE);
AttributeValue timest;
timest.setN(dateTimeProvider.getDateTime());
/* Create an AttributeValue for 'temp', convert the number to a
* string (AttributeValue object represents numbers as strings), and
* use setN to apply that value to the AttributeValue. */
char numberBuffer[4];
AttributeValue tempAttributeValue;
sprintf(numberBuffer, "%d", temp);
tempAttributeValue.setN(numberBuffer);
/* Create the Key-value pairs and make an array of them. */
MinimalKeyValuePair < MinimalString, AttributeValue
> att1(HASH_KEY_NAME, id);
MinimalKeyValuePair < MinimalString, AttributeValue
> att2(RANGE_KEY_NAME, timest);
MinimalKeyValuePair < MinimalString, AttributeValue
> att3("temp", tempAttributeValue);
MinimalKeyValuePair<MinimalString, AttributeValue> itemArray[] = { att1,
att2, att3 };
/* Set values for putItemInput. */
putItemInput.setItem(MinimalMap < AttributeValue > (itemArray, 3));
putItemInput.setTableName(TABLE_NAME);
/* Perform putItem and check for errors. */
PutItemOutput putItemOutput = ddbClient.putItem(putItemInput,
actionError);
switch (actionError) {
case NONE_ACTIONERROR:
Serial.println("PutItem succeeded!");
break;
case INVALID_REQUEST_ACTIONERROR:
Serial.print("ERROR: Invalid request");
Serial.println(putItemOutput.getErrorMessage().getCStr());
break;
case MISSING_REQUIRED_ARGS_ACTIONERROR:
Serial.println(
"ERROR: Required arguments were not set for PutItemInput");
break;
case RESPONSE_PARSING_ACTIONERROR:
Serial.println("ERROR: Problem parsing http response of PutItem");
break;
case CONNECTION_ACTIONERROR:
Serial.println("ERROR: Connection problem");
break;
}
/* wait to not double-record */
delay(750);