Interacción de Spark Core con un servidor web:
Con Spark core podemos enviar datos de nuestros sensores a una pagina web y monitorear los datos de tus sensores desde cualquier parte.
Material:
-Una sensor de Humedad RHTo3
-Una resistencia de 10kohm
-Cables Jumper
-Protoboard
Conexiones:
Librerias Spark Core:
Código Spark Core:
// 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); }
Ubidots:
Crea tu cuenta en Ubidots: http://ubidots.com/
Y sigué los pasos: