[GH-ISSUE #887] Autoconnect only if credentials are saved #749

Open
opened 2026-02-28 01:26:53 +03:00 by kerem · 7 comments
Owner

Originally created by @malaki86 on GitHub (May 15, 2019).
Original GitHub issue: https://github.com/tzapu/WiFiManager/issues/887

I have a project that can use WiFi, but it's not required. What I'm looking for is a way to only attempt to autoconnect if there is already a WiFi connection saved. If not, skip it and the user can hit a button later on to start the AP config page.

I know that I can use the config page timeout, but I don't want the system to 'hang'.

Originally created by @malaki86 on GitHub (May 15, 2019). Original GitHub issue: https://github.com/tzapu/WiFiManager/issues/887 I have a project that can use WiFi, but it's not required. What I'm looking for is a way to only attempt to autoconnect if there is already a WiFi connection saved. If not, skip it and the user can hit a button later on to start the AP config page. I know that I can use the config page timeout, but I don't want the system to 'hang'.
Author
Owner

@tablatronix commented on GitHub (May 15, 2019):

You should be able to just getssid and check but its a little different in esp32

<!-- gh-comment-id:492462977 --> @tablatronix commented on GitHub (May 15, 2019): You should be able to just getssid and check but its a little different in esp32
Author
Owner

@SomeGuyNamedJay commented on GitHub (May 15, 2019):

Does this work for you?

  if (WiFi.SSID()=="")
  {
    Serial.println("Blank");
  }
  else
  {
    Serial.println(WiFi.SSID());
    WiFi.begin(WiFi.SSID(), WiFi.psk());
  }
<!-- gh-comment-id:492632918 --> @SomeGuyNamedJay commented on GitHub (May 15, 2019): Does this work for you? ``` if (WiFi.SSID()=="") { Serial.println("Blank"); } else { Serial.println(WiFi.SSID()); WiFi.begin(WiFi.SSID(), WiFi.psk()); } ```
Author
Owner

@malaki86 commented on GitHub (May 15, 2019):

I saw the getssid in the keywords file, but when I try to use it, I get a 'function not defined' error

WiFi.SSID returns the SSID for the current, active WiFi connection. I need to read the saved one, if it exists. It will always return a blank response before connecting.

<!-- gh-comment-id:492681307 --> @malaki86 commented on GitHub (May 15, 2019): I saw the getssid in the keywords file, but when I try to use it, I get a 'function not defined' error WiFi.SSID returns the SSID for the current, active WiFi connection. I need to read the saved one, if it exists. It will always return a blank response before connecting.
Author
Owner

@tablatronix commented on GitHub (May 15, 2019):

Yeah that is the behavior on esp32 also, if you want to read the saved ssid you might have to read directly from the config struct.

   // esp8266
    struct station_config conf;
    wifi_station_get_config_default(&conf);
    // conf.ssid;
<!-- gh-comment-id:492762476 --> @tablatronix commented on GitHub (May 15, 2019): Yeah that is the behavior on esp32 also, if you want to read the saved ssid you might have to read directly from the config struct. ```C++ // esp8266 struct station_config conf; wifi_station_get_config_default(&conf); // conf.ssid; ```
Author
Owner

@tablatronix commented on GitHub (May 15, 2019):

on esp32 it is

String WiFiManager::WiFi_SSID(){
  #ifdef ESP8266
    return WiFi.SSID();
  #elif defined(ESP32)
    //@todo , workaround only when not connected
    wifi_config_t conf;
    esp_wifi_get_config(WIFI_IF_STA, &conf);
    return String(reinterpret_cast<const char*>(conf.sta.ssid));
  #endif
}
<!-- gh-comment-id:492762748 --> @tablatronix commented on GitHub (May 15, 2019): on esp32 it is ```C++ String WiFiManager::WiFi_SSID(){ #ifdef ESP8266 return WiFi.SSID(); #elif defined(ESP32) //@todo , workaround only when not connected wifi_config_t conf; esp_wifi_get_config(WIFI_IF_STA, &conf); return String(reinterpret_cast<const char*>(conf.sta.ssid)); #endif } ```
Author
Owner

@tablatronix commented on GitHub (May 15, 2019):

Might be nice to make a getter for this
I think I made one once and removed it, sorry about that, no getssid exists

<!-- gh-comment-id:492762996 --> @tablatronix commented on GitHub (May 15, 2019): Might be nice to make a getter for this I think I made one once and removed it, sorry about that, no getssid exists
Author
Owner

@malaki86 commented on GitHub (May 21, 2019):

It wouldn't even have to return the actual SSID or password that WiFiManager has saved. It could be a simple boolean return value.

Example:
if WiFiManager.Saved == TRUE {
WiFiManager.autoconnect;
}

<!-- gh-comment-id:494197446 --> @malaki86 commented on GitHub (May 21, 2019): It wouldn't even have to return the actual SSID or password that WiFiManager has saved. It could be a simple boolean return value. Example: if WiFiManager.Saved == TRUE { WiFiManager.autoconnect; }
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#749
No description provided.