-
-
Notifications
You must be signed in to change notification settings - Fork 104
WifiS3 - Non blocking Wifi connect #461
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
Changes from 1 commit
99df703
7350bbb
a260388
2d6b21e
61b798f
b233fe0
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
- Loading branch information
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||
|---|---|---|---|---|---|---|---|---|
|
|
@@ -5,7 +5,7 @@ | |||||||
| using namespace std; | ||||||||
|
|
||||||||
| /* -------------------------------------------------------------------------- */ | ||||||||
| CWifi::CWifi() : _timeout(10000){ | ||||||||
| CWifi::CWifi() : _timeout(10000), _start_connection_time(0){ | ||||||||
| } | ||||||||
| /* -------------------------------------------------------------------------- */ | ||||||||
|
|
||||||||
|
|
@@ -66,15 +66,21 @@ int CWifi::begin(const char* ssid, const char *passphrase) { | |||||||
|
|
||||||||
| int CWifi::isConnected() | ||||||||
| { | ||||||||
| if (status() == WL_CONNECTED) | ||||||||
| return WL_CONNECTED; | ||||||||
|
|
||||||||
| if (millis() - _start_connection_time < _timeout) | ||||||||
| { | ||||||||
| return WL_CONNECTING; | ||||||||
| } | ||||||||
|
|
||||||||
| return WL_CONNECT_FAILED; | ||||||||
| uint8_t current_status = status(); | ||||||||
|
|
||||||||
| if (current_status == WL_CONNECTED) { | ||||||||
| return WL_CONNECTED; | ||||||||
| } | ||||||||
|
|
||||||||
| if (current_status == WL_CONNECT_FAILED) { | ||||||||
| return WL_CONNECT_FAILED; | ||||||||
| } | ||||||||
|
|
||||||||
| if (millis() - _start_connection_time < _timeout) { | ||||||||
|
||||||||
| if (millis() - _start_connection_time < _timeout) { | |
| // Only check timeout if a connection attempt has started | |
| if (_start_connection_time != 0 && (millis() - _start_connection_time < _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.
When the server connection fails, the status is not reset. This means the code will stay in the
WL_CONNECTEDblock and keep trying to connect to the server on every loop iteration. While theif (clientConnected)block won't execute, the loop will still continuously attempt to connect without the proper state management. Consider adding anelseclause that handles the connection failure and potentially resets the status or adds a delay.