@@ -169,7 +169,10 @@ void ESP8266Interface::_oob2global_event_queue()
169
169
170
170
int ESP8266Interface::connect ()
171
171
{
172
- nsapi_error_t status;
172
+ nsapi_error_t status = _conn_status_to_error ();
173
+ if (status != NSAPI_ERROR_NO_CONNECTION) {
174
+ return status;
175
+ }
173
176
174
177
if (strlen (ap_ssid) == 0 ) {
175
178
return NSAPI_ERROR_NO_SSID;
@@ -199,6 +202,11 @@ int ESP8266Interface::connect()
199
202
200
203
int ESP8266Interface::set_credentials (const char *ssid, const char *pass, nsapi_security_t security)
201
204
{
205
+ nsapi_error_t status = _conn_status_to_error ();
206
+ if (status != NSAPI_ERROR_NO_CONNECTION) {
207
+ return status;
208
+ }
209
+
202
210
_ap_sec = security;
203
211
204
212
if (!ssid) {
@@ -246,8 +254,8 @@ int ESP8266Interface::disconnect()
246
254
{
247
255
_initialized = false ;
248
256
249
- if (_conn_stat == NSAPI_STATUS_DISCONNECTED || ! get_ip_address ())
250
- {
257
+ nsapi_error_t status = _conn_status_to_error ();
258
+ if (status == NSAPI_ERROR_NO_CONNECTION || ! get_ip_address ()) {
251
259
return NSAPI_ERROR_NO_CONNECTION;
252
260
}
253
261
@@ -716,4 +724,27 @@ void ESP8266Interface::proc_oob_evnt()
716
724
_esp.bg_process_oob (ESP8266_RECV_TIMEOUT, true );
717
725
}
718
726
727
+ nsapi_error_t ESP8266Interface::_conn_status_to_error ()
728
+ {
729
+ nsapi_error_t ret;
730
+
731
+ _esp.bg_process_oob (ESP8266_RECV_TIMEOUT, true );
732
+
733
+ switch (_conn_stat) {
734
+ case NSAPI_STATUS_DISCONNECTED:
735
+ ret = NSAPI_ERROR_NO_CONNECTION;
736
+ break ;
737
+ case NSAPI_STATUS_CONNECTING:
738
+ ret = NSAPI_ERROR_ALREADY;
739
+ break ;
740
+ case NSAPI_STATUS_GLOBAL_UP:
741
+ ret = NSAPI_ERROR_IS_CONNECTED;
742
+ break ;
743
+ default :
744
+ ret = NSAPI_ERROR_DEVICE_ERROR;
745
+ }
746
+
747
+ return ret;
748
+ }
749
+
719
750
#endif
0 commit comments