[GH-ISSUE #913] Non blocking mode is still very much blocking #773

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

Originally created by @markg85 on GitHub (Jul 13, 2019).
Original GitHub issue: https://github.com/tzapu/WiFiManager/issues/913

Hi,

I'm on the development branch now :)

So i did set "setConfigPortalBlocking" to false and followed that with a process() call in my loop function.

But that's still blocking.
I'm guessing that only make it non blocking in the config portal, aka when there is no connection or it failed to connect. It's still very much blocking at the point where it tries to make a connection.

The function:
uint8_t WiFiManager::connectWifi(String ssid, String pass)

is the one that triggers waiting. It has this if/else statement:

  if (ssid != "") {
    wifiConnectNew(ssid,pass);
    if(_saveTimeout > 0){
      connRes = waitForConnectResult(_saveTimeout); // use default save timeout for saves to prevent bugs in esp->waitforconnectresult loop
    }  
    else {
       connRes = waitForConnectResult(0);
    }
  }
  else {
    // connect using saved ssid if there is one
    if (WiFi_hasAutoConnect()) {
      wifiConnectDefault();
      connRes = waitForConnectResult();
    }
    else {
      DEBUG_WM(F("No saved credentials, skipping wifi"));
    }
  }

And if i follow waitForConnectResult then it actually waits (busy waiting loop) till it has a connection. That's the issue.

I'm looking at how to hack that to be not blocking, to be continued.

Cheers,
Mark

Originally created by @markg85 on GitHub (Jul 13, 2019). Original GitHub issue: https://github.com/tzapu/WiFiManager/issues/913 Hi, I'm on the development branch now :) So i did set "setConfigPortalBlocking" to false and followed that with a process() call in my loop function. But that's still blocking. I'm guessing that only make it non blocking in the **config portal**, aka when there is no connection or it failed to connect. It's still very much blocking at the point where it tries to make a connection. The function: uint8_t WiFiManager::connectWifi(String ssid, String pass) is the one that triggers waiting. It has this if/else statement: ``` if (ssid != "") { wifiConnectNew(ssid,pass); if(_saveTimeout > 0){ connRes = waitForConnectResult(_saveTimeout); // use default save timeout for saves to prevent bugs in esp->waitforconnectresult loop } else { connRes = waitForConnectResult(0); } } else { // connect using saved ssid if there is one if (WiFi_hasAutoConnect()) { wifiConnectDefault(); connRes = waitForConnectResult(); } else { DEBUG_WM(F("No saved credentials, skipping wifi")); } } ``` And if i follow waitForConnectResult then it actually waits (busy waiting loop) till it has a connection. That's the issue. I'm looking at how to hack that to be not blocking, to be continued. Cheers, Mark
Author
Owner

@tablatronix commented on GitHub (Jul 14, 2019):

Thats when you save the portal... not sure what you mean

<!-- gh-comment-id:511213729 --> @tablatronix commented on GitHub (Jul 14, 2019): Thats when you save the portal... not sure what you mean
Author
Owner

@tablatronix commented on GitHub (Jul 14, 2019):

Do you mean autoconnect? You can simple not use it and use your own connect wait loop

<!-- gh-comment-id:511214038 --> @tablatronix commented on GitHub (Jul 14, 2019): Do you mean autoconnect? You can simple not use it and use your own connect wait loop
Author
Owner

@markg85 commented on GitHub (Jul 14, 2019):

In my code i'm calling autoconnect. I obviously want the features of WiFiManager, aka pop up an AP if it can't make a connection and connect to an existing AP if it can. The autoconnect function eventually calls connectWifi where it is trying to connect to an existing AP if no user/pass is given (if both are emtpy). connectWifi is eventually* calling waitForConnectResult which blocks.

I don't think i can use my own connect in my main loop as i would lose the setup part that i also want if i can't make a connection. Unless you tell me otherwise that is :)

I did actually get it to work but it requires quite a different handling of connectWifi and waitForConnectResult. In fact, waitForConnectResult has to be rewritten mostly and put in the process method. I do have much of that now but i'm quite sure i currently broke the setup part... So that's definitely not something i'm going to share now.

* unless it has no credentials, but that defeats the point entirely as i would have no wifi connection.

<!-- gh-comment-id:511215071 --> @markg85 commented on GitHub (Jul 14, 2019): In my code i'm calling autoconnect. I obviously want the features of WiFiManager, aka pop up an AP if it can't make a connection and connect to an existing AP if it can. The `autoconnect` function eventually calls `connectWifi` where it is trying to connect to an existing AP if no user/pass is given (if both are emtpy). `connectWifi` is eventually* calling `waitForConnectResult` which blocks. I don't think i can use my own connect in my main loop as i would lose the setup part that i also want if i can't make a connection. Unless you tell me otherwise that is :) I did actually get it to work but it requires quite a different handling of `connectWifi` and `waitForConnectResult`. In fact, `waitForConnectResult` has to be rewritten mostly and put in the `process` method. I do have much of that now but i'm quite sure i currently broke the setup part... So that's definitely not something i'm going to share now. \* unless it has no credentials, but that defeats the point entirely as i would have no wifi connection.
Author
Owner

@tablatronix commented on GitHub (Jul 14, 2019):

You just startconfigportal when you need it.. see the ondemand example

<!-- gh-comment-id:511219739 --> @tablatronix commented on GitHub (Jul 14, 2019): You just startconfigportal when you need it.. see the ondemand example
Author
Owner

@markg85 commented on GitHub (Jul 14, 2019):

Then how do i make a connection to Wifi?

<!-- gh-comment-id:511221206 --> @markg85 commented on GitHub (Jul 14, 2019): Then how do i make a connection to Wifi?
Author
Owner

@tablatronix commented on GitHub (Jul 14, 2019):

The esp automatically connects to wifi or you can call wifi.begin

<!-- gh-comment-id:511222728 --> @tablatronix commented on GitHub (Jul 14, 2019): The esp automatically connects to wifi or you can call wifi.begin
Author
Owner

@kbickham commented on GitHub (Aug 14, 2019):

It's not blocking as much as the original library did, with that my display would not sync with my controller at all. Dev kit C on a prototype for a dehyrdator machine with a bunch of sensors. This whole deal is fairly timing sensitive. It's now syncing fine, portal is popping up on it's own. I have some indicators running off of if (WiFi.status() == WL_CONNECTED) that didn't go on, but I need to go read the debug uart port so can get iron this out. EDIT- NOPE, It's all good. This is pretty sweet.

<!-- gh-comment-id:521102682 --> @kbickham commented on GitHub (Aug 14, 2019): It's not blocking as much as the original library did, with that my display would not sync with my controller at all. Dev kit C on a prototype for a dehyrdator machine with a bunch of sensors. This whole deal is fairly timing sensitive. It's now syncing fine, portal is popping up on it's own. I have some indicators running off of if (WiFi.status() == WL_CONNECTED) that didn't go on, but I need to go read the debug uart port so can get iron this out. EDIT- NOPE, It's all good. This is pretty sweet.
Author
Owner

@tablatronix commented on GitHub (Aug 14, 2019):

I really suggest not using autoconnect, I would require user long press or special boot sequence to enter config mode for a project like that

<!-- gh-comment-id:521325788 --> @tablatronix commented on GitHub (Aug 14, 2019): I really suggest not using autoconnect, I would require user long press or special boot sequence to enter config mode for a project like that
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#773
No description provided.