bozimmerman/Zimodem

Connecting to wifi fails first time

Closed this issue · 0 comments

When I try to connect to my wifi it always fail the first time. Second time it works. I tried some modifications of the code. After changing the connectWifi function a bit it works for me. Not sure why... this is my working code:

static bool connectWifi(const char* ssid, const char* password)
{
int WiFiCounter = 0;
//if(WiFi.status() == WL_CONNECTED)
// WiFi.disconnect();
WiFi.mode(WIFI_STA);
WiFi.begin(ssid, password);
boolean amConnected = false;
//delay(1000);
while ((!amConnected) && (WiFiCounter < 10))
{
WiFiCounter++;
amConnected = (WiFi.status() == WL_CONNECTED) && (strcmp(WiFi.localIP().toString().c_str(), "0.0.0.0")!=0);
if(!amConnected)
{
delay(500);
}
}
wifiConnected = amConnected;
if (!amConnected)
{
WiFi.disconnect();
}
return wifiConnected;
}