Skip to content

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

Open
wants to merge 11 commits into
base: master
Choose a base branch
from
Open
51 changes: 51 additions & 0 deletions cores/esp8266/WString.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -781,6 +781,57 @@ void String::trim(void) {
buffer[len] = 0;
}

/************************************************************/
Copy link
Collaborator

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?

Copy link
Author

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.

/* TridentTD's split : split by delimiters to String Array */
/************************************************************/
// Version 2.3
/* example
* String data = "Hello Test; 18:00:48; 16/10/2018";
* String *data_split = NULL;
* int count = data.td_split( " ;:/", &data_split ); // split data to data_split by space or semicolon or colon or slash
* if( count > 1 )
* for(int i =0; i< count ; ++i)
* Serial.println( data_split[i] );
*/

int String::td_split(String delimiter, String** str_array) {
if(*str_array != NULL) {
delete[] *str_array;
*str_array = NULL;
}

if(!buffer || len == 0) {
*str_array = new String[1];
(*str_array)[0] = "";
return 0;
}

String input = String(buffer);
int token_size = 0;

char *pChar = strtok( (char*)input.c_str(), (char*)delimiter.c_str());
while ( pChar != NULL ) {
pChar = strtok( NULL, (char*)delimiter.c_str());
++token_size;
}

if(token_size == 0) {
*str_array = new String[1]; (*str_array)[0] = input;
return 1;
}

*str_array = new String[token_size];
input = String(buffer);
token_size = 0;

pChar = strtok( (char*) input.c_str(), (char*)delimiter.c_str());
while ( pChar != NULL ) {
(*str_array)[token_size] = String(pChar);
pChar = strtok( NULL, (char*)delimiter.c_str());
++token_size;
}
return token_size;
}
// /*********************************************/
// /* Parsing / Conversion */
// /*********************************************/
Expand Down
3 changes: 2 additions & 1 deletion cores/esp8266/WString.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please remove this change.

Copy link
Author

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.

// parsing/conversion
long toInt(void) const;
float toFloat(void) const;
Expand Down
3 changes: 2 additions & 1 deletion libraries/ESP8266WiFi/src/ESP8266WiFiSTA.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Copy link
Collaborator

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.

Copy link
Author

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 ?

Copy link
Collaborator

@d-a-v d-a-v Jul 30, 2018

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.

Copy link
Collaborator

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:

  1. the function should take a timeout argument, in ms, which defaults to some value that disables the timeout (std::numeric_limits?)
  2. If the user wants a timeout, he can specify a value for the argument.
  3. 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?

Copy link
Author

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.

delay(100);
}
return status();
Expand Down