I’m using a Photon to run a weather station. I’ve stripped the my sketch down to read an Adafruit SHT31 and report to Blynk.
Power is supplied via USB or 2W solar panel through DFRobot solar charger and 44000mhA battery from Adafruit.
My photon will run for a few hours or a couple days and then something happens and it get stuck with a solid white LED (might be stuck in solid cyan, its outside in bright light and hard to see.)
I can reset, it goes through reset process and runs just fine for a while but crashes again.
I can’t figure out why it is not stable.
//Libraries ===================================================================
#include "Adafruit_SHT31.h" // include the SHT31 library from adafruit
#include "Wire.h"
#include "blynk.h"
#define DEBUG 1 // 1 debug on, 0 debug off
//Global constants ============================================================
const int samp_interval = 10; // sampling/measurement interval in seconds, unique
const int stor_interval = 2; // averaging/storage interval in minutes, unique
//blynk ========================================================================
char auth[] = "AUTH CODE";
//SHT31 - Temererature, Humidity, Dewpoint ====================================
Adafruit_SHT31 sht31 = Adafruit_SHT31(); // create SHT31 instance
float h; // humidity, %
float t; // air temperature, C
float d; // calculated dewpoint temperature, C
float Tdew(float Tair, float Rh)
{
float X=log(Rh/100)+((17.27*Tair)/(237.3+Tair));
float dp =(237.3*X)/(17.27-X);
return dp;
}
// battery volts ==============================================================
float batt;
//SETUP --------------------------------------------------------------------------------------------------------
void setup()
{
Serial.begin(115200); // start serial port
Time.zone(-7); //set time zone to MST
Blynk.begin(auth);
// start SHT31 T/RH sensor
if (! sht31.begin(0x44)) { // 0x44 for adafruit
// digitalWrite(redLED, LOW); // turn red on
delay(500);
while (1) delay(1);
}
Serial.println("setup complete");
}
//MAIN LOOP ----------------------------------------------------------------------------------------------------
void loop()
{
Blynk.run();
h=sht31.readHumidity(); // measure humidity
t=sht31.readTemperature(); // measure temp
d=Tdew(t,h); // calc dewpoint with subroutine
batt = (analogRead(A0)/1023.0*0.893/0.909); // measure battery with 100M/100K volt divider
int wifi = WiFi.RSSI();
#ifdef DEBUG // print results during debug
Serial.println();
Serial.println(Time.now());
Serial.println("temp \t hum \t dwpt\t");
Serial.print(t);Serial.print("\t");
Serial.print(h);Serial.print("\t");
Serial.print(d);Serial.print("\t");
Serial.println(batt);
#endif
//Send Data to Blynk =======================
Blynk.virtualWrite(V1, t);
Blynk.virtualWrite(V2, h);
Blynk.virtualWrite(V3, d);
Blynk.virtualWrite(V4, batt);
Blynk.virtualWrite(V5, wifi);
}