khoih-prog / ESPAsync_WiFiManager

This is an ESP32 (including ESP32-S2 and ESP32-C3) / ESP8266 WiFi Connection Manager, using ESPAsyncWebServer, with fallback web configuration portal. Use this library for configuring ESP32, ESP8266 modules' WiFi, etc. Credentials at runtime. You can also specify static DNS servers, personalized HostName, fixed or random AP WiFi channel. With examples supporting ArduinoJson 6.0.0+ as well as 5.13.5- . Using AsyncDNSServer instead of DNSServer now.
MIT License
290 stars 73 forks source link

how to close the AP after successfully connecting to the configured WiFi? #87

Closed slaesh closed 2 years ago

slaesh commented 2 years ago

the AP is still "there", even after connecting to the WiFi! :) Even on every new reset with stored (and valid) SSID/pass!

void wifimanager_setup()
{
    delay(500);

    Serial.print("\nStarting Async_AutoConnect_ESP32_minimal on " + String(ARDUINO_BOARD));
    Serial.println(ESP_ASYNC_WIFIMANAGER_VERSION);

#if (USING_ESP32_S2 || USING_ESP32_C3)
    ESPAsync_WiFiManager ESPAsync_wifiManager(&webServer, NULL, HOSTNAME);
#else
    ESPAsync_WiFiManager ESPAsync_wifiManager(&webServer, &dnsServer, HOSTNAME);
#endif

    ESPAsync_wifiManager.setDebugOutput(true);

    // We can't use WiFi.SSID() in ESP32 as it's only valid after connected.
    // SSID and Password stored in ESP32 wifi_ap_record_t and wifi_config_t are also cleared in reboot
    // Have to create a new function to store in EEPROM/SPIFFS for this purpose
    String Router_SSID = ESPAsync_wifiManager.WiFi_SSID();
    String Router_Pass = ESPAsync_wifiManager.WiFi_Pass();

    // Remove this line if you do not want to see WiFi password printed
    Serial.println("ESP Self-Stored: SSID = " + Router_SSID + ", Pass = " + Router_Pass);

    // ESPAsync_wifiManager.resetSettings();   //reset saved settings
    ESPAsync_wifiManager.setAPStaticIPConfig(IPAddress(192, 168, 132, 1), IPAddress(192, 168, 132, 1), IPAddress(255, 255, 255, 0));
    ESPAsync_wifiManager.autoConnect(AP_NAME);

    if (WiFi.status() == WL_CONNECTED)
    {
        Serial.print(F("Connected. Local IP: "));
        Serial.println(WiFi.localIP());

        // ESPAsync_wifiManager.stopConfigPortal = true;
    }
    else
    {
        Serial.println(ESPAsync_wifiManager.getStatus(WiFi.status()));
    }
}
khoih-prog commented 2 years ago

Hi @slaesh

Please don't use any of the minimal examples as they are just demo to show how you can minimize the code, certainly with minimal features.

Start with other examples, such as Async_ConfigOnDoubleReset, etc.

I'm thinking about deleting all the confusing minimal examples to avoid future issues.

Good Luck,