Skip to content

Commit f2abdcb

Browse files
author
Cruz Monrreal
authored
Merge pull request #9639 from michalpasztamobica/esp8266_connect_timeout
ESP8266: connect() checks errors from ESP chip
2 parents d36ebe7 + 6a184da commit f2abdcb

File tree

3 files changed

+13
-8
lines changed

3 files changed

+13
-8
lines changed

TESTS/network/wifi/main.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ using namespace utest::v1;
5252

5353
utest::v1::status_t test_setup(const size_t number_of_cases)
5454
{
55-
GREENTEA_SETUP(240, "default_auto");
55+
GREENTEA_SETUP(360, "default_auto");
5656
return verbose_test_setup_handler(number_of_cases);
5757
}
5858

components/wifi/esp8266-driver/ESP8266Interface.cpp

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,7 @@ ESP8266Interface::ESP8266Interface()
5858
_if_blocking(true),
5959
_if_connected(_cmutex),
6060
_initialized(false),
61+
_connect_retval(NSAPI_ERROR_OK),
6162
_conn_stat(NSAPI_STATUS_DISCONNECTED),
6263
_conn_stat_cb(NULL),
6364
_global_event_queue(NULL),
@@ -187,18 +188,19 @@ void ESP8266Interface::_connect_async()
187188
_cmutex.unlock();
188189
return;
189190
}
190-
191-
if (_esp.connect(ap_ssid, ap_pass) != NSAPI_ERROR_OK) {
191+
_connect_retval = _esp.connect(ap_ssid, ap_pass);
192+
if (_connect_retval == NSAPI_ERROR_OK || _connect_retval == NSAPI_ERROR_AUTH_FAILURE
193+
|| _connect_retval == NSAPI_ERROR_NO_SSID) {
194+
_connect_event_id = 0;
195+
_if_connected.notify_all();
196+
} else {
192197
// Postpone to give other stuff time to run
193198
_connect_event_id = _global_event_queue->call_in(ESP8266_CONNECT_TIMEOUT, callback(this, &ESP8266Interface::_connect_async));
194199

195200
if (!_connect_event_id) {
196201
MBED_ERROR(MBED_MAKE_ERROR(MBED_MODULE_DRIVER, MBED_ERROR_CODE_ENOMEM), \
197202
"_connect_async(): unable to add event to queue");
198203
}
199-
} else {
200-
_connect_event_id = 0;
201-
_if_connected.notify_all();
202204
}
203205
_cmutex.unlock();
204206
}
@@ -235,6 +237,7 @@ int ESP8266Interface::connect()
235237

236238
_cmutex.lock();
237239

240+
_connect_retval = NSAPI_ERROR_NO_CONNECTION;
238241
MBED_ASSERT(!_connect_event_id);
239242
_connect_event_id = _global_event_queue->call(callback(this, &ESP8266Interface::_connect_async));
240243

@@ -243,13 +246,14 @@ int ESP8266Interface::connect()
243246
"connect(): unable to add event to queue");
244247
}
245248

246-
while (_if_blocking && (_conn_status_to_error() != NSAPI_ERROR_IS_CONNECTED)) {
249+
while (_if_blocking && (_conn_status_to_error() != NSAPI_ERROR_IS_CONNECTED)
250+
&& (_connect_retval == NSAPI_ERROR_NO_CONNECTION)) {
247251
_if_connected.wait();
248252
}
249253

250254
_cmutex.unlock();
251255

252-
return NSAPI_ERROR_OK;
256+
return _connect_retval;
253257
}
254258

255259
int ESP8266Interface::set_credentials(const char *ssid, const char *pass, nsapi_security_t security)

components/wifi/esp8266-driver/ESP8266Interface.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -368,6 +368,7 @@ class ESP8266Interface : public NetworkStack, public WiFiInterface {
368368
bool _get_firmware_ok();
369369
nsapi_error_t _init(void);
370370
void _hw_reset();
371+
nsapi_error_t _connect_retval;
371372

372373
//sigio
373374
struct {

0 commit comments

Comments
 (0)