Calling WiFi.listen twice fails

On the Photon, calling WiFi.listen the first time succeeds, opens up the softAP, and flashes blue.
Calling, 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:

void setup() {
    unsigned long timing = millis();
    while (millis()-timing<8000) Particle.process();
    timing = millis();
    while (millis()-timing<8000) Particle.process();

void loop() {

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 to allow a proper cleanup when terminating LM.


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