[GH-ISSUE #497] How to use WiFiManager only as a fallback if a certain network is not there? #417

Closed
opened 2026-02-28 01:25:11 +03:00 by kerem · 2 comments
Owner

Originally created by @probonopd on GitHub (Jan 29, 2018).
Original GitHub issue: https://github.com/tzapu/WiFiManager/issues/497

I need to use WiFiManager only as a fallback if a certain network (homeNetwork) is not there.

However, if I do the following then apparently the credentials do not get saved and loaded correctly - after a reboot, AutoConnectAP is always spawned.

How to fix this?

#if defined(ESP8266)
#include <ESP8266WiFi.h>          //https://github.com/esp8266/Arduino
#else
#include <WiFi.h>
#endif

#include <DNSServer.h>
#include <ESPAsyncWebServer.h>
#include <ESPAsyncWiFiManager.h>

AsyncWebServer server(80);
DNSServer dns;

void setup() {
  Serial.begin(115200);

  bool homeNetworkAvailable = false;

  // Check if the home network is available
  // it needs some special authentication mechanism through a captive portal
  // (not shown in this example)

  int n = WiFi.scanNetworks();
  randomSeed(ESP.getCycleCount());
  Serial.println("scan done");
  if (n == 0)
    Serial.println("no networks found");
  else
  {
    Serial.print(n);
    Serial.println(" networks found");
    for (int i = 0; i < n; ++i)
    {
      // Print SSID and RSSI for each network found
      Serial.println(WiFi.SSID(i));
      if (WiFi.SSID(i) == "homeNetwork") { // enter the ssid which you want to search
        Serial.println("The homeNetwork network is available, trying to log in");
        homeNetworkAvailable = true;

      }
    }
  }

  // ONLY if the home network is NOT available use AsyncWiFiManager
  // This works only ONCE, after a reboot I get "*WM: No saved credentials
  // FIXME

  if (homeNetworkAvailable == false) {
    AsyncWiFiManager wifiManager(&server, &dns);
    //wifiManager.resetSettings(); // reset settings - for testing
    wifiManager.setTimeout(180);

    if (!wifiManager.autoConnect("AutoConnectAP")) {
      Serial.println("failed to connect and hit timeout");
      delay(3000);
      ESP.reset();
      delay(5000);
    }
  }

  Serial.println("connected...yeey :)");

}

void loop() {
  // put your main code here, to run repeatedly:

}
Originally created by @probonopd on GitHub (Jan 29, 2018). Original GitHub issue: https://github.com/tzapu/WiFiManager/issues/497 I need to use WiFiManager only as a fallback if a certain network (`homeNetwork`) is __not__ there. However, if I do the following then apparently the credentials do not get saved and loaded correctly - after a reboot, `AutoConnectAP` is always spawned. How to fix this? ``` #if defined(ESP8266) #include <ESP8266WiFi.h> //https://github.com/esp8266/Arduino #else #include <WiFi.h> #endif #include <DNSServer.h> #include <ESPAsyncWebServer.h> #include <ESPAsyncWiFiManager.h> AsyncWebServer server(80); DNSServer dns; void setup() { Serial.begin(115200); bool homeNetworkAvailable = false; // Check if the home network is available // it needs some special authentication mechanism through a captive portal // (not shown in this example) int n = WiFi.scanNetworks(); randomSeed(ESP.getCycleCount()); Serial.println("scan done"); if (n == 0) Serial.println("no networks found"); else { Serial.print(n); Serial.println(" networks found"); for (int i = 0; i < n; ++i) { // Print SSID and RSSI for each network found Serial.println(WiFi.SSID(i)); if (WiFi.SSID(i) == "homeNetwork") { // enter the ssid which you want to search Serial.println("The homeNetwork network is available, trying to log in"); homeNetworkAvailable = true; } } } // ONLY if the home network is NOT available use AsyncWiFiManager // This works only ONCE, after a reboot I get "*WM: No saved credentials // FIXME if (homeNetworkAvailable == false) { AsyncWiFiManager wifiManager(&server, &dns); //wifiManager.resetSettings(); // reset settings - for testing wifiManager.setTimeout(180); if (!wifiManager.autoConnect("AutoConnectAP")) { Serial.println("failed to connect and hit timeout"); delay(3000); ESP.reset(); delay(5000); } } Serial.println("connected...yeey :)"); } void loop() { // put your main code here, to run repeatedly: } ```
kerem closed this issue 2026-02-28 01:25:11 +03:00
Author
Owner

@tablatronix commented on GitHub (Jan 29, 2018):

Whats AsyncWiFiManager ?

<!-- gh-comment-id:361249392 --> @tablatronix commented on GitHub (Jan 29, 2018): Whats AsyncWiFiManager ?
Author
Owner

@probonopd commented on GitHub (Jan 29, 2018):

Err, good point @tablatronix - sorry I have mixed up the projects. https://github.com/alanswx/ESPAsyncWiFiManager is a fork of https://github.com/tzapu/WiFiManager/ but async. Closing here and asking there.

I suspect it has something to do with "Using last saved values, should be faster" - apparently doing a network scan confuses this. Is this supposed to work with https://github.com/tzapu/WiFiManager/?

<!-- gh-comment-id:361326889 --> @probonopd commented on GitHub (Jan 29, 2018): Err, good point @tablatronix - sorry I have mixed up the projects. https://github.com/alanswx/ESPAsyncWiFiManager is a fork of https://github.com/tzapu/WiFiManager/ but async. Closing here and asking there. I suspect it has something to do with "Using last saved values, should be faster" - apparently doing a network scan confuses this. Is this supposed to work with https://github.com/tzapu/WiFiManager/?
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#417
No description provided.