Skip to content

WiFiMulti hangs if no DHCP Server is available #3993

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
manholl opened this issue Dec 18, 2017 · 5 comments
Closed

WiFiMulti hangs if no DHCP Server is available #3993

manholl opened this issue Dec 18, 2017 · 5 comments
Assignees
Labels
component: libraries type: bug waiting for feedback Waiting on additional info. If it's not received, the issue may be closed.
Milestone

Comments

@manholl
Copy link

manholl commented Dec 18, 2017

ESP12F
SDK Version 2.3

I use Wifi.begin(SSID, key) to connect to my WLAN - if the DHCP-Server is available- everythink works ok and the "onStationModeGotIP" Event is fired - see last line..

scandone
.f r0, scandone
state: 0 -> 2 (b0)
state: 2 -> 3 (0)
state: 3 -> 5 (10)
add 0
aid 1
cnt 

connected with TML4, channel 1
dhcp client start...
ip:192.168.0.112,mask:255.255.255.0,gw:192.168.0.1
12334 DEBUG  | GOT IP!!!!: 192.168.0.112

But if the DHCP Server is not available the Programm hangs until the Server is available again.
I tried to use the onStationModeDHCPTimeout but it never gets fired..

scandone
.f r0, scandone
state: 0 -> 2 (b0)
state: 2 -> 3 (0)
state: 3 -> 5 (10)
add 0
aid 1
cnt 

connected with TML4, channel 1
dhcp client start...
pm open,type:2 0

I have expected that after some time the "onStationModeDHCPTimeout" Event is fired, or i get a wifi.status so that i can handle that i have no IP. But now my Program hangs - this is a big problem for me, because my ESP is battery powered.. and will not enter deep sleep mode.

@devyte
Copy link
Collaborator

devyte commented Dec 18, 2017

@hotchpotch please retest with latest git, and build with lwip2 (option in menu).

@devyte devyte added the waiting for feedback Waiting on additional info. If it's not received, the issue may be closed. label Dec 18, 2017
@manholl
Copy link
Author

manholl commented Dec 19, 2017

Hello again..
Now i checked it with the latest git build, and after some debugging i found that not Wifi.begin is the problem.
The problem is that i also use WiFiMulti

ESP8266WiFiMulti.cpp Line 112

WiFi.begin(bestNetwork.ssid, bestNetwork.passphrase, bestChannel, bestBSSID);
status = WiFi.status();

            // wait for connection or fail
            while(status != WL_CONNECTED && status != WL_NO_SSID_AVAIL && status != WL_CONNECT_FAILED) {
                delay(10);
                status = WiFi.status();
            }

The while loop hangs here because "status" is WL_DISCONNECTED until a IP Adress is assigned...
WIFI.status() calls wifi_station_get_connect_status() and this function retuns "CONNECTING" but WIFI.status() returns "WL_DISCONNECTED" (switch - default)

@manholl manholl closed this as completed Dec 19, 2017
@manholl manholl reopened this Dec 19, 2017
@igrr igrr changed the title Wifi hangs if no DHCP Server is available WiFiMulti hangs if no DHCP Server is available Dec 27, 2017
@igrr igrr added component: libraries type: bug and removed waiting for feedback Waiting on additional info. If it's not received, the issue may be closed. labels Dec 27, 2017
@igrr igrr added this to the 2.5.0 milestone Dec 27, 2017
@devyte
Copy link
Collaborator

devyte commented Jan 3, 2018

WiFiMulti i meant for networks with a working dhcp server. I think implementing a timeout for that while loop should be enough.

@devyte
Copy link
Collaborator

devyte commented Jan 12, 2018

@manholl @gavanfantom @denisn73 please test PR #4146 . It implements a timeout in the WiFi connection loop inside WiFiMulti. It addresses cases of no DHCP, wrong password, etc.
Most importantly, I have hardcoded a timeout of 5s.

@devyte devyte added the waiting for feedback Waiting on additional info. If it's not received, the issue may be closed. label Jan 12, 2018
@dachshund-digital
Copy link

Anyone have a code example of how to use the following handler? onStationModeDHCPTimeout? I can't seem to find any examples on this specific handler, illustrating its use.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
component: libraries type: bug waiting for feedback Waiting on additional info. If it's not received, the issue may be closed.
Projects
None yet
Development

No branches or pull requests

4 participants