Skip to content

Instantly share code, notes, and snippets.

@LuisFDuarte
Created November 4, 2014 19:45
Show Gist options
  • Save LuisFDuarte/9358c3daa34a8b6a81f4 to your computer and use it in GitHub Desktop.
Save LuisFDuarte/9358c3daa34a8b6a81f4 to your computer and use it in GitHub Desktop.
// This #include statement was automatically added by the Spark IDE.
#include "HttpClient/HttpClient.h"
HttpClient http;
#define VARIABLE_ID "544e4a8f7625426e332b1e8e"
#define TOKEN "40RwMVjyvD9H360HOu7p191MoqSHg4"
int people = 0;
int tiempo=0;
int presence=0;
// Headers currently need to be set at init, useful for API keys etc.
http_header_t headers[] = {
{ "Content-Type", "application/json" },
{ "X-Auth-Token" , TOKEN },
{ NULL, NULL } // NOTE: Always terminate headers will NULL
};
http_request_t request;
http_response_t response;
void setup() {
pinMode(D1, INPUT);
request.hostname = "things.ubidots.com";
request.port = 80;
Serial.begin(9600);
}
void loop() {
presence=digitalRead(D1);
Serial.print("presence");
Serial.println(presence);
if(presence)
{
people=people+1;
do{
presence=digitalRead(D1);
}while(presence);
//delay(2000);
}
tiempo=tiempo+1;
delay(1000);
if(tiempo==10)
{
Serial.println(people);
request.path = "/api/v1.6/variables/"VARIABLE_ID"/values";
request.body = "{\"value\":" + String(people) + "}";
http.post(request, response, headers);
tiempo=0;
Serial.println(response.status);
Serial.println(response.body);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment