Created
December 15, 2014 12:36
-
-
Save LuisFDuarte/f7048d4e739f3a9eec08 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 "HttpClient/HttpClient.h" | |
// This #include statement was automatically added by the Spark IDE. | |
#include "OneWire/OneWire.h" | |
// This #include statement was automatically added by the Spark IDE. | |
#include "spark-dallas-temperature/spark-dallas-temperature.h" | |
#define ONE_WIRE_BUS D2 | |
OneWire oneWire(ONE_WIRE_BUS); | |
DallasTemperature sensor(&oneWire); | |
float temperature = 0.0; | |
char resultstr[64]; | |
HttpClient http; | |
#define VARIABLE_ID "5489bf717625424489244e2a" | |
#define TOKEN "pSZJt9W7v5W3fpUsRYNKiDMgJ770NK" | |
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.port = 80; | |
request.hostname = "things.ubidots.com"; | |
request.path = "/api/v1.6/variables/"VARIABLE_ID"/values"; | |
Serial.begin(9600); | |
sensor.begin(); | |
} | |
void loop() { | |
sensor.requestTemperatures(); | |
temperature=sensor.getTempCByIndex( 0 ); | |
sprintf(resultstr, "{\"value\":%.4f}",temperature); | |
request.body = resultstr;//Sending presence to Ubidots | |
http.post(request, response, headers); | |
Serial.println(response.status); //For debug only | |
Serial.println(response.body); | |
delay(1000); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment