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);
}
/* 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);


}
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;
	}
}
Example #4
0
void monster::find2(tree *t)
{
	short tx,ty,dr,D;
	for(int i=0;i<4;i++)
	if((tx=t->x+cd2[D=(t->D+i)%4])<mapwidth-1 && tx>0 &&
	   (ty=t->y+cd2[4+D])<mapheight-1 && ty>0 &&
	   massmon[ty][tx]==100 && isgeneration(tx,ty,t,D) &&
	   (dr=t->R-eff2[maze[ty][tx]*4+t->J])>=0)
	{
		if((t->c[i]=(tree *)malloc(sizeof(tree)))==0)return;
		t->c[i]->x=tx;
		t->c[i]->y=ty;
		t->c[i]->J=t->J;
		t->c[i]->R=dr;
		t->c[i]->D=D;
		t->c[i]->f=t;
		for(int j=0;j<4;j++)
			t->c[i]->c[j]=0;
		att2(t->c[i]);
		find2(t->c[i]);
	}
}