Skip to content

ESP8266: connect() checks errors from ESP chip #9639

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
Feb 14, 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
2 changes: 1 addition & 1 deletion TESTS/network/wifi/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ using namespace utest::v1;

utest::v1::status_t test_setup(const size_t number_of_cases)
{
GREENTEA_SETUP(240, "default_auto");
GREENTEA_SETUP(360, "default_auto");
return verbose_test_setup_handler(number_of_cases);
}

Expand Down
18 changes: 11 additions & 7 deletions components/wifi/esp8266-driver/ESP8266Interface.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ ESP8266Interface::ESP8266Interface()
_if_blocking(true),
_if_connected(_cmutex),
_initialized(false),
_connect_retval(NSAPI_ERROR_OK),
_conn_stat(NSAPI_STATUS_DISCONNECTED),
_conn_stat_cb(NULL),
_global_event_queue(NULL),
Expand Down Expand Up @@ -187,18 +188,19 @@ void ESP8266Interface::_connect_async()
_cmutex.unlock();
return;
}

if (_esp.connect(ap_ssid, ap_pass) != NSAPI_ERROR_OK) {
_connect_retval = _esp.connect(ap_ssid, ap_pass);
if (_connect_retval == NSAPI_ERROR_OK || _connect_retval == NSAPI_ERROR_AUTH_FAILURE
|| _connect_retval == NSAPI_ERROR_NO_SSID) {
_connect_event_id = 0;
_if_connected.notify_all();
} else {
// Postpone to give other stuff time to run
_connect_event_id = _global_event_queue->call_in(ESP8266_CONNECT_TIMEOUT, callback(this, &ESP8266Interface::_connect_async));

if (!_connect_event_id) {
MBED_ERROR(MBED_MAKE_ERROR(MBED_MODULE_DRIVER, MBED_ERROR_CODE_ENOMEM), \
"_connect_async(): unable to add event to queue");
}
} else {
_connect_event_id = 0;
_if_connected.notify_all();
}
_cmutex.unlock();
}
Expand Down Expand Up @@ -235,6 +237,7 @@ int ESP8266Interface::connect()

_cmutex.lock();

_connect_retval = NSAPI_ERROR_NO_CONNECTION;
MBED_ASSERT(!_connect_event_id);
_connect_event_id = _global_event_queue->call(callback(this, &ESP8266Interface::_connect_async));

Expand All @@ -243,13 +246,14 @@ int ESP8266Interface::connect()
"connect(): unable to add event to queue");
}

while (_if_blocking && (_conn_status_to_error() != NSAPI_ERROR_IS_CONNECTED)) {
while (_if_blocking && (_conn_status_to_error() != NSAPI_ERROR_IS_CONNECTED)
&& (_connect_retval == NSAPI_ERROR_NO_CONNECTION)) {
_if_connected.wait();
}

_cmutex.unlock();

return NSAPI_ERROR_OK;
return _connect_retval;
}

int ESP8266Interface::set_credentials(const char *ssid, const char *pass, nsapi_security_t security)
Expand Down
1 change: 1 addition & 0 deletions components/wifi/esp8266-driver/ESP8266Interface.h
Original file line number Diff line number Diff line change
Expand Up @@ -368,6 +368,7 @@ class ESP8266Interface : public NetworkStack, public WiFiInterface {
bool _get_firmware_ok();
nsapi_error_t _init(void);
void _hw_reset();
nsapi_error_t _connect_retval;

//sigio
struct {
Expand Down