Block in the loop when Spark.connect()?

@helxsz, I had this little sketch whiped up for another thread.
As I understand it does something similar to what you want.

SYSTEM_MODE(SEMI_AUTOMATIC);

const uint32_t waitConnect = 5000; // at least 5 sec between reconnect attempts

uint32_t msConnect;
bool firstAttempt;

void setup() 
{
    pinMode(D7, OUTPUT);
    WiFi.connect();
    firstAttempt = false;
}

void loop() 
{
    if (firstAttempt && Spark.connected())
    {
        firstAttempt = false;
    }
    else if(!firstAttempt  && !Spark.connected())
    {
        Spark.connect();
        firstAttempt = true;
        msConnect = millis();
    }

    digitalWrite(D7, (millis() >> 2) & 0x88); // just some LED pattern ;-)
}

Maybe this helps you a bit (I’d hope :sunglasses:)

By first watching the LED pattern stop from time to time and corresond these to the RGB LED, you can get a feeling of what’s going on; where connection blocks your code and where your code is running free.
From this on you can wrap your own conditional code blocks (e.g. WiFi.connecting(), !WiFi.ready(), !Spark.connected(), Spark.connected(), …) around the devices behaviour.

1 Like