Skip to content

ESP8266 "busy s..." fix (ONME-4352) #11817

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Dec 13, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 21 additions & 1 deletion components/wifi/esp8266-driver/ESP8266/ESP8266.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -626,6 +626,7 @@ nsapi_error_t ESP8266::send(int id, const void *data, uint32_t amount)
}

_smutex.lock();
RETRY:
set_timeout(ESP8266_SEND_TIMEOUT);
_busy = false;
_error = false;
Expand All @@ -634,11 +635,25 @@ nsapi_error_t ESP8266::send(int id, const void *data, uint32_t amount)
goto END;
}

//We might receive "busy s/p..." and "OK" from modem, so we need to check that also
_ok_received = false;
_parser.oob("OK", callback(this, &ESP8266::_oob_ok_received));

if (!_parser.recv(">")) {
_parser.remove_oob("OK");
if (_busy) {
if (_ok_received) {
goto RETRY;
} else if (_parser.recv("OK")) {
goto RETRY;
}
}
tr_debug("send(): Didn't get \">\"");
ret = NSAPI_ERROR_WOULD_BLOCK;
goto END;
}
_ok_received = false;
_parser.remove_oob("OK");

if (_parser.write((char *)data, (int)amount) >= 0 && _parser.recv("SEND OK")) {
ret = NSAPI_ERROR_OK;
Expand Down Expand Up @@ -1071,7 +1086,6 @@ void ESP8266::_oob_busy()
"ESP8266::_oob_busy() AT timeout\n");
}
_busy = true;
_parser.abort();
}

void ESP8266::_oob_tcp_data_hdlr()
Expand Down Expand Up @@ -1205,6 +1219,12 @@ void ESP8266::_oob_connection_status()
_conn_stat_cb();
}

void ESP8266::_oob_ok_received()
{
tr_debug("_oob_ok_received called");
_ok_received = true;
}

int8_t ESP8266::default_wifi_mode()
{
int8_t mode;
Expand Down
2 changes: 2 additions & 0 deletions components/wifi/esp8266-driver/ESP8266/ESP8266.h
Original file line number Diff line number Diff line change
Expand Up @@ -469,6 +469,7 @@ class ESP8266 {
void _oob_tcp_data_hdlr();
void _oob_ready();
void _oob_scan_results();
void _oob_ok_received();

// OOB state variables
int _connect_error;
Expand All @@ -479,6 +480,7 @@ class ESP8266 {
bool _error;
bool _busy;
bool _reset_done;
bool _ok_received;

// Modem's address info
char _ip_buffer[16];
Expand Down
6 changes: 6 additions & 0 deletions platform/ATCmdParser.h
Original file line number Diff line number Diff line change
Expand Up @@ -311,6 +311,12 @@ class ATCmdParser : private NonCopyable<ATCmdParser> {
*/
void oob(const char *prefix, mbed::Callback<void()> func);

/**
* @brief remove_oob Removes oob callback handler
* @param prefix Prefix to identify oob to be removed.
*/
void remove_oob(const char *prefix);

/**
* Flushes the underlying stream
*/
Expand Down
19 changes: 19 additions & 0 deletions platform/source/ATCmdParser.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -362,6 +362,25 @@ void ATCmdParser::oob(const char *prefix, Callback<void()> cb)
_oobs = oob;
}

void ATCmdParser::remove_oob(const char *prefix)
{
struct oob *prev = NULL;
struct oob *oob = _oobs;
while (oob) {
if (memcmp(oob->prefix, prefix, strlen(prefix)) == 0) {
if (prev) {
prev->next = oob->next;
} else {
_oobs = oob->next;
}
delete oob;
return;
}
prev = oob;
oob = oob->next;
}
}

void ATCmdParser::abort()
{
_aborted = true;
Expand Down