Skip to content

Commit 12fa3e5

Browse files
author
Veijo Pesonen
committed
Fixes AT command timeout values from reset&connect
1 parent 9857ee1 commit 12fa3e5

File tree

1 file changed

+11
-9
lines changed

1 file changed

+11
-9
lines changed

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

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -233,22 +233,25 @@ bool ESP8266::startup(int mode)
233233

234234
bool ESP8266::reset(void)
235235
{
236+
bool done = false;
237+
236238
_smutex.lock();
237239
set_timeout(ESP8266_CONNECT_TIMEOUT);
238240

239241
for (int i = 0; i < 2; i++) {
240242
if (_parser.send("AT+RST")
241243
&& _parser.recv("OK\n")
242244
&& _parser.recv("ready")) {
243-
_clear_socket_packets(ESP8266_ALL_SOCKET_IDS);
244-
_smutex.unlock();
245-
return true;
245+
done = true;
246+
break;
246247
}
247248
}
249+
250+
_clear_socket_packets(ESP8266_ALL_SOCKET_IDS);
248251
set_timeout();
249252
_smutex.unlock();
250253

251-
return false;
254+
return done;
252255
}
253256

254257
bool ESP8266::dhcp(bool enabled, int mode)
@@ -285,14 +288,14 @@ bool ESP8266::cond_enable_tcp_passive_mode()
285288

286289
nsapi_error_t ESP8266::connect(const char *ap, const char *passPhrase)
287290
{
291+
nsapi_error_t ret = NSAPI_ERROR_OK;
292+
288293
_smutex.lock();
289294
set_timeout(ESP8266_CONNECT_TIMEOUT);
290295

291296
_parser.send("AT+CWJAP_CUR=\"%s\",\"%s\"", ap, passPhrase);
292297
if (!_parser.recv("OK\n")) {
293298
if (_fail) {
294-
_smutex.unlock();
295-
nsapi_error_t ret;
296299
if (_connect_error == 1) {
297300
ret = NSAPI_ERROR_CONNECTION_TIMEOUT;
298301
} else if (_connect_error == 2) {
@@ -302,16 +305,15 @@ nsapi_error_t ESP8266::connect(const char *ap, const char *passPhrase)
302305
} else {
303306
ret = NSAPI_ERROR_NO_CONNECTION;
304307
}
305-
306308
_fail = false;
307309
_connect_error = 0;
308-
return ret;
309310
}
310311
}
312+
311313
set_timeout();
312314
_smutex.unlock();
313315

314-
return NSAPI_ERROR_OK;
316+
return ret;
315317
}
316318

317319
bool ESP8266::disconnect(void)

0 commit comments

Comments
 (0)