Skip to content

Commit

Permalink
FIX: force the wifi radio reset and wifi connection on the first loop…
Browse files Browse the repository at this point in the history
… call

Sometimes, Wifi.status() will return CONNECTED instead of DISCONNECTED at the bigenning and this causes issue to this lib. Now we forces the radio reset and we plan the wifi connection at the first loop call.
  • Loading branch information
Patrick Lapointe committed Sep 7, 2020
1 parent 1faf534 commit 2cd0c42
Showing 1 changed file with 11 additions and 0 deletions.
11 changes: 11 additions & 0 deletions src/EspMQTTClient.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,17 @@ void EspMQTTClient::enableLastWillMessage(const char* topic, const char* message

void EspMQTTClient::loop()
{
static bool firstLoopCall = true;

// When it's the first loop call, reset the wifi radio and schedule the wifi connection
if(firstLoopCall && _wifiSsid != NULL)
{
WiFi.disconnect(true);
_nextWifiConnectionAttemptMillis = millis() + 500;
firstLoopCall = false;
return;
}

// Delayed execution requests handling
processDelayedExecutionRequests();

Expand Down

0 comments on commit 2cd0c42

Please sign in to comment.