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

Conversation

michalpasztamobica
Copy link
Contributor

@michalpasztamobica michalpasztamobica commented Feb 7, 2019

Description

ESP8266Interface::connect() checks ESP8266::connect() return values and returns if unrecoverable errors are returned.
Increased timeout for network-wifi greentea tests.
Fixes failing network-wifi-WIFI-CONNECT-SECURE-FAIL tests for ESP8266.

Pull request type

[x] Fix
[ ] Refactor
[ ] Target update
[ ] Functionality change
[ ] Docs update
[ ] Test update
[ ] Breaking change

Reviewers

@SeppoTakalo
@VeijoPesonen

@ciarmcom ciarmcom requested review from SeppoTakalo, VeijoPesonen and a team February 7, 2019 18:00
@ciarmcom
Copy link
Member

ciarmcom commented Feb 7, 2019

@michalpasztamobica, thank you for your changes.
@VeijoPesonen @SeppoTakalo @ARMmbed/mbed-os-test @ARMmbed/mbed-os-ipcore @ARMmbed/mbed-os-maintainers please review.

@@ -244,7 +244,10 @@ int ESP8266Interface::connect()
}

while (_if_blocking && (_conn_status_to_error() != NSAPI_ERROR_IS_CONNECTED)) {
_if_connected.wait();
if (_if_connected.wait_for(ESP8266_INTERFACE_CONNECT_TIMEOUT)) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I have made this way too simplistic(read - I made a mistake) and that's why there is need to introduce one more variable to see what ESP8266::connect returns, sorry for that. Timeout here wouldn't work because the condition might get raised spuriously. Instead of returning NSAPI_ERROR_CONNECTION_TIMEOUT we would want to return what ever ESP8266::connect spits out.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just to elaborate - there is not much of a reason to continue if ESP8266::connect() returns, e.g., NSAPI_ERROR_NO_SSID.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The process can continue on the background but call should return.

@@ -34,6 +34,10 @@

#define ESP8266_SOCKET_COUNT 5

#ifndef ESP8266_INTERFACE_CONNECT_TIMEOUT
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The whole block is not needed

@michalpasztamobica michalpasztamobica changed the title ESP8266: connect() timeout introduction ESP8266: connect() checks errors from ESP chip Feb 8, 2019
@michalpasztamobica
Copy link
Contributor Author

@VeijoPesonen , I modified the code to handle the errors recognized by ESP8266::connect() (AUTH_FAILURE, CONNECTION_TIMEOUT and NO_SSID). If any of these or OK are detected the ESP8266Interface::connect() will be signalled to return a proper return value.
network-wifi suite is passing with this solution.
Let me know if this is more or less what you meant? :)

I also updated the commit message and title of this PR, leaving the PR's Description as was, to maintain history.

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_CONNECTION_TIMEOUT || _connect_retval == NSAPI_ERROR_NO_SSID) {
Copy link
Contributor

@VeijoPesonen VeijoPesonen Feb 8, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we should continue trying with NSAPI_ERROR_CONNECTION_TIMEOUT. In other words with that return value we should end up in the else-statement

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You are right, although checking this led me to a sad conclusion, that ESP does not realize that "aaaaaaaa" network does not exist and it never returns with "3: cannot find the target AP" error code, as the documentation promises.
Instead after two minutes it returns a "2: wrong password", which we later translate to AUTH_FAILURE.
I even logged into ruka and loaded a cliapp to run "wlan0 scan" to make double sure "aaaaaaaa" does not exist. It doesn't.
To make up for the 2 minute wait I will also extend the wifi testsuite duration.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sounds like a good idea.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There is also influence from previous tests - when I run the whole suite the ESP will never return anything else than 1 in WIFI-CONNECT-SECURE-FAIL. I am investigating.

ESP8266Interface::connect() checks the exact return value from
the underlying ESP8266::connect() call.
Increased timeout for network-wifi greentea tests to 6 minutes.
@michalpasztamobica
Copy link
Contributor Author

I updated the code according to Veijo's remark (not to return if ESP advertises timeout). Unfortunately, the network-wifi-WIFI-CONNECT-SECURE-FAIL was not passing after this last change. I tried many things: the way we set up and tear down the test, the reset line assertion on disconnect, the order of tests in the suite, etc.
In the end I provided the json config with credentials for our local office WiFi and run the wifi suite locally. It is passing just fine (I did not have an unsecured WiFi, so I did not test that part).
I think there is some issue with the ruka wifi network. If the CI keeps failing with these changes I will raise a proper ticket. With my local, stable, uncrowded WiFi the tests are passing fine.
@VeijoPesonen , @SeppoTakalo , if you agree with the changes and the plan for future, please approve.

@michalpasztamobica
Copy link
Contributor Author

@cmonr , @0xc0170 , this is approved. Can we merge this in to see its influence on the nightly CI builds?

@cmonr
Copy link
Contributor

cmonr commented Feb 13, 2019

@michalpasztamobica Need to start CI first. Looking at the current CI queue, it looks like merging it tonight might be a hard sell.

@cmonr
Copy link
Contributor

cmonr commented Feb 13, 2019

CI started

@mbed-ci
Copy link

mbed-ci commented Feb 14, 2019

Test run: SUCCESS

Summary: 12 of 12 test jobs passed
Build number : 1
Build artifacts

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants