8000 Merge pull request #422 from HanVertegaal/Fix-for-issue-#421 · hasevr/esp32-snippets@5e0e104 · GitHub
[go: up one dir, main page]

Skip to content

Commit 5e0e104

Browse files
authored
Merge pull request nkolban#422 from HanVertegaal/Fix-for-issue-#421
Retry if esp_wifi_connect fails to connect
2 parents 72c02bd + 280aa84 commit 5e0e104

File tree

1 file changed

+10
-7
lines changed

1 file changed

+10
-7
lines changed

cpp_utils/WiFi.cpp

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -194,14 +194,17 @@ bool WiFi::connectAP(const std::string& ssid, const std::string& password, bool
194194
}
195195

196196
m_connectFinished.take("connectAP"); // Take the semaphore to wait for a connection.
197+
do {
198+
ESP_LOGD(LOG_TAG, "esp_wifi_connect");
199+
errRc = ::esp_wifi_connect();
200+
if (errRc != ESP_OK) {
201+
ESP_LOGE(LOG_TAG, "esp_wifi_connect: rc=%d %s", errRc, GeneralUtils::errorToString(errRc));
202+
abort();
203+
}
204+
}
205+
while (!m_connectFinished.take(5000, "connectAP")); // retry if not connected within 5s
206+
m_connectFinished.give();
197207

198-
errRc = ::esp_wifi_connect();
199-
if (errRc != ESP_OK) {
200-
ESP_LOGE(LOG_TAG, "esp_wifi_connect: rc=%d %s", errRc, GeneralUtils::errorToString(errRc));
201-
abort();
202-
}
203-
204-
m_connectFinished.wait("connectAP"); // Wait for the completion of the connection.
205208
ESP_LOGD(LOG_TAG, "<< connectAP");
206209
return m_apConnected; // Return true if we are now connected and false if not.
207210
} // connectAP

0 commit comments

Comments
 (0)
0