From ab1a51130f74d71cb9cc3691ad6ec116ce1f0576 Mon Sep 17 00:00:00 2001 From: Veijo Pesonen Date: Wed, 17 Oct 2018 12:44:45 +0300 Subject: [PATCH] Fixes disconnect to not rely on C++11 --- ESP8266Interface.cpp | 14 ++++++++++---- ESP8266Interface.h | 2 +- 2 files changed, 11 insertions(+), 5 deletions(-) diff --git a/ESP8266Interface.cpp b/ESP8266Interface.cpp index 7c23ec1..5bc5556 100644 --- a/ESP8266Interface.cpp +++ b/ESP8266Interface.cpp @@ -250,7 +250,16 @@ int ESP8266Interface::set_channel(uint8_t channel) int ESP8266Interface::disconnect() { - return _esp.disconnect() ? NSAPI_ERROR_OK : NSAPI_ERROR_DEVICE_ERROR; + int ret = _esp.disconnect() ? NSAPI_ERROR_OK : NSAPI_ERROR_DEVICE_ERROR; + + if (ret == NSAPI_ERROR_OK) { + // Try to lure the nw status update from ESP8266, might come later + _esp.bg_process_oob(ESP8266_RECV_TIMEOUT, true); + // In case the status update arrives later + _conn_stat = NSAPI_STATUS_DISCONNECTED; + } + + return ret; } const char *ESP8266Interface::get_ip_address() @@ -640,9 +649,6 @@ void ESP8266Interface::attach(mbed::Callback stat nsapi_connection_status_t ESP8266Interface::get_connection_status() const { - if (_initialized) { - _esp.bg_process_oob(ESP8266_RECV_TIMEOUT, true); - } return _conn_stat; } diff --git a/ESP8266Interface.h b/ESP8266Interface.h index 643480a..ebd6411 100644 --- a/ESP8266Interface.h +++ b/ESP8266Interface.h @@ -332,7 +332,7 @@ class ESP8266Interface : public NetworkStack, public WiFiInterface private: // AT layer - mutable ESP8266 _esp; + ESP8266 _esp; void update_conn_state_cb(); // Credentials