Hi guys 
My current setup with my photon looks like this:
WiFi.on();
WiFi.setCredentials(SSID, PASSWORD);
WiFi.connect();
waitFor(WiFi.ready, 60000);
Particle.connect();
What would happen, if we have no wifi connection = after 60 sec the device will jump to Particle.connect(); which will not be successful because of no Wifi signal. Will it block the code until it get’s a connection to the particle cloud? Or will it jump to loop but still try to establish a connection?
AFAIK, calling Particle.connect() will call WiFi.connect() and can block depending on whether you have the system thread enabled.
I think you should specify what you want the photon to do if the WiFi connection is not established within 60 seconds.
if (!waitFor(WiFi.ready, 60000))
{
// The code in this block will execute if the waitFor times out
// Maybe sleep the photon?
}
1 Like
From photon Reference:
Functions should return 0/false to indicate waiting, or non-zero/true to stop waiting. bool
or int
are valid return types. If a complex expression is required, a separate function should be created to evaluate that expression.
in case that your void setup () looks like that:
void setup () {
WiFi.on();
WiFi.setCredentials(SSID, PASSWORD);
WiFi.connect();
waitFor(WiFi.ready, 60000);
Particle.connect();
}
waitFor(WiFi.ready, 60000);
will do nothing.
You should wrap waitFor()
with some "If"
and "else"
statement and then, depends what waitFor()
returns, make next steps.
Also for waitFor() you should have SYSTEM_THREAD(ENABLED)
and also consider SEMI_AUTOMATIC
too
2 Likes
I’m using SYSTEM_THREAD(ENABLED). If the photon isn’'t able to connect to the wifi within 60 sec it should jump to void loop and just as normal run the loop but still retry to get a wifi connection