-
Notifications
You must be signed in to change notification settings - Fork 3k
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
ESP8266: connect() checks errors from ESP chip #9639
Conversation
@michalpasztamobica, thank you for your changes. |
@@ -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)) { |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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 |
There was a problem hiding this comment.
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
a0d0131
to
66e8a67
Compare
@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. 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) { |
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
66e8a67
to
6a184da
Compare
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. |
@michalpasztamobica Need to start CI first. Looking at the current CI queue, it looks like merging it tonight might be a hard sell. |
CI started |
Test run: SUCCESSSummary: 12 of 12 test jobs passed |
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
Reviewers
@SeppoTakalo
@VeijoPesonen