コード例 #1
0
void loop() {

    int prevSwitchState = switchState;
    /* Read the state of the tilt switch. */
    switchState = digitalRead(SWITCH_PIN);

    /* If state has changed back to low a button press (or a full tilt if using
     * a tilt switch) has passed */
    if (prevSwitchState == HIGH && switchState == LOW) {
        /* Create an Item. */
        AttributeValue deviceValue;
        deviceValue.setS(HASH_KEY_VALUE);
        AttributeValue timeValue;
        /* Getting current time for Time attribute. */
        timeValue.setN(dateTimeProvider.getDateTime());
        MinimalKeyValuePair < MinimalString, AttributeValue
                > att1(HASH_KEY_NAME, deviceValue);
        MinimalKeyValuePair < MinimalString, AttributeValue
                > att2(RANGE_KEY_NAME, timeValue);
        MinimalKeyValuePair < MinimalString, AttributeValue
                > att3(ATTRIBUTE_KEY_NAME, ATTRIBUTE_KEY_VALUE);
        MinimalKeyValuePair<MinimalString, AttributeValue> itemArray[] = { att1,
                att2, att3};

        /* Set values for putItemInput. */
        putItemInput.setItem(MinimalMap < AttributeValue > (itemArray, 2));
        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: ");
            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(2000);


    }
    delay(150);
}
コード例 #2
0
/* This function loops forever --------------------------------------------*/
void loop()
{
	//This will run in a loop
	rssi = WiFi.RSSI();
/* Create an Item. */
        AttributeValue deviceValue;
        deviceValue.setS(HASH_KEY_VALUE);
        AttributeValue timeValue;
        /* Getting current time for Time attribute. */
        timeValue.setS(dateTimeProvider.getDateTime());
        MinimalKeyValuePair < MinimalString, AttributeValue
                > att1(HASH_KEY_NAME, deviceValue);
        MinimalKeyValuePair < MinimalString, AttributeValue
                > att2(RANGE_KEY_NAME, timeValue);
        MinimalKeyValuePair<MinimalString, AttributeValue> itemArray[] = { att1,
                att2};

        /* Set values for putItemInput. */
        putItemInput.setItem(MinimalMap < AttributeValue > (itemArray, 2));
        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!");
            Serial.println(myIDStr);
            Serial.println(rssi);
            break;
        case INVALID_REQUEST_ACTIONERROR:
            Serial.print("ERROR: ");
            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(5000);


}
コード例 #3
0
void putDynamoDb() {
	// Put device & datestamp record in DynamoDB table
	// Create an Item.
	AttributeValue deviceIdValue;
	deviceIdValue.setS(HASH_KEY_VALUE);
	AttributeValue timeValue;
	// Getting current time for Time attribute.
	timeValue.setN(dateTimeProvider.getDateTime());
	AttributeValue deviceValue;
	deviceValue.setS(ATTRIBUTE_VALUE);

	MinimalKeyValuePair<MinimalString, AttributeValue> att1(HASH_KEY_NAME, deviceIdValue);
	MinimalKeyValuePair<MinimalString, AttributeValue> att2(RANGE_KEY_NAME, timeValue);
	MinimalKeyValuePair<MinimalString, AttributeValue> att3(ATTRIBUTE_NAME, deviceValue);
	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("DynamoDB PutItem succeeded!");
		break;
	case INVALID_REQUEST_ACTIONERROR:
		Serial.print("ERROR: ");
		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;
	}
}