Hi,
This is more likely a problem of ESP8266 itself, but I will post it here just in case there is something in the ESP8266 driver.
With Mbed-OS-5.15, ESP8266 mostly working fine. But upon careful inspection, I noticed that it will constantly lose connection with router then re-connects by itself shortly after.
Some post claims that the problem will go away once sleep mode is disabled. In mbed’s case, setting sleep mode at the time of connect to ESP8266 doesn’t seem do help much if at all.
// ESP8266.cpp
nsapi_error_t ESP8266::connect(const char *ap, const char *passPhrase)
{
nsapi_error_t ret = NSAPI_ERROR_OK;
_smutex.lock();
set_timeout(ESP8266_CONNECT_TIMEOUT);
bool res = _parser.send("AT+CWJAP_CUR=\"%s\",\"%s\"", ap, passPhrase);
if (!res || !_parser.recv("OK\n")) {
if (_fail) {
if (_connect_error == 1) {
ret = NSAPI_ERROR_CONNECTION_TIMEOUT;
} else if (_connect_error == 2) {
ret = NSAPI_ERROR_AUTH_FAILURE;
} else if (_connect_error == 3) {
ret = NSAPI_ERROR_NO_SSID;
} else {
ret = NSAPI_ERROR_NO_CONNECTION;
}
_fail = false;
_connect_error = 0;
}
}
// The following are added lines to ensure sleep mode is turned off
res = _parser.send("AT+SLEEP=0");
if (!res || !_parser.recv("OK\n")) {
printf("%d: ESP8266 set sleep mode failed\r\n", time(nullptr));
} else {
printf("%d: ESP8266 sleep mode set to 0\r\n", time(nullptr));
}
set_timeout();
_smutex.unlock();
return ret;
}
Withe sleep mode turned off, I can see 30mA increase of current draw of the whole system, presumably can be attributed to ESP8266. But ESP8266 still keeps dropping connection.
If we use ESP8266 to connect to a WebSocket server, the connections will disconnect and reconnect mostly in 10 minutes, sometimes longer, like 40 minutes, depending time of the day or something else. If we repeatedly use ESP8266 to make HTTP calls, sometimes we will see:
NSAPI_ERROR_CONNECTION_LOST = -3016, /*!< connection lost */
Such problems don’t happen if we use Ethernet or cellular connection.
I assume the only solution is to customize ESP8266 firmware. Right now we use AT-nonos-1.7.4. Is there anything we can do on MBed side?
Thanks.