I have been wondering why, after startup, I kept getting these errors logged in the Serial console:
Trying to connect to My Wifi Network. Waiting 1 sec...
Trying to connect to My Wifi Network. Waiting 2 sec...
[ 4756][E][WiFiGeneric.cpp:113] set_esp_interface_ip(): Netif Set IP Failed! 0x5007
Trying to connect to My Wifi Network. Waiting 4 sec...
then up to more than 16 seconds, then a minute... btw, 0x5007 is ESP_ERR_ESP_NETIF_DHCP_NOT_STOPPED
.. or this one:
Trying to connect to My Wifi Network. Waiting 2 sec...
E (11070) wifi:sta is connecting, return error
[ 5381][E][WiFiSTA.cpp:317] begin(): connect failed! 0x3007
Trying to connect to My Wifi Network. Waiting 4 sec...
E (12459) wifi:sta is connecting, return error
[ 6770][E][WiFiSTA.cpp:317] begin(): connect failed! 0x3007
WiFi Connected! IP Address = 192.168.80.118
.. After logging the return value of WiFi.begin() in HomeSpan.cpp, we see it immediately return WL_DISCONNECTED, which is a status set by the WiFi arduino library during the connection attempt.
The issue seems to be that HS is currently calling WiFi.begin() back-to-back, too fast, causing some strange behavior.
Adding WiFi.waitForConnectResult(20000) right after solves this issue:
if(waitTime==32000){
LOG0("\n*** Can't connect to %s. You may type 'W <return>' to re-configure WiFi, or 'X <return>' to erase WiFi credentials. Will try connecting again in 60 seconds.\n\n",network.wifiData.ssid);
waitTime=60000;
} else {
if(verboseWifiReconnect)
addWebLog(true,"Trying to connect to %s. Waiting %d sec...",network.wifiData.ssid,waitTime/1000);
WiFi.begin(network.wifiData.ssid,network.wifiData.pwd);
// Wait 20 seconds maximum for a successful or failed connection
WiFi.waitForConnectResult(20000);
}
Of course, right now 20 seconds is hardcoded, but this is just a connect-timeout value which ideally would be configurable. On my network, this method will exit between 3 and 5.5 seconds, and I no longer see any error on connections.
Any chance to add this fix?
I have been wondering why, after startup, I kept getting these errors logged in the Serial console:
then up to more than 16 seconds, then a minute... btw,
0x5007isESP_ERR_ESP_NETIF_DHCP_NOT_STOPPED.. or this one:
.. After logging the return value of
WiFi.begin()inHomeSpan.cpp, we see it immediately returnWL_DISCONNECTED, which is a status set by the WiFi arduino library during the connection attempt.The issue seems to be that HS is currently calling
WiFi.begin()back-to-back, too fast, causing some strange behavior.Adding
WiFi.waitForConnectResult(20000)right after solves this issue:Of course, right now 20 seconds is hardcoded, but this is just a connect-timeout value which ideally would be configurable. On my network, this method will exit between 3 and 5.5 seconds, and I no longer see any error on connections.
Any chance to add this fix?