Skip to content

Commit cbbe2ff

Browse files
author
Veijo Pesonen
committed
ESP8266: retry reset attempt once in failure
1 parent 2d6b63d commit cbbe2ff

File tree

1 file changed

+16
-12
lines changed

1 file changed

+16
-12
lines changed

components/wifi/esp8266-driver/ESP8266/ESP8266.cpp

Lines changed: 16 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -256,23 +256,27 @@ bool ESP8266::reset(void)
256256
unsigned long int start_time = rtos::Kernel::get_ms_count();
257257
_reset_done = false;
258258
set_timeout(ESP8266_RECV_TIMEOUT);
259-
if (!_parser.send("AT+RST") || !_parser.recv("OK\n")) {
260-
tr_debug("reset(): AT+RST failed or no response");
261-
goto EXIT;
262-
}
259+
for (int i = 0; i < 2; i++) {
260+
if (!_parser.send("AT+RST") || !_parser.recv("OK\n")) {
261+
tr_debug("reset(): AT+RST failed or no response");
262+
continue;
263+
}
263264

264-
_rmutex.lock();
265-
while ((rtos::Kernel::get_ms_count() - start_time < ESP8266_BOOTTIME) && !_reset_done) {
266-
_process_oob(ESP8266_RECV_TIMEOUT, true); // UART mutex claimed -> need to check for OOBs ourselves
267-
_reset_check.wait_for(100); // Arbitrary relatively short delay
268-
}
265+
_rmutex.lock();
266+
while ((rtos::Kernel::get_ms_count() - start_time < ESP8266_BOOTTIME) && !_reset_done) {
267+
_process_oob(ESP8266_RECV_TIMEOUT, true); // UART mutex claimed -> need to check for OOBs ourselves
268+
_reset_check.wait_for(100); // Arbitrary relatively short delay
269+
}
269270

270-
done = _reset_done;
271-
_rmutex.unlock();
271+
done = _reset_done;
272+
_rmutex.unlock();
273+
if (done) {
274+
break;
275+
}
276+
}
272277

273278
tr_debug("reset(): done: %s", done ? "OK" : "FAIL");
274279

275-
EXIT:
276280
_clear_socket_packets(ESP8266_ALL_SOCKET_IDS);
277281
set_timeout();
278282
_smutex.unlock();

0 commit comments

Comments
 (0)