Skip to content

Instantly share code, notes, and snippets.

@anthonywebb
Created August 21, 2015 23:38
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save anthonywebb/fe2b5958c6d42f07d6aa to your computer and use it in GitHub Desktop.
Save anthonywebb/fe2b5958c6d42f07d6aa to your computer and use it in GitHub Desktop.
WiFi.listen() issues
STARTUP(WiFi.selectAntenna(ANT_EXTERNAL));
// we will handle wifi manually
SYSTEM_MODE(SEMI_AUTOMATIC);
void setup() {
Serial.begin(9600); // open serial over USB
delay(3000);
Serial.println("connecting to wifi");
WiFi.connect();
if(!WiFi.ready()){
Serial.println("no wifi, going into listen mode");
WiFi.listen();
// only listen for a while
unsigned int stopTryingToListen = millis() + 180000;
while(millis() < stopTryingToListen){
// waiting for some credentials
}
// did not get any new creds reset the device
Serial.println("did not get any new creds, reset the device");
System.reset();
} else {
Serial.println("wifi is ready to go");
}
Spark.connect();
}
void loop() {
}
@m-mcgowan
Copy link

Hi there! Looking over this script I'm unsure how this could ever have worked. Here's some things that I see:

  • WiFi.connect, followed by WiFi.ready() - this will work on the Photon but not in general since WiFi.connect() is potentially an asynchronous operation. (So this doesn't cause a problem here, but raises a red flag in my mind!)
  • WiFI.listen() is always an asynchronous call. The listening doesn't happen until the background loop is executed. So your loop will just wait the given timeout then exit. I can promise you it's always been like this!

There is a bug in 0.4.4 that the first call to connect fails. So as a workaround try duplicating WiFi.connect();

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment