I’m now using this Code with a timer. But still -127°C in Blynk.
#include <SparkCorePolledTimer.h>
// This #include statement was automatically added by the Particle IDE.
#include <blynk.h>
// This #include statement was automatically added by the Particle IDE.
#include <OneWire.h>
// This #include statement was automatically added by the Particle IDE.
#include "spark-dallas-temperature.h"
// You should get Auth Token in the Blynk App.
// Go to the Project Settings (nut icon).
char auth[] = "xxxxxxxxxxxxxxxxxxxxxxxxxx";
//#define SensorPin 2
OneWire oneWire(D2);
DallasTemperature sensors(&oneWire);
double tempc = 0.0;
BlynkTimer timer;
// This function sends Arduino's up time every second to Virtual Pin (5).
// In the app, Widget's reading frequency should be set to PUSH. This means
// that you define how often to send data to Blynk App.
void sendSensor()
{
sensors.requestTemperatures();
double tempCheck = sensors.getTempCByIndex(0);
tempc = (double) tempCheck;
Blynk.virtualWrite(V5, tempCheck);
}
void setup()
{
// Debug console
Serial.begin(9600);
delay(5000); // Allow board to settle
Blynk.begin(auth);
Particle.variable("tempc", &tempc, DOUBLE);
sensors.begin();
// Setup a function to be called every second
timer.setInterval(1000L, sendSensor);
}
void loop()
{
Blynk.run();
timer.run();
}