-
Notifications
You must be signed in to change notification settings - Fork 13.3k
Update ESP8266WiFiSTAClass::waitForConnectResult() for the same behavior with ESP32. #4985
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
base: master
Are you sure you want to change the base?
Conversation
…ior to ESP32 add counter i for trying WIFi-connection 100 times
split Arduino's String to Arduino's String Array
Ref: #4983 You seem to have committed something else along with this proposal. Please do another PR for this. To not break very precious backward compatibility,
You'd propose the same fix to esp-idf with 10 instead of 0. |
cores/esp8266/WString.cpp
Outdated
@@ -781,6 +781,57 @@ void String::trim(void) { | |||
buffer[len] = 0; | |||
} | |||
|
|||
/************************************************************/ |
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.
Please remove this String addition.
On a personal note, the implementation makes me want to tear my eyes out. Why didn't the author use a C++ reference instead of a double pointer?
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.
Sorry, I just tried something on String addition but not for this PR.
Already remove them.
cores/esp8266/WString.h
Outdated
@@ -237,7 +237,8 @@ class String { | |||
void toLowerCase(void); | |||
void toUpperCase(void); | |||
void trim(void); | |||
|
|||
|
|||
int td_split(String delimiter, String** str_array); // v2.3 split String to String Array by multi-delimiters |
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.
Please remove this change.
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.
Already removed this String addition change.
@@ -374,7 +374,8 @@ uint8_t ESP8266WiFiSTAClass::waitForConnectResult() { | |||
if((wifi_get_opmode() & 1) == 0) { | |||
return WL_DISCONNECTED; | |||
} | |||
while(status() == WL_DISCONNECTED) { | |||
int i = 0; | |||
while((!status() || status() >= WL_DISCONNECTED) && i++ < 100) { |
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.
This is a max of 10s time. Some connections could take longer, especially under poor signal conditions. Some users could not want to spend so much time trying to connect and want to give up sooner. I suggest taking an argument that defaults to this when not set.
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.
If default time trying to connect when not set is 15 secs. What do you think ?
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.
What would happen with a default non infinite value when user's network connectivity / the router is for any reason powered down or disconnected for a while (a longer while than this default value), or takes long to power on, or whatever ?
My point is that usually sketches patiently wait for connectivity. With this change, all sketches would need to be updated to loop on the connectivity loop.
I don't question this PR, only the historical default behavior / backward compatibility.
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.
Oops @d-a-v is correct: either we maintain backwards compatibility and merge now, or we keep this breaking change and wait until release 3.0.0 to merge. I prefer the former.
So:
- the function should take a timeout argument, in ms, which defaults to some value that disables the timeout (std::numeric_limits?)
- If the user wants a timeout, he can specify a value for the argument.
- In a future release we'll change the default to some value like 10 or 15s.
@ShinDaiIchi Could you please implement the changes and update the PR?
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.
Already update with WiFi connecting's wait-timeout with backwards compatibility.
@@ -374,7 +374,8 @@ uint8_t ESP8266WiFiSTAClass::waitForConnectResult() { | |||
if((wifi_get_opmode() & 1) == 0) { | |||
return WL_DISCONNECTED; | |||
} | |||
while(status() == WL_DISCONNECTED) { | |||
int i = 0; | |||
while((!status() || status() >= WL_DISCONNECTED) && i++ < 100) { |
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.
Oops @d-a-v is correct: either we maintain backwards compatibility and merge now, or we keep this breaking change and wait until release 3.0.0 to merge. I prefer the former.
So:
- the function should take a timeout argument, in ms, which defaults to some value that disables the timeout (std::numeric_limits?)
- If the user wants a timeout, he can specify a value for the argument.
- In a future release we'll change the default to some value like 10 or 15s.
@ShinDaiIchi Could you please implement the changes and update the PR?
…meout and compatable old version.
…meout and compatable old version.
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.
Minor changes requested. Will merge once fixed.
//1 and 3 have STA enabled | ||
if((wifi_get_opmode() & 1) == 0) { | ||
return WL_DISCONNECTED; | ||
} | ||
while(status() == WL_DISCONNECTED) { | ||
int i = 0; int try_times = wait_secs*10; | ||
while((!status() || status() >= WL_DISCONNECTED) && ((wait_secs!=0)? (i++ < try_times): true )) { |
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.
don't use inverted logic please:
... && ((wait_secs==0) ? true : (i++ < try_times) )
//1 and 3 have STA enabled | ||
if((wifi_get_opmode() & 1) == 0) { | ||
return WL_DISCONNECTED; | ||
} | ||
while(status() == WL_DISCONNECTED) { | ||
int i = 0; int try_times = wait_secs*10; |
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.
PLease declare/init try_times on its own line
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.
Update
@@ -374,7 +374,8 @@ uint8_t ESP8266WiFiSTAClass::waitForConnectResult() { | |||
if((wifi_get_opmode() & 1) == 0) { | |||
return WL_DISCONNECTED; | |||
} | |||
while(status() == WL_DISCONNECTED) { | |||
int i = 0; | |||
while((!status() || status() >= WL_DISCONNECTED) && i++ < 100) { |
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.
Already update with WiFi connecting's wait-timeout with backwards compatibility.
while(status() == WL_DISCONNECTED) { | ||
int i = 0; | ||
int try_times = wait_secs*10; | ||
while((!status() || status() >= WL_DISCONNECTED) && ((wait_secs==0)? true : (i++ < try_times))) { |
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.
This line is difficult to read.
!status()
tests whether the status is non-zero, but status is an enum and it’s unobvious which value is zero.- The part after && is really complicated.
How about:
for (int timeout = wait_secs * 10; wait_secs == 0 || timeout > 0; --timeout) {
auto st = status();
switch (st) {
case WL_CONNECTED:
case WL_NO_SSID_AVAIL:
case WL_CONNECT_FAILED:
return st;
default:
delay(100);
break;
}
}
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.
Agree with @yoursunny . However:
I have a PR with a class that encapsulates the polled timeout. I suggest waiting a bit until it's merged, then using it, instead of reinventing the wheel for the nth time.
the switch should define cases for all enum values, and leave the default case for values not in the enum (error).
@ShinDaiIchi the polledTimeout class has been available for a while now. Could you please resolve conflicts and update with that? |
Add counter i for trying WIFi-connection 100 times