[GH-ISSUE #336] Unable to connect to a new AP if currently connected to the old AP #280

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

Originally created by @babitsky on GitHub (Mar 22, 2017).
Original GitHub issue: https://github.com/tzapu/WiFiManager/issues/336

Hello,

I'm calling startConfigPortal on demand.
The module is currently connected to AP "x".
Using the config portal, I select a new AP "y", with new credentials.
The module attempts to connect to the new AP "y", but "fails" (inappropriate optimization for this scenario) since it remains connected to "x":

*WM: Sent wifi save page
*WM: Connecting to new AP
*WM: Connecting as wifi client...
*WM: Already connected. Bailing out.

New AP "y" and its credentials are therefore lost.
Module remains connected to "x".

Originally created by @babitsky on GitHub (Mar 22, 2017). Original GitHub issue: https://github.com/tzapu/WiFiManager/issues/336 Hello, I'm calling startConfigPortal on demand. The module is currently connected to AP "x". Using the config portal, I select a new AP "y", with new credentials. The module attempts to connect to the new AP "y", but "fails" (inappropriate optimization for this scenario) since it remains connected to "x": ``` *WM: Sent wifi save page *WM: Connecting to new AP *WM: Connecting as wifi client... *WM: Already connected. Bailing out. ``` New AP "y" and its credentials are therefore lost. Module remains connected to "x".
kerem 2026-02-28 01:24:29 +03:00
  • closed this issue
  • added the
    bug
    label
Author
Owner

@pbecchi commented on GitHub (Mar 25, 2017):

I have exactly the same problem!
One I am connected to an AP I cannot change it with startconfigportal call!

<!-- gh-comment-id:289218813 --> @pbecchi commented on GitHub (Mar 25, 2017): I have exactly the same problem! One I am connected to an AP I cannot change it with startconfigportal call!
Author
Owner

@telanoc commented on GitHub (Mar 30, 2017):

I would add WiFi.disconnect(true) to force a disconnection (and clearing of saved credentials) before calling startConfigPortal().

<!-- gh-comment-id:290305261 --> @telanoc commented on GitHub (Mar 30, 2017): I would add `WiFi.disconnect(true)` to force a disconnection (and clearing of saved credentials) before calling `startConfigPortal()`.
Author
Owner

@tzapu commented on GitHub (Mar 30, 2017):

hi guys,
this is a bug in the library, the disconnect trick will work as a workaround

cheers

<!-- gh-comment-id:290364358 --> @tzapu commented on GitHub (Mar 30, 2017): hi guys, this is a bug in the library, the disconnect trick will work as a workaround cheers
Author
Owner

@mouk commented on GitHub (Apr 18, 2017):

@tzapu has this bug been reported?

<!-- gh-comment-id:294959999 --> @mouk commented on GitHub (Apr 18, 2017): @tzapu has this bug been reported?
Author
Owner

@babitsky commented on GitHub (Apr 18, 2017):

@telanoc I'm not sure clearing the credentials is the best solution... At least not for my application.

My suggestion is to add a check in connectWifi() to make sure the "Already connected. Bailing out." code is not executed when connecting to a new SSID (the && (WiFi.SSID() == ssid) part):

  //fix for auto connect racing issue
  if ((WiFi.status() == WL_CONNECTED) && (WiFi.SSID() == ssid)) {
    DEBUG_WM("Already connected. Bailing out.");
    return WL_CONNECTED;
  }

I plan to submit it as a pull request one day, when I learn how to do it :)
So far, it seems to have solved the problem for me completely.

<!-- gh-comment-id:294970012 --> @babitsky commented on GitHub (Apr 18, 2017): @telanoc I'm not sure clearing the credentials is the best solution... At least not for my application. My suggestion is to add a check in ```connectWifi()``` to make sure the "Already connected. Bailing out." code is not executed when connecting to a new SSID (the ```&& (WiFi.SSID() == ssid)``` part): ``` //fix for auto connect racing issue if ((WiFi.status() == WL_CONNECTED) && (WiFi.SSID() == ssid)) { DEBUG_WM("Already connected. Bailing out."); return WL_CONNECTED; } ``` I plan to submit it as a pull request one day, when I learn how to do it :) So far, it seems to have solved the problem for me completely.
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#280
No description provided.