I acquired my first photon a few weeks ago, The photon is just awesome for me and the excitement has worn down yet. I have written several apps and uploaded them from cloud successfully and they functioned as i intended them to.
Now my problem is, at the end of the week i flashed a code that used the publish function to print out some values on the cloud, the app was flashed successfully and the photon connected to the cloud and printed out what i needed but after 45 secs the photon disconnected from the cloud and started breathing Green.
why does my photon disconnect from the cloud and how can i solve this?
Note, i have flashed another code locally that does not have the publish function, but the photon still disconnects from cloud after 45 secs.
int ledpin = 7; // attach the LED to this pin (Therephone Use relay one on RELAY SHIELD)
Serial.begin(9600);// initialize serial monitor
Time.zone(3);// Set time zone to France time zone (GMT +1)
pinMode(ledpin, OUTPUT);// initialize ledpin as an output
int nowh = Time.hour();// fecth time in hours from cloud
int nowm = Time.minute();// fetch time in minutes from cloud
if (nowh == 5 || nowh <= 9)// check whether the time is between 05hr and 22 hr, if it is light LED
nowh = Time.hour();// Check time in hours
digitalWrite(ledpin, HIGH);//Light LED
//Particle.publish("LED STATUS ", "ON");
}while(nowh < 9);// Light LED till it is past 21 hrs i.e time is greater than 21hr, therefore its 22hrs
digitalWrite(ledpin,LOW);// if time is not between 05hrs and 22hrs switch off led
// Particle.publish("LED STATUS ", "OFF");
If you read the docs on Particle.publish(), you’ll see the following:
NOTE: Currently, a device can publish at rate of about 1 event/sec, with bursts of up to 4 allowed in 1 second. Back to back burst of 4 messages will take 4 seconds to recover.
thats not the reason why it disconnects though. blinking green indicated that the cloud connection is lost, presumably because you’ve blocked if from connecting for too long.
Cloud interaction is handled between loop executions. Your ‘do while’ loop blocks that for longer than it can sustain, thus dropping the connection. You could try Threading, or manual mode, but in all honesty, it’s probably better to rewrite it to be non-blocking.
Give it a try and let us know if it helped.