Go into listening mode if no known networks are available

Yes. Adding WiFi.disconnect() fixes it.

#include "Particle.h"
#include "softap_http.h"

SYSTEM_MODE(MANUAL);
SYSTEM_THREAD(ENABLED);

WiFiAccessPoint ap[5];

int found;

/* SoftAP Stuff
Ommitted */

void setup()
{
        WiFi.on();
        found = WiFi.getCredentials(ap, 5);
        WiFi.connect();
        if(!waitFor(WiFi.ready, found * 15000))
        {
                WiFi.disconnect();
                WiFi.listen();
        }
        else {
                // either procede with your app code while in listening mode
                // or wait forever
                // waitUntil(WiFi.ready);
        }
}


void loop()
{
        if (!WiFi.ready()) // If WiFi connection is interrupted...
        {
                WiFi.connect(); // Attempt to reconnect
                if(!waitFor(WiFi.ready, found * 15000)) // If the connection times out...
                {
                        WiFi.disconnect();
                        WiFi.listen(); // Go into SoftAP setup mode
                }
        }
}
1 Like