Bug? ESP8266 wifi.connect2 hangs

JanG

Member
Licensed User
Longtime User
Another problem:
I use Wemos D1. For connecting to WIFI I use the funtion wifi.connect2. But sometimes this function hangs forever. A reset by the button doesn't help. Only a power off/on helps. I checked this behaviour with two diffent Wemos (D1 mini pro and D1 R2).

Maybe this is the same issue:
https://www.b4x.com/android/forum/posts/457328/

And the obove mentioned problem seems to go with this:
https://www.b4x.com/android/forum/threads/memory-leak-in-wifisocket-connecthost.74286/

With the line CallSubPlus("CloseConnection", 200, 0) I don't have this issue, but then I have the other issue. Strange! I can decide between problem A and problem B, but I don't need anything of it...
 
Last edited:

JanG

Member
Licensed User
Longtime User
After searching the net I think I found the solution. You have to edit the function Connect2 in rESP8266WiFi.cpp like that:
B4X:
    bool B4RESPWiFi::Connect2(B4RString* SSID, B4RString* Password) {
        WiFi.persistent(false);
        WiFi.mode(WIFI_STA);
        if (WiFi.status() != WL_CONNECTED){
            WiFi.begin(SSID->data, Password != NULL ? Password->data : NULL);
            while (WiFi.status() != WL_CONNECTED){
                delay(500);
            }
        }
        return WiFi.waitForConnectResult() == WL_CONNECTED;
    }
I think that's the solution. Until now I don't have this long waiting problems and I hope it will remain like that :).
BTW: I deleted a debug line in your code: "available" in checkForClient.
 

Attachments

  • rESP8266WiFi.zip
    1.6 KB · Views: 273
Last edited:

JanG

Member
Licensed User
Longtime User
Yes, it hangs anyway, because the two lines
B4X:
WiFi.persistent(false);
WiFi.mode(WIFI_STA);
do not solve the problem alone. It's the while-waiting:
B4X:
while (WiFi.status() != WL_CONNECTED){
    delay(500);
}
This code can only be integrated if you edit the rESP8266WiFi.cpp.
 
Top