[GH-ISSUE #1220] (Question) Sometimes AP randomly comes back on #1040

Open
opened 2026-02-28 01:28:14 +03:00 by kerem · 18 comments
Owner

Originally created by @bwjohns4 on GitHub (Mar 2, 2021).
Original GitHub issue: https://github.com/tzapu/WiFiManager/issues/1220

I've made a lot of customizations to Wifimanager and everything appears stable, however I see that sometimes the AP randomly starts broadcasting it's SSID well after WiFimanager has gone out of scope? Is this a known issue that sometimes happens, or am I doing something wrong. Is there a way to prevent that, or delete the AP configuration from the ESP8266 after Wifimanager runs? On the devices I've observed this on, it had a previous sketch on it from months ago, then I OTA updated it to newer firmware. Could this be an ESP bug that would go away with erase_flash? Any insight would be appreciated. Is there a way to load a new sketch and check if AP mode is already active or something like that?

Originally created by @bwjohns4 on GitHub (Mar 2, 2021). Original GitHub issue: https://github.com/tzapu/WiFiManager/issues/1220 I've made a lot of customizations to Wifimanager and everything appears stable, however I see that sometimes the AP randomly starts broadcasting it's SSID well after WiFimanager has gone out of scope? Is this a known issue that sometimes happens, or am I doing something wrong. Is there a way to prevent that, or delete the AP configuration from the ESP8266 after Wifimanager runs? On the devices I've observed this on, it had a previous sketch on it from months ago, then I OTA updated it to newer firmware. Could this be an ESP bug that would go away with erase_flash? Any insight would be appreciated. Is there a way to load a new sketch and check if AP mode is already active or something like that?
Author
Owner

@tablatronix commented on GitHub (Mar 2, 2021):

Set WiFi.mode(WIFI_STA) in your sketch, the esp automatically starts aps (EDITED)

If you want only sta mode set it, or else esp will default to sta+ap

<!-- gh-comment-id:789101493 --> @tablatronix commented on GitHub (Mar 2, 2021): Set `WiFi.mode(WIFI_STA)` in your sketch, the esp automatically starts aps **(EDITED)** If you want only sta mode set it, or else esp will default to sta+ap
Author
Owner

@bwjohns4 commented on GitHub (Mar 2, 2021):

Wifimanager usually closes that right? And sets things back to STA mode before returning? Does that sometimes fail and get stuck? I call these two functions, below, in setup() and in general the SSID goes away after wifimanager.autoConnect is complete. It just sometimes comes back randomly after days though. Why is it sporadic and not always that I see the SSID being broadcasted after startup?

wifiManager.setTimeout(600);
wifiManager.autoConnect("MySSID");

I can just add WiFi.mode(WiFi_STA); after autoConnect() if that won't mess anything up. Just curious why this only sometimes happens...

<!-- gh-comment-id:789144116 --> @bwjohns4 commented on GitHub (Mar 2, 2021): Wifimanager usually closes that right? And sets things back to STA mode before returning? Does that sometimes fail and get stuck? I call these two functions, below, in setup() and in general the SSID goes away after wifimanager.autoConnect is complete. It just sometimes comes back randomly after days though. Why is it sporadic and not always that I see the SSID being broadcasted after startup? wifiManager.setTimeout(600); wifiManager.autoConnect("MySSID"); I can just add WiFi.mode(WiFi_STA); after autoConnect() if that won't mess anything up. Just curious why this only sometimes happens...
Author
Owner

@tablatronix commented on GitHub (Mar 2, 2021):

Add it before anything, it gets saved to flash
WM no longer clobbers persistent settings.

<!-- gh-comment-id:789145191 --> @tablatronix commented on GitHub (Mar 2, 2021): Add it before anything, it gets saved to flash WM no longer clobbers persistent settings.
Author
Owner

@bwjohns4 commented on GitHub (Mar 2, 2021):

I still want WiFiManager to go into it's normal config portal mode when needed and broadcast it's SSID when needed. Will adding this before calling WM not prevent that from happening?

<!-- gh-comment-id:789148334 --> @bwjohns4 commented on GitHub (Mar 2, 2021): I still want WiFiManager to go into it's normal config portal mode when needed and broadcast it's SSID when needed. Will adding this before calling WM not prevent that from happening?
Author
Owner

@tablatronix commented on GitHub (Mar 2, 2021):

Nope, thats just ESP default stuff

<!-- gh-comment-id:789148554 --> @tablatronix commented on GitHub (Mar 2, 2021): Nope, thats just ESP default stuff
Author
Owner

@tablatronix commented on GitHub (Mar 2, 2021):

I tried adding a way to force this for consistency with old versions, I guess its not working though

<!-- gh-comment-id:789151309 --> @tablatronix commented on GitHub (Mar 2, 2021): I tried adding a way to force this for consistency with old versions, I guess its not working though
Author
Owner

@bwjohns4 commented on GitHub (Mar 2, 2021):

How does that work? ESP saves the mode in flash and WM starts up an AP without changing the mode and somehow doesn't tamper with the persistent settings in flash? Also, your way of forcing for consistency may still work, I have made lots of tweaks to my copy of WM although I intended to leave everything alone related to the WIFI management portion since I'm not too savvy on the underlying details of that.

<!-- gh-comment-id:789175001 --> @bwjohns4 commented on GitHub (Mar 2, 2021): How does that work? ESP saves the mode in flash and WM starts up an AP without changing the mode and somehow doesn't tamper with the persistent settings in flash? Also, your way of forcing for consistency may still work, I have made lots of tweaks to my copy of WM although I intended to leave everything alone related to the WIFI management portion since I'm not too savvy on the underlying details of that.
Author
Owner

@tablatronix commented on GitHub (Mar 2, 2021):

Are you using esp8266 or esp32 ?

<!-- gh-comment-id:789223928 --> @tablatronix commented on GitHub (Mar 2, 2021): Are you using esp8266 or esp32 ?
Author
Owner

@bwjohns4 commented on GitHub (Mar 2, 2021):

esp8266

<!-- gh-comment-id:789229566 --> @bwjohns4 commented on GitHub (Mar 2, 2021): esp8266
Author
Owner

@tablatronix commented on GitHub (Mar 2, 2021):

Remind me what version you are using again?

<!-- gh-comment-id:789249107 --> @tablatronix commented on GitHub (Mar 2, 2021): Remind me what version you are using again?
Author
Owner

@bwjohns4 commented on GitHub (Mar 2, 2021):

It's off the master branch but I forked it about a month ago and started putting my own tweaks into it. May even be 6 weeks behind the current master

<!-- gh-comment-id:789252252 --> @bwjohns4 commented on GitHub (Mar 2, 2021): It's off the master branch but I forked it about a month ago and started putting my own tweaks into it. May even be 6 weeks behind the current master
Author
Owner

@tablatronix commented on GitHub (Mar 2, 2021):

Oh ok so before dev was merged into master?

hmm, that should not exist in the 0.x versions

What customizations are you making to source code, you should really be using the new version as it lets you do more without modifying code

<!-- gh-comment-id:789310684 --> @tablatronix commented on GitHub (Mar 2, 2021): Oh ok so before dev was merged into master? hmm, that should not exist in the 0.x versions What customizations are you making to source code, you should really be using the new version as it lets you do more without modifying code
Author
Owner

@bwjohns4 commented on GitHub (Mar 3, 2021):

It was after ESP32 portion was merged into master (my application compiles either ESP8266 or ESP32, but I've only noticed this issue so far with ESP8266), so I'm thinking that is what you mean about dev being merged into master. I made these modifications:

  • Added handler for a logo image
  • Added handler for a javascript file
  • Added an input_type to the parameters class so I could add different types of html pieces such as elements A few parameter constructor overloads to take my new parameters Then since my code size was pushing upper limits for a 1M chip, I commented out a bunch of the new features such as OTA and other stuff I wasn't using. I left alone everything related to wifi connection management aspect.
<!-- gh-comment-id:789333998 --> @bwjohns4 commented on GitHub (Mar 3, 2021): It was after ESP32 portion was merged into master (my application compiles either ESP8266 or ESP32, but I've only noticed this issue so far with ESP8266), so I'm thinking that is what you mean about dev being merged into master. I made these modifications: - Added handler for a logo image - Added handler for a javascript file - Added an input_type to the parameters class so I could add different types of html pieces such as <select> elements - A few parameter constructor overloads to take my new parameters - Then since my code size was pushing upper limits for a 1M chip, I commented out a bunch of the new features such as OTA and other stuff I wasn't using. I left alone everything related to wifi connection management aspect.
Author
Owner

@tablatronix commented on GitHub (Mar 3, 2021):

Ok I was looking into defining out some stuff, help strings, ota, info page stuff also , let me know how you managed those, I am looking into making html inputs better and some stuff you mentioned as discussed in other issues and I have some stashed branches I am playing with

<!-- gh-comment-id:789367836 --> @tablatronix commented on GitHub (Mar 3, 2021): Ok I was looking into defining out some stuff, help strings, ota, info page stuff also , let me know how you managed those, I am looking into making html inputs better and some stuff you mentioned as discussed in other issues and I have some stashed branches I am playing with
Author
Owner

@bwjohns4 commented on GitHub (Mar 3, 2021):

Why did you recommend calling WiFi.mode(WiFi_STA) before WM.autoConnect()? Is there any reason not to call it after? I'd prefer the call after WM, just a way of ensuring and future proofing that after WM we always go back to WIFI_STA. Would it hurt to call it before AND after?

<!-- gh-comment-id:790087218 --> @bwjohns4 commented on GitHub (Mar 3, 2021): Why did you recommend calling WiFi.mode(WiFi_STA) before WM.autoConnect()? Is there any reason not to call it after? I'd prefer the call after WM, just a way of ensuring and future proofing that after WM we always go back to WIFI_STA. Would it hurt to call it before AND after?
Author
Owner

@tablatronix commented on GitHub (Mar 3, 2021):

you could also check if mode is not what you want and then change it also.

Technically you are only doing it once, once its saved it never changes, subsequent calls should be ignored by esp lib, but make sure its not causing you disconnects or anything.

Here is the source code, you can see it just returns true

/**
 * set new mode
 * @param m WiFiMode_t
 */
bool WiFiGenericClass::mode(wifi_mode_t m)
{
    wifi_mode_t cm = getMode();
    if(cm == m) {
        return true;
    }
    if(!cm && m){
        if(!espWiFiStart(_persistent)){
            return false;
        }
    } else if(cm && !m){
        return espWiFiStop();
    }

    esp_err_t err;
    err = esp_wifi_set_mode(m);
    if(err){
        log_e("Could not set mode! %d", err);
        return false;
    }
    return true;
}
<!-- gh-comment-id:790115809 --> @tablatronix commented on GitHub (Mar 3, 2021): you could also check if mode is not what you want and then change it also. Technically you are only doing it once, once its saved it never changes, subsequent calls should be ignored by esp lib, but make sure its not causing you disconnects or anything. Here is the source code, you can see it just returns true ```C++ /** * set new mode * @param m WiFiMode_t */ bool WiFiGenericClass::mode(wifi_mode_t m) { wifi_mode_t cm = getMode(); if(cm == m) { return true; } if(!cm && m){ if(!espWiFiStart(_persistent)){ return false; } } else if(cm && !m){ return espWiFiStop(); } esp_err_t err; err = esp_wifi_set_mode(m); if(err){ log_e("Could not set mode! %d", err); return false; } return true; } ```
Author
Owner

@hebertreis commented on GitHub (Mar 14, 2021):

Using the version 2.x this did happen with me, after connected show a open network with SSID starting with ESP- plus 6 last digits from the mac address.

Adding WiFi.mode(WiFi_STA) didn't work, Arduino IDE says that WiFi_STA variable is not declared. Try to look other ways to fix on STA mode but didn't work anyway.

Doing the downgrade to 0.16 version this behavior stop and solved for me.

<!-- gh-comment-id:798823636 --> @hebertreis commented on GitHub (Mar 14, 2021): Using the version 2.x this did happen with me, after connected show a open network with SSID starting with `ESP-` plus 6 last digits from the mac address. Adding `WiFi.mode(WiFi_STA)` didn't work, Arduino IDE says that `WiFi_STA` variable is not declared. Try to look other ways to fix on STA mode but didn't work anyway. Doing the downgrade to 0.16 version this behavior stop and solved for me.
Author
Owner

@tablatronix commented on GitHub (Mar 14, 2021):

Sorry its all caps
WiFi.mode(WIFI_STA); // explicitly set mode, esp defaults to STA+AP

<!-- gh-comment-id:798934538 --> @tablatronix commented on GitHub (Mar 14, 2021): Sorry its all caps `WiFi.mode(WIFI_STA); // explicitly set mode, esp defaults to STA+AP`
Sign in to join this conversation.
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
starred/WiFiManager#1040
No description provided.