[WIP] Add delay in softAPConfig() after call to enableAP() to assure AP startup works #6630
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
On latest git today.
I have been intermittently encountering an issue where the AP won't start given certain unknown conditions. In particular, I have a WiFi control sequence where the logic is controlled by configuration parameters. In my case, the sequence is being called from a callback that executes in the SYS context (callback of an Async object).
If the AP is to be enabled, such as when switching from STA to AP mode, then the very first call in that sequence is WiFi.softAPConfig():
And that fails.
When the failure happens, it's repeatable. Then, I will change some unrelated code and rebuild, and the problem may go away, or continue to be present and still consistent. This leads me to believe it is some race condition.
Debugging (DebugLevel WiFi) the calls inside softAPConfig() shows logs that indicate that the call to enableAP() at the very start of the method succeeds, but then all subsequent SDK API calls fail. On a whim, I moved my control sequence code to the CONT context by wrapping it in a lambda and scheduling it. This continued to show the failure. Then, I added a delay(10) right after the call to enableAP(), as shown in this PR, and suddenly the issue disappeared and can't be reproduced.
My suspicion is that the mode switch at low level (in the SDK or in hardware) isn't synchronous. Either there is a hw sequence that should be waited upon, or there is a sequence of SDK tasks that get queued that need to be executed for the sequence to complete.
This PR is meant for discussion. Off the top of my head:
Notes:
-a delayMicroseconds() could check for a hw sequence. If it works, it's a hw sequence. If not, it's likely a sequence of tasks that were queued.
-If a mode switch is a sequence of tasks, other wifi things could be as well. I'm thinking of the case where the status() doesn't always reflect reality.