UbiMaker
Published

Logging temperature data using the Spark Core

Log your aquarium's temperature and get an SMS when it's outside a given range

Full instructions provided9,969
Logging temperature data using the Spark Core

Things used in this project

Hardware components

Spark Core
Particle Spark Core
×1
DS18B20 Temperature Sensor
×1
4.7 KOhm resistor
×1
Jumper wires (generic)
Jumper wires (generic)
×1

Story

Read more

Code

file_12097.txt

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

Credits

UbiMaker

UbiMaker

52 projects • 156 followers
Maker @ ubidots.com
Contact

Comments