[SOLVED]Photon Disconnecting from cloud after a few seconds

Hey Guys,

Help me out here.

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.

  1. why does my photon disconnect from the cloud and how can i solve this?

  2. Note, i have flashed another code locally that does not have the publish function, but the photon still disconnects from cloud after 45 secs.

Please help

Having your code shared would help us look for potential issues :slight_smile:

int ledpin = 7; // attach the LED to this pin (Therephone Use relay one on RELAY SHIELD)

void setup()
    {
        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
    }
    
void loop()
    {
        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
            {
              do
              {
                  nowh = Time.hour();// Check time in hours
                  digitalWrite(ledpin, HIGH);//Light LED
                  Serial.print(nowh);
                  Serial.print(":");
                  Serial.println(nowm);
                  //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
              
            }
       else 
        {
            digitalWrite(ledpin,LOW);// if time is not between 05hrs and 22hrs switch off led
            Serial.println(nowh);
            // Particle.publish("LED STATUS ", "OFF");
        }
    }

@kennethlimcp thanks kenneth, i have shared the code above, it’s just a simple code

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.

@Moors7 Thanks Moors, let me try that

1 Like

@Moors7 Thanks Moors, It worked now i connected to cloud continuously :smiley:

Thanks

Glad to hear that!

There were a couple of things in there, what exactly worked ;)?

The photon is not disconnecting from the cloud, i removed the do-while loop so the photon is staying continuously connected to cloud

1 Like