@@ -184,13 +184,20 @@ void ESP8266Interface::_connect_async()
184
184
return ;
185
185
}
186
186
_connect_retval = _esp.connect (ap_ssid, ap_pass);
187
+ int timeleft_ms = ESP8266_INTERFACE_CONNECT_TIMEOUT_MS - _conn_timer.read_ms ();
187
188
if (_connect_retval == NSAPI_ERROR_OK || _connect_retval == NSAPI_ERROR_AUTH_FAILURE
188
- || _connect_retval == NSAPI_ERROR_NO_SSID) {
189
+ || _connect_retval == NSAPI_ERROR_NO_SSID
190
+ || ((_if_blocking == true ) && (timeleft_ms <= 0 ))) {
189
191
_connect_event_id = 0 ;
192
+ _conn_timer.stop ();
193
+ if (timeleft_ms <= 0 ) {
194
+ _connect_retval = NSAPI_ERROR_CONNECTION_TIMEOUT;
195
+ }
190
196
_if_connected.notify_all ();
191
197
} else {
192
198
// Postpone to give other stuff time to run
193
- _connect_event_id = _global_event_queue->call_in (ESP8266_CONNECT_TIMEOUT, callback (this , &ESP8266Interface::_connect_async));
199
+ _connect_event_id = _global_event_queue->call_in (ESP8266_INTERFACE_CONNECT_INTERVAL_MS,
200
+ callback (this , &ESP8266Interface::_connect_async));
194
201
if (!_connect_event_id) {
195
202
MBED_ERROR (MBED_MAKE_ERROR (MBED_MODULE_DRIVER, MBED_ERROR_CODE_ENOMEM), \
196
203
" ESP8266Interface::_connect_async(): unable to add event to queue. Increase \" events.shared-eventsize\"\n " );
@@ -233,6 +240,9 @@ int ESP8266Interface::connect()
233
240
234
241
_connect_retval = NSAPI_ERROR_NO_CONNECTION;
235
242
MBED_ASSERT (!_connect_event_id);
243
+ _conn_timer.stop ();
244
+ _conn_timer.reset ();
245
+ _conn_timer.start ();
236
246
_connect_event_id = _global_event_queue->call (callback (this , &ESP8266Interface::_connect_async));
237
247
238
248
if (!_connect_event_id) {
@@ -315,7 +325,7 @@ int ESP8266Interface::disconnect()
315
325
_initialized = false ;
316
326
317
327
nsapi_error_t status = _conn_status_to_error ();
318
- if (status == NSAPI_ERROR_NO_CONNECTION || ! get_ip_address () ) {
328
+ if (status == NSAPI_ERROR_NO_CONNECTION) {
319
329
return NSAPI_ERROR_NO_CONNECTION;
320
330
}
321
331
0 commit comments