This has been a very strange issue. I am pushing data to 2 virtual pins, temperature and humidity from a DHT22 sensor. I am using the PietteTech_DHT library. However it seems if I push the temp and humidity values from the readings it causes my Photon to crash and do a red SOS blinking. If I hard code in say some int values like 5 and 6, it works just fine. But what is strange is that doing just one virtualWrite works just fine with the actual sensor values. Blynk Debug output has nothing that I can see of value. It just crashes and restarts.
Heres my stripped down code:
//#define BLYNK_DEBUG // Optional, this enables lots of prints
//#define BLYNK_PRINT Serial
#include "blynk/blynk.h"
char auth[] = "0123456789abcd";
#include <math.h>
// This #include statement was automatically added by the Particle IDE.
#include "PietteTech_DHT/PietteTech_DHT.h"
double temp = 0;
double humidity = 0;
#define DHTTYPE DHT22 // Sensor type DHT11/21/22/AM2301/AM2302
#define DHTPIN 3 // Digital pin for communications
void dht_wrapper(); // must be declared before the lib initialization
PietteTech_DHT DHT(DHTPIN, DHTTYPE, dht_wrapper);
Timer blynk_timer(15000, blynkPublish);
Timer environment_timer(600000, environmentPublish);
void setup(){
Particle.variable("g_temp", temp);
Particle.variable("g_humidity", humidity);
delay(1000);
environmentPublish();
delay(1000);
blynk_timer.start();
environment_timer.start();
Particle.publish("End of setup");
Blynk.begin(auth);
}
void dht_wrapper(){
DHT.isrCallback();
}
void loop(){
Blynk.run();
}
void blynkPublish(){
if(Blynk.connected()){
/* This failes */
Blynk.virtualWrite(V0, temp); // temp shows up like 70.2 when I view the variable
Blynk.virtualWrite(V1, humidity); // humidity shows up like 50.4 when I view the variable
/*
This is fine
Blynk.virtualWrite(V0, 5);
Blynk.virtualWrite(V1, 6);
*/
}
}
void environmentPublish(){
DHT.acquireAndWait();
delay(500);
temp = DHT.getFahrenheit();
humidity = DHT.getHumidity();
temp = round(temp*10)/10.0;
humidity = round(humidity*10)/10.0;
Particle.publish("temp", String(temp), 60, PRIVATE);
Particle.publish("humidity", String(humidity), 60, PRIVATE);
}