From 62108056961ce48bef6d4490175e668dd746e55e Mon Sep 17 00:00:00 2001 From: Russ Butler Date: Mon, 17 Dec 2018 10:11:52 -0600 Subject: [PATCH] Fix ESP8266 "Link Type" errors after reset As part of the ESP8266 connect sequence, ESP8266Interface::connect, a software reset is performed. If the ESP8266 had been connected previously then the ESP8266 will sometimes send a "WIFI DISCONNECT" OOB message before performing the software reset. This causes the ESP8266::_oob_connection_status to change its state (_conn_status) from NSAPI_STATUS_DISCONNECTED to NSAPI_STATUS_CONNECTING. This causes ESP8266Interface::_startup, called later in the boot seqeunce, to skip ESP8266::startup. Without this call socket mux mode (CIPMUX=1) is never enabled and all send commands using this format fail with a "Link Type" error. This patch fixes that problem by unconditionally calling ESP8266::startup as part of the ESP8266 connect sequence. --- .../wifi/esp8266-driver/ESP8266Interface.cpp | 23 +++---------------- .../wifi/esp8266-driver/ESP8266Interface.h | 1 - 2 files changed, 3 insertions(+), 21 deletions(-) diff --git a/components/wifi/esp8266-driver/ESP8266Interface.cpp b/components/wifi/esp8266-driver/ESP8266Interface.cpp index c81af3a91c..51e77a8b1c 100644 --- a/components/wifi/esp8266-driver/ESP8266Interface.cpp +++ b/components/wifi/esp8266-driver/ESP8266Interface.cpp @@ -190,11 +190,6 @@ int ESP8266Interface::connect() return NSAPI_ERROR_IS_CONNECTED; } - status = _startup(ESP8266::WIFIMODE_STATION); - if (status != NSAPI_ERROR_OK) { - return status; - } - if (!_esp.dhcp(true, 1)) { return NSAPI_ERROR_DHCP_FAILURE; } @@ -315,11 +310,6 @@ int ESP8266Interface::scan(WiFiAccessPoint *res, unsigned count) return status; } - status = _startup(ESP8266::WIFIMODE_STATION); - if (status != NSAPI_ERROR_OK) { - return status; - } - return _esp.scan(res, count); } @@ -370,6 +360,9 @@ nsapi_error_t ESP8266Interface::_init(void) if (!_esp.cond_enable_tcp_passive_mode()) { return NSAPI_ERROR_DEVICE_ERROR; } + if (!_esp.startup(ESP8266::WIFIMODE_STATION)) { + return NSAPI_ERROR_DEVICE_ERROR; + } _initialized = true; } @@ -385,16 +378,6 @@ void ESP8266Interface::_hw_reset() _rst_pin.rst_deassert(); } -nsapi_error_t ESP8266Interface::_startup(const int8_t wifi_mode) -{ - if (_conn_stat == NSAPI_STATUS_DISCONNECTED) { - if (!_esp.startup(wifi_mode)) { - return NSAPI_ERROR_DEVICE_ERROR; - } - } - return NSAPI_ERROR_OK; -} - struct esp8266_socket { int id; nsapi_protocol_t proto; diff --git a/components/wifi/esp8266-driver/ESP8266Interface.h b/components/wifi/esp8266-driver/ESP8266Interface.h index b50f9dbfd4..415e291d7d 100644 --- a/components/wifi/esp8266-driver/ESP8266Interface.h +++ b/components/wifi/esp8266-driver/ESP8266Interface.h @@ -353,7 +353,6 @@ private: bool _get_firmware_ok(); nsapi_error_t _init(void); void _hw_reset(); - nsapi_error_t _startup(const int8_t wifi_mode); //sigio struct {