Created
August 22, 2014 20:27
-
-
Save LuisFDuarte/232d157c3780b2710da9 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// This #include statement was automatically added by the Spark IDE. | |
#include "Adafruit_DHT/Adafruit_DHT.h" | |
// This #include statement was automatically added by the Spark IDE. | |
#include "HttpClient/HttpClient.h" | |
HttpClient http; | |
#define VARIABLE_ID "53f6caea76254277ef8837cd" | |
#define VARIABLE_ID2 "53f63fa576254235bec59148" | |
#define TOKEN "cfaI5R1bcr7wlwf58hAnNZNNvfSoUk" | |
int lightLevel = 0; | |
#define DHTPIN 2 // what pin we're connected to | |
// Uncomment whatever type you're using! | |
#define DHTTYPE DHT11 // DHT 11 | |
DHT dht(DHTPIN, DHTTYPE); | |
// Reading temperature or humidity takes about 250 milliseconds! | |
// Sensor readings may also be up to 2 seconds 'old' (its a | |
// very slow sensor) | |
// Read temperature as Celsius | |
// 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() { | |
request.hostname = "things.ubidots.com"; | |
request.port = 80; | |
Serial.begin(9600); | |
dht.begin(); | |
} | |
void loop() { | |
float h = dht.getHumidity(); | |
float t = dht.getTempCelcius(); | |
request.path = "/api/v1.6/variables/"VARIABLE_ID"/values"; | |
request.body = "{\"value\":" + String(t) + "}"; | |
http.post(request, response, headers); | |
Serial.println(response.body); | |
request.path = "/api/v1.6/variables/"VARIABLE_ID2"/values"; | |
request.body = "{\"value\":" + String(h) + "}"; | |
http.post(request, response, headers); | |
Serial.println(response.body); | |
Serial.print("la temperatura es: "); | |
Serial.println(t); | |
Serial.print("la humedad relativa es: "); | |
Serial.println(h); | |
delay(2000); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment