@@ -55,6 +55,8 @@ ESP8266Interface::ESP8266Interface()
55
55
: _esp(MBED_CONF_ESP8266_TX, MBED_CONF_ESP8266_RX, MBED_CONF_ESP8266_DEBUG, MBED_CONF_ESP8266_RTS, MBED_CONF_ESP8266_CTS),
56
56
_rst_pin(MBED_CONF_ESP8266_RST), // Notice that Pin7 CH_EN cannot be left floating if used as reset
57
57
_ap_sec(NSAPI_SECURITY_UNKNOWN),
58
+ _if_blocking(true ),
59
+ _if_connected(_cmutex),
58
60
_initialized(false ),
59
61
_conn_stat(NSAPI_STATUS_DISCONNECTED),
60
62
_conn_stat_cb(NULL ),
@@ -84,6 +86,8 @@ ESP8266Interface::ESP8266Interface(PinName tx, PinName rx, bool debug, PinName r
84
86
: _esp(tx, rx, debug, rts, cts),
85
87
_rst_pin(rst),
86
88
_ap_sec(NSAPI_SECURITY_UNKNOWN),
89
+ _if_blocking(true ),
90
+ _if_connected(_cmutex),
87
91
_initialized(false ),
88
92
_conn_stat(NSAPI_STATUS_DISCONNECTED),
89
93
_conn_stat_cb(NULL ),
@@ -194,6 +198,7 @@ void ESP8266Interface::_connect_async()
194
198
}
195
199
} else {
196
200
_connect_event_id = 0 ;
201
+ _if_connected.notify_all ();
197
202
}
198
203
_cmutex.unlock ();
199
204
}
@@ -229,14 +234,19 @@ int ESP8266Interface::connect()
229
234
}
230
235
231
236
_cmutex.lock ();
232
- MBED_ASSERT (!_connect_event_id);
233
237
238
+ MBED_ASSERT (!_connect_event_id);
234
239
_connect_event_id = _global_event_queue->call (callback (this , &ESP8266Interface::_connect_async));
235
240
236
241
if (!_connect_event_id) {
237
242
MBED_ERROR (MBED_MAKE_ERROR (MBED_MODULE_DRIVER, MBED_ERROR_CODE_ENOMEM), \
238
243
" connect(): unable to add event to queue" );
239
244
}
245
+
246
+ while (_if_blocking && (_conn_status_to_error () != NSAPI_ERROR_IS_CONNECTED)) {
247
+ _if_connected.wait ();
248
+ }
249
+
240
250
_cmutex.unlock ();
241
251
242
252
return NSAPI_ERROR_OK;
@@ -795,4 +805,12 @@ nsapi_error_t ESP8266Interface::_conn_status_to_error()
795
805
return ret;
796
806
}
797
807
808
+ nsapi_error_t ESP8266Interface::set_blocking (bool blocking)
809
+ {
810
+ _if_blocking = blocking;
811
+
812
+ return NSAPI_ERROR_OK;
813
+ }
814
+
815
+
798
816
#endif
0 commit comments