Particle.connected test in loop not working

I want to show an indicator led for the connection of my Electron to the cloud. for this reason I wrote following code:

 void loop(){
// check if connected to cloud
if (Particle.connected()){
    Status = 0; // Status OK
}else{
    Status = 1; // Status Error
}

switch(Status){
    case 0:
    digitalWrite(D0, HIGH);
    break;
    
    case 1:
    digitalWrite(D0, HIGH);
    delay(500);
    digitalWrite(D0, LOW);
    delay(500);
    break;
}

So theoretically the LED on D0 should blink until connected.
Instead it is dark during the status LED is flashing green and it goes on when the connection is established so the status LED is slowly blinking cyan.

Does this mean that the loop is not entered until the connection is established?

Any ideas?

Yes, this does mean exactly that and this is the intended behaviour for default SYSTEM_MODE(AUTOMATIC).

If you want to have your code run before hand have a look at the docs about SYSTEM_MODE()

2 Likes

Thanks for this information. I was not aware about the system modes. will try it out.