@fouad2000, I spent a lot of hours scouring the forum for an answer to this problem. 9 times out 10 the poster would find that their code was stuck in a loop so I would suggest that you start there. However, there were some that were sure that their code wasn’t stuck and yet the problem still continued to happen. One thing that seemed to be a trend was to make sure that you are using SYSTEM_THREAD(ENABLED). This allows the “OS” of the photon to run even if the code gets stuck in a loop. I came across another where the poster had determined that turning the WiFi off and back on would stop the problem. So, the following code is what I have been putting into my project and I haven’t had a breathing green failure since mid October 2018. Basically it includes the SYSTEM_THREAD(ENABLED) and 2 counter functions. One starts counting if the photon is attached to the WiFi but not the cloud. If it stays this way for 5 minutes, it turns the WiFi off. The second turns the WiFi back on after a minute. I deployed both of these “fixes” at the same time so I’m not sure both are needed but I know that together they work. I’ve never used the cellular version of the photon but I’m sure that there is a similar function to turn off the radio and then turn it back on gain. You’ll just have to change WiFi.off and on to what commands are needed for your version.
SYSTEM_THREAD(ENABLED);//Added so that program would still run if WiFi locked up
int countLoop;//This and the next 6 variables are used to shutdown WiFi and restart it if connection to the cloud is lost for over 5 minutes.
int countWIFILoop;
int countLoopWIFI;
int offWIFIcount;
unsigned long lastCheck;
unsigned long lastWIFICheck;
unsigned long lastCountWiFi;
void setup()
{
Serial.begin(9600);
delay(100);
countLoop = 0;//This line and the next 6 just set initial values for the counters used for WiFi shut off/on for extended cloud loss
lastCheck = 0;//
lastWIFICheck = 0;//
lastCountWiFi = 0;
countWIFILoop = 0;//
countLoopWIFI = 0;
offWIFIcount = 0;//
}
void loop()
{
delay(200);
cloudOutDisconnect();//Function to turn off WiFi if cloud has been disconnected for 5 minutes
onWifiAfterOne();//Function to turn Wifi back on after being off for one minute
}
void cloudOutDisconnect()
/*I've had a lot of problems with my photon "breathing green" and locking up the program. Did a lot of
looking online for solutions and the result is that I added the system thread enabled in the beginning of the
program and added the next two functions to combat that. The first turns off the WiFi if the photon
has been connected to the WiFi but NOT the cloud for 5 minutes. The second turns the WiFi back on
after a minute. I deployed both fixes at the same time and it has worked with no glitches for
over a month. Not really sure if both are needed or just one or the other. All I know is it worked.*/
{
if((!Particle.connected()) && (WiFi.ready()))
{
unsigned long now = millis();
if(now - lastCheck >= 1000)
{
countLoop ++;
lastCheck = millis();
if(countLoop >= 300)
{
WiFi.off();
Serial.print("WiFi turned off at ");
Serial.println(Time.now());
offWIFIcount ++;
countLoop = 0;
}
}
}
else(countLoop = 0);
}
void onWifiAfterOne()
{
if(!WiFi.ready())
{
unsigned long now = millis();
if(now - lastWIFICheck >= 1000)
{
countWIFILoop ++;
lastWIFICheck = millis();
if(countWIFILoop >= 60)
{
WiFi.on();
Serial.print("WiFi turned back on at ");
Serial.println(Time.now());
countWIFILoop = 0;
}
}
}
else(countWIFILoop = 0);
}
Ok. There’s my fix. I hope it helps you out. It’s not fancy or very elegant but it works for me.