[GH-ISSUE #425] AP unstable, specially when there are a lot of networks #357

Closed
opened 2026-02-28 01:24:55 +03:00 by kerem · 9 comments
Owner

Originally created by @Jsolo1 on GitHub (Sep 20, 2017).
Original GitHub issue: https://github.com/tzapu/WiFiManager/issues/425

In a quite enviroment I can very easily connect to the Access point created by Autoconnect. But when there are a lot of Wifi networks around it is impossible to connect to it. Tried with multiple devices across different platforms and none of them can manage to make it work. I found the following issue which seems very similar:

https://github.com/tzapu/WiFiManager/issues/227

Checking with a Wifi Analyzer, the wifi goes on and off:
screenshot_2017-09-20-11-19-23 1

Then I included a few lines of code before the AP is created by the WifiManager:

WiFi.persistent(false);
WiFi.disconnect();
WiFi.persistent(true);
wifi_station_set_reconnect_policy(false);
wifi_station_set_auto_connect(false);

Here the full function:

void WiFiManager::setupConfigPortal() {
  dnsServer.reset(new DNSServer());
  server.reset(new ESP8266WebServer(80));

  DEBUG_WM(F(""));
  _configPortalStart = millis();

  DEBUG_WM(F("Configuring access point... "));
  DEBUG_WM(_apName);
  if (_apPassword != NULL) {
    if (strlen(_apPassword) < 8 || strlen(_apPassword) > 63) {
      // fail passphrase to short or long!
      DEBUG_WM(F("Invalid AccessPoint password. Ignoring"));
      _apPassword = NULL;
    }
    DEBUG_WM(_apPassword);
  }

  //optional soft ip config
  if (_ap_static_ip) {
    DEBUG_WM(F("Custom AP IP/GW/Subnet"));
    WiFi.softAPConfig(_ap_static_ip, _ap_static_gw, _ap_static_sn);
  }
	WiFi.persistent(false);
        WiFi.disconnect();
	WiFi.persistent(true);
	wifi_station_set_reconnect_policy(false);
	wifi_station_set_auto_connect(false);
  if (_apPassword != NULL) {
    WiFi.softAP(_apName, _apPassword,3);//password option
  } else {
    WiFi.softAP(_apName,"",3);
  }

  delay(500); // Without delay I've seen the IP address blank
  DEBUG_WM(F("AP IP address: "));
  DEBUG_WM(WiFi.softAPIP());

  /* Setup the DNS server redirecting all the domains to the apIP */
  dnsServer->setErrorReplyCode(DNSReplyCode::NoError);
  dnsServer->start(DNS_PORT, "*", WiFi.softAPIP());

  /* Setup web pages: root, wifi config pages, SO captive portal detectors and not found. */
  server->on("/", std::bind(&WiFiManager::handleRoot, this));
  server->on("/wifi", std::bind(&WiFiManager::handleWifi, this, true));
  server->on("/0wifi", std::bind(&WiFiManager::handleWifi, this, false));
  server->on("/wifisave", std::bind(&WiFiManager::handleWifiSave, this));
  server->on("/i", std::bind(&WiFiManager::handleInfo, this));
  server->on("/r", std::bind(&WiFiManager::handleReset, this));
  //server->on("/generate_204", std::bind(&WiFiManager::handle204, this));  //Android/Chrome OS captive portal check.
  server->on("/fwlink", std::bind(&WiFiManager::handleRoot, this));  //Microsoft captive portal. Maybe not needed. Might be handled by notFound handler.
  server->onNotFound (std::bind(&WiFiManager::handleNotFound, this));
  server->begin(); // Web server start
  DEBUG_WM(F("HTTP server started"));

}

With no success.

Any ideas?

Thanks

Originally created by @Jsolo1 on GitHub (Sep 20, 2017). Original GitHub issue: https://github.com/tzapu/WiFiManager/issues/425 In a quite enviroment I can very easily connect to the Access point created by Autoconnect. But when there are a lot of Wifi networks around it is impossible to connect to it. Tried with multiple devices across different platforms and none of them can manage to make it work. I found the following issue which seems very similar: https://github.com/tzapu/WiFiManager/issues/227 Checking with a Wifi Analyzer, the wifi goes on and off: <img width="400" alt="screenshot_2017-09-20-11-19-23 1" src="https://user-images.githubusercontent.com/31732759/30642983-088c7744-9e05-11e7-8fae-6cba0b1fc506.png"> Then I included a few lines of code before the AP is created by the WifiManager: ``` WiFi.persistent(false); WiFi.disconnect(); WiFi.persistent(true); wifi_station_set_reconnect_policy(false); wifi_station_set_auto_connect(false); ``` Here the full function: ``` void WiFiManager::setupConfigPortal() { dnsServer.reset(new DNSServer()); server.reset(new ESP8266WebServer(80)); DEBUG_WM(F("")); _configPortalStart = millis(); DEBUG_WM(F("Configuring access point... ")); DEBUG_WM(_apName); if (_apPassword != NULL) { if (strlen(_apPassword) < 8 || strlen(_apPassword) > 63) { // fail passphrase to short or long! DEBUG_WM(F("Invalid AccessPoint password. Ignoring")); _apPassword = NULL; } DEBUG_WM(_apPassword); } //optional soft ip config if (_ap_static_ip) { DEBUG_WM(F("Custom AP IP/GW/Subnet")); WiFi.softAPConfig(_ap_static_ip, _ap_static_gw, _ap_static_sn); } WiFi.persistent(false); WiFi.disconnect(); WiFi.persistent(true); wifi_station_set_reconnect_policy(false); wifi_station_set_auto_connect(false); if (_apPassword != NULL) { WiFi.softAP(_apName, _apPassword,3);//password option } else { WiFi.softAP(_apName,"",3); } delay(500); // Without delay I've seen the IP address blank DEBUG_WM(F("AP IP address: ")); DEBUG_WM(WiFi.softAPIP()); /* Setup the DNS server redirecting all the domains to the apIP */ dnsServer->setErrorReplyCode(DNSReplyCode::NoError); dnsServer->start(DNS_PORT, "*", WiFi.softAPIP()); /* Setup web pages: root, wifi config pages, SO captive portal detectors and not found. */ server->on("/", std::bind(&WiFiManager::handleRoot, this)); server->on("/wifi", std::bind(&WiFiManager::handleWifi, this, true)); server->on("/0wifi", std::bind(&WiFiManager::handleWifi, this, false)); server->on("/wifisave", std::bind(&WiFiManager::handleWifiSave, this)); server->on("/i", std::bind(&WiFiManager::handleInfo, this)); server->on("/r", std::bind(&WiFiManager::handleReset, this)); //server->on("/generate_204", std::bind(&WiFiManager::handle204, this)); //Android/Chrome OS captive portal check. server->on("/fwlink", std::bind(&WiFiManager::handleRoot, this)); //Microsoft captive portal. Maybe not needed. Might be handled by notFound handler. server->onNotFound (std::bind(&WiFiManager::handleNotFound, this)); server->begin(); // Web server start DEBUG_WM(F("HTTP server started")); } ``` With no success. Any ideas? Thanks
kerem 2026-02-28 01:24:55 +03:00
Author
Owner

@tablatronix commented on GitHub (Sep 20, 2017):

This is usually only an issue when you have bad sta info and the esp is trying to connect.

Have you tried erasing the config to see if it stabilizes ?

<!-- gh-comment-id:330845463 --> @tablatronix commented on GitHub (Sep 20, 2017): This is usually only an issue when you have bad sta info and the esp is trying to connect. Have you tried erasing the config to see if it stabilizes ?
Author
Owner

@Jsolo1 commented on GitHub (Sep 20, 2017):

Ok, erasing the credentials makes it stable but there must be a way to stop it from trying to connect over and over, because when the ESP is moved from one network to another, where there are multiple other networks around, it would be impossible to erase/change the credentials unless connecting it to a computer.
Maybe making the function that tries to connect slower? Like every 30 seconds / 1 minute?

<!-- gh-comment-id:330853590 --> @Jsolo1 commented on GitHub (Sep 20, 2017): Ok, erasing the credentials makes it stable but there must be a way to stop it from trying to connect over and over, because when the ESP is moved from one network to another, where there are multiple other networks around, it would be impossible to erase/change the credentials unless connecting it to a computer. Maybe making the function that tries to connect slower? Like every 30 seconds / 1 minute?
Author
Owner

@tablatronix commented on GitHub (Sep 20, 2017):

The workaround is to disable sta mode if not connected when starting the config portal, this is handled in my PR for dev

wifimanager does not do the connecting, you could also disable autoconnect in your own code, or swtich off sta mode before starting configportal

There are a few pull requests that fix this, but they do not address other issues like persistent mode problems.

<!-- gh-comment-id:330856213 --> @tablatronix commented on GitHub (Sep 20, 2017): The workaround is to disable sta mode if not connected when starting the config portal, this is handled in my PR for dev wifimanager does not do the connecting, you could also disable autoconnect in your own code, or swtich off sta mode before starting configportal There are a few pull requests that fix this, but they do not address other issues like persistent mode problems.
Author
Owner

@tablatronix commented on GitHub (Sep 20, 2017):

if(!WiFi.isConnected()){
WiFi.persistent(false);
WiFi.disconnect(); # this alone is not enough to stop the autoconnecter
WiFi.mode(WIFI_AP);
WiFi.persistent(true);
} else WiFi.mode(WIFI_AP_STA);
<!-- gh-comment-id:330862663 --> @tablatronix commented on GitHub (Sep 20, 2017): ``` if(!WiFi.isConnected()){ WiFi.persistent(false); WiFi.disconnect(); # this alone is not enough to stop the autoconnecter WiFi.mode(WIFI_AP); WiFi.persistent(true); } else WiFi.mode(WIFI_AP_STA); ```
Author
Owner

@Jsolo1 commented on GitHub (Sep 20, 2017):

That did the trick, i've also added a small loop to try to connect 5 times before starting the portal, and a timeout in the portal with a reset, that way it's error proof!
Thanks!

<!-- gh-comment-id:330883883 --> @Jsolo1 commented on GitHub (Sep 20, 2017): That did the trick, i've also added a small loop to try to connect 5 times before starting the portal, and a timeout in the portal with a reset, that way it's error proof! Thanks!
Author
Owner

@janoist1 commented on GitHub (Jan 11, 2018):

I seem to be having the same issue: It is very unstable, sometimes it allows me to connect sometimes it doesn't.
It's not fully clear what was the workaround, can you explain it a bit more detailed please? Thanks @tablatronix .

<!-- gh-comment-id:357012216 --> @janoist1 commented on GitHub (Jan 11, 2018): I seem to be having the same issue: It is very unstable, sometimes it allows me to connect sometimes it doesn't. It's not fully clear what was the workaround, can you explain it a bit more detailed please? Thanks @tablatronix .
Author
Owner

@janoist1 commented on GitHub (Jan 12, 2018):

Ok, I think I've got it. Putting the code above into the configModeCallback callback looks to have been resolved my issue. 👍

<!-- gh-comment-id:357175608 --> @janoist1 commented on GitHub (Jan 12, 2018): Ok, I think I've got it. Putting the code above into the `configModeCallback` callback looks to have been resolved my issue. 👍
Author
Owner

@gunhansancar commented on GitHub (Mar 22, 2018):

@janoist1 @tablatronix When I put that code inside configModeCallback it works ok but then in the Config page it doesn't show the available wifi networks. Like the scan function doesn't work anymore.

<!-- gh-comment-id:375373496 --> @gunhansancar commented on GitHub (Mar 22, 2018): @janoist1 @tablatronix When I put that code inside `configModeCallback` it works ok but then in the Config page it doesn't show the available wifi networks. Like the `scan` function doesn't work anymore.
Author
Owner

@tablatronix commented on GitHub (Mar 22, 2018):

no idea, use development version

<!-- gh-comment-id:375402833 --> @tablatronix commented on GitHub (Mar 22, 2018): no idea, use development version
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#357
No description provided.