My first post here and wasn’t able to find many other discussions on this. I am using my photon to take temperature readings and publish them. Also, using one of the temp readings to control a fridge compressor with a 5 minute timeout. Everything seemed to be working but after about an hour the device will stop publishing temp data to the dashboard. When I try to reflash firmware from the web IDE (and Particle Dev), it will say that it was successful. However, if I leave the dashboard running it will publish spark/flash/status failed. Like this:
I have tried to reset the photon. I have reflashed the photon using the dfu-util by flashing tinker, then running particle setup. When I flash my code again through the WebIDE, it will work for a short amount of time and then stop logging again.
Any thoughts? Code attached:
// This #include statement was automatically added by the Particle IDE.
#include "OneWire/OneWire.h"
// This #include statement was automatically added by the Particle IDE.
#include "spark-dallas-temperature/spark-dallas-temperature.h"
OneWire ds = OneWire(D0);// Connected to D0 Pin
OneWire oneWire(ds);//Setup oneWire instance
// Pass our oneWire reference to Dallas Temperature.
DallasTemperature sensors(&oneWire);
// Addresses of the 1-Wire sensors.
// Tutorial on how to obtain these addresses:
// http://www.hacktronics.com/Tutorials/arduino-1-wire-address-finder.html
DeviceAddress fridgeSensor1 = { 0x28, 0x3C, 0x14, 0xB6, 0x06, 0x00, 0x00, 0xA4 };//white label on sensor
DeviceAddress fridgeSensor2 = { 0x28, 0x0A, 0xBF, 0xB6, 0x06, 0x00, 0x00, 0xB8 };
DeviceAddress fridgeSensor3 = { 0x28, 0x01, 0x7D, 0x2A, 0x07, 0x00, 0x00, 0xB9 };//short cable
DeviceAddress iceboxSensor1 = { 0x28, 0x92, 0xCB, 0x1D, 0x07, 0x00, 0x00, 0x4C };
//variables
//strings for publishing temp data
char fridge1String[10];
char fridge2String[10];
char fridge3String[10];
char icebox1String[10];
char compStateString[10];
int comp = D1;
float low_temp = 6.0;
float high_temp = 8.0;
int restTime = 5*60*1000;
int compState = 1;//0=on timeout 1=ready
void setup(void)
{
// Start up the library
sensors.begin();
// set the resolution to 10 bit (good enough?)
sensors.setResolution(fridgeSensor1, 10);
sensors.setResolution(fridgeSensor2, 10);
sensors.setResolution(fridgeSensor3, 10);
sensors.setResolution(iceboxSensor1, 10);
//initialize compressor pin as output and turn on
pinMode(comp, OUTPUT);
digitalWrite(comp, HIGH);
}
Timer compTimeout(restTime,compStateReset);
void compStateReset()
{
compState=1;
compTimeout.reset();
}
void loop(void)
{
delay(15000);
//SENSOR MEASUREMENT EXECUTION
//telling sensors to initiate a new measurement
sensors.requestTemperatures();
//get temperatures in degrees C as Floats
float fridge1=sensors.getTempC(fridgeSensor1);
float fridge2=sensors.getTempC(fridgeSensor2);
float fridge3=sensors.getTempC(fridgeSensor3);
float icebox1=sensors.getTempC(iceboxSensor1);
if ((fridge1<=-127)||(fridge2<=-127)||(fridge3<=-127)||(icebox1<=-127)){//breaks from loop if error received from either temp sensor
return;
}
//DATA PUBLISHING
//convert floats to strings
sprintf(fridge1String,"%.2f",fridge1);
sprintf(fridge2String,"%.2f",fridge2);
sprintf(fridge3String,"%.2f",fridge3);
sprintf(icebox1String,"%.2f",icebox1);
sprintf(compStateString,"%d",digitalRead(comp));
//publish strings to cloud (note: it looks like can only publish 4 vars)
Spark.publish("Fridge Temperature 1",fridge1String);
Spark.publish("Fridge Temperature 2",fridge2String);
Spark.publish("Fridge Temperature 3",fridge3String);
//TEMP CONTROL LOGIC
if ((fridge1>high_temp) && (compState=1)) {//checks if it is too warm and the compressor is ready
digitalWrite(comp, HIGH);
}else if(fridge1<low_temp) { //checks if it is too cold
digitalWrite(comp, LOW);
compState=0;
compTimeout.start();
}
}