Calling WiFi.listen twice fails

On the Photon, calling WiFi.listen the first time succeeds, opens up the softAP, and flashes blue.
Calling WiFi.off, then WiFi.on, then WiFi.listen the second time fails. The LED continues breathing white and no softAP is opened.
Here is the code to replicate:
SYSTEM_MODE(MANUAL);
SYSTEM_THREAD(ENABLED);

void setup() {
    WiFi.listen();
    unsigned long timing = millis();
    while (millis()-timing<8000) Particle.process();
    WiFi.listen(false);
    WiFi.off();
    timing = millis();
    while (millis()-timing<8000) Particle.process();
    WiFi.on();
    WiFi.listen();
}

void loop() {
    Particle.process();
}

Help is appreciated, am I missing something?

For one, in SYSTEM_MODE(MANUAL) I’d call WiFi.on() before engaging WiFi.listen() for the first time.

Second, what is happening in the 8 seconds while your device is in LM?
Are there any attempts to connect to the SoftAP which might leave some things in some limbo state when terminating LM?
Maybe try adding some delay between WiFi.listen(false) and WiFi.off() to allow a proper cleanup when terminating LM.

3 Likes

That’s a fair first comment. I will say, though, I haven’t had an issue with calling WiFi.listen() without calling WiFi.on().
As for the second comment, nothing is happening, there are no attempts to connect to the SoftAP.
As for the third comment, you hit the nail on the head, that solved it. Thanks, ScruffR!

1 Like