Skip to content

Fix ESP8266 driver behavior on connection failures #10377

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 2 commits into from
Apr 18, 2019

Conversation

michalpasztamobica
Copy link
Contributor

Description

In case the application calls disconnect() the driver will only perform actual disconnection procedure (including a status update and event signalling) if the ESP was really disconnected. This was added in this commit, but in fact user might call disconnect() for example after a failed connection attempt. In this case we should stop trying to connect, so that a retry is possible. This is also how EMAC drivers work.

Furthermore, we did not make use of ESP8266 timeout message, because in fact it kept on trying to connect. Therefore we need to use our own timeout to return a proper error value if the connection really takes too long.

Pull request type

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

Reviewers

@VeijoPesonen
@SeppoTakalo

@ciarmcom ciarmcom requested review from SeppoTakalo, VeijoPesonen and a team April 11, 2019 15:00
@ciarmcom
Copy link
Member

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

@michalpasztamobica michalpasztamobica force-pushed the esp8266_connect_failures branch 3 times, most recently from 23267c8 to 0221ef4 Compare April 12, 2019 10:59
@michalpasztamobica
Copy link
Contributor Author

@kjbracey-arm , @SeppoTakalo , would you please provide any review remarks?

@VeijoPesonen
Copy link
Contributor

Furthermore, we did not make use of ESP8266 timeout message, because in fact it kept on trying to connect. Therefore we need to use our own timeout to return a proper error value if the connection really takes too long.

I had a talk with Kevin and my understanding is that giving up after 30 seconds in blocking mode should be fine. The rest of this comment you should read as my opinion.

Assumption here is that each connection attempt takes at maximum ~15 seconds(ESP8266_CONNECT_TIMEOUT). There is a 15 second grace period between the attempts with the current implementation. In other words please increase ESP8266_INTERFACE_CONNECT_TIMEOUT_MS to 30s+some seconds so that connect procedure has time to run two times if necessary.

That timelimit tells how long the driver has time to initiate a new connect-call, not when it should be done. It might still take 15 seconds(ESP8266_CONNECT_TIMEOUT) before the procedure succeeds or fails. So altogether it might take ~45 seconds that we know has the connection been established or did it fail.

I guess the grace period could be tuned down a bit from that 15 seconds so that the documentation can say we give up after 45 seconds. Return value should be something which makes possible to break out from the loop in blocking-mode.

@michalpasztamobica michalpasztamobica force-pushed the esp8266_connect_failures branch from 0221ef4 to d4adad6 Compare April 15, 2019 11:13
@michalpasztamobica
Copy link
Contributor Author

@VeijoPesonen , thank you for this valuable comment. I fully agree with your opinion, I tried to embrace it in the code with the following line:

#define ESP8266_INTERFACE_CONNECT_TIMEOUT_MS (2 * ESP8266_CONNECT_TIMEOUT + 15000)

I hope this would make it cristal clear for anyone reading the code in the future what this timeout depends on and what to consider when adjusting it.

@michalpasztamobica michalpasztamobica force-pushed the esp8266_connect_failures branch from d4adad6 to 453e485 Compare April 15, 2019 14:48
@michalpasztamobica michalpasztamobica force-pushed the esp8266_connect_failures branch 2 times, most recently from 0386089 to 7472b19 Compare April 16, 2019 07:01
The ESP chip returns timeout, but keeps trying to connect, so we want to
keep track of time ourselves, instead of relying on the chip's timeout.
This fixes failing WIFI-CONNECT-SECURE-FAIL test.
@michalpasztamobica michalpasztamobica force-pushed the esp8266_connect_failures branch from 7472b19 to 3e70df7 Compare April 16, 2019 11:24
@mbed-ci
Copy link

mbed-ci commented Apr 17, 2019

Test run: SUCCESS

Summary: 11 of 11 test jobs passed
Build number : 2
Build artifacts

@0xc0170 0xc0170 merged commit 69b9f3f into ARMmbed:master Apr 18, 2019
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.

7 participants