Friends,
I’ve been trying to figure out how to make WiFi optional for my Photon projects. I.e. I want the device to look for WiFi on power up and connect if it’s there… but if no wifi is found, I want it to run anyway. The reason i need this is that the function of the thing I’m building doesn’t need Cloud connection… but I don’t want to give up the ability to reflash it wirelessly when wifi is around.
I saw several discussions about SYSTEM_MODE(SEMI_AUTOMATIC); that tell one how to connect on a button press, etc…but my device is sealed… so buttons are problematic… I’ve yet to see a complete example that tries to connect on power-up, but continues when none is available. (quite a bit of discussion here Create time out for Spark.connect()?) … but no conclusion.
here’s what I’m trying to do :
-i put the device in SEMI_AUTOMATIC mode
-In my loop, I check if WiFI is not connected, If not,
— I try a routine that Sets a TImer, then tries to connect.
—if connect is successful, I kill the timer
— if instead the timer times out, I call disconnect, in the hopes it will ‘unblock’ the attempt to connect. (see my psuedo code example below)
Short story is It doesn’t work… , the connect still appears to block… and it never returns…
Does anyone have an example of something that does this ? \I’m trying to make soething for a wedding today… so I’m kinda desperate. Thanks very much !
-jc
#include <SparkIntervalTimer.h>
SYSTEM_MODE(SEMI_AUTOMATIC);
IntervalTimer myTimer;
volatile bool onLine = true;
void noCon(void) {
Particle.disconnect();
onLine = false;
}
void doCon(void) {
myTimer.begin(noCon, 30000, hmSec);
Particle.connect();
myTimer.end();
}
void setup() {
.. setup stuff …..
}
void loop() {
if((onLine && !Particle.connected()) == true) {
doCon();
}
… loop stuff ….
}