From 0be5be64fa45e6d92b3dec2a79c7084fb5807fba Mon Sep 17 00:00:00 2001 From: ShinDaiIchi Date: Mon, 30 Jul 2018 13:49:07 +0700 Subject: [PATCH 1/8] Update ESP8266WiFiSTAClass::waitForConnectResult() for the same behavior to ESP32 add counter i for trying WIFi-connection 100 times --- libraries/ESP8266WiFi/src/ESP8266WiFiSTA.cpp | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/libraries/ESP8266WiFi/src/ESP8266WiFiSTA.cpp b/libraries/ESP8266WiFi/src/ESP8266WiFiSTA.cpp index 730b52886a..91027abab7 100644 --- a/libraries/ESP8266WiFi/src/ESP8266WiFiSTA.cpp +++ b/libraries/ESP8266WiFi/src/ESP8266WiFiSTA.cpp @@ -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) { delay(100); } return status(); From d2c4cc795b3d5ec899d21c35b644fab9acd56b51 Mon Sep 17 00:00:00 2001 From: ShinDaiIchi Date: Mon, 30 Jul 2018 13:56:56 +0700 Subject: [PATCH 2/8] Add td_split() for spliting String to String Array by multi-delimiters split Arduino's String to Arduino's String Array --- cores/esp8266/WString.h | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/cores/esp8266/WString.h b/cores/esp8266/WString.h index fbf3c59b2f..7300a9d79b 100644 --- a/cores/esp8266/WString.h +++ b/cores/esp8266/WString.h @@ -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 // parsing/conversion long toInt(void) const; float toFloat(void) const; From b39fc188a198a3e872999094760d4738b208936e Mon Sep 17 00:00:00 2001 From: ShinDaiIchi Date: Mon, 30 Jul 2018 14:01:34 +0700 Subject: [PATCH 3/8] Add td_split() for spliting String to String Array --- cores/esp8266/WString.cpp | 51 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 51 insertions(+) diff --git a/cores/esp8266/WString.cpp b/cores/esp8266/WString.cpp index edc8ab8b54..8443552f36 100644 --- a/cores/esp8266/WString.cpp +++ b/cores/esp8266/WString.cpp @@ -781,6 +781,57 @@ void String::trim(void) { buffer[len] = 0; } +/************************************************************/ +/* 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 */ // /*********************************************/ From 579a9a63eafee0a70be75aa55010d25e7fc5a30f Mon Sep 17 00:00:00 2001 From: ShinDaiIchi Date: Tue, 31 Jul 2018 05:16:13 +0700 Subject: [PATCH 4/8] Update WString.h --- cores/esp8266/WString.h | 2 -- 1 file changed, 2 deletions(-) diff --git a/cores/esp8266/WString.h b/cores/esp8266/WString.h index 7300a9d79b..81d26c3210 100644 --- a/cores/esp8266/WString.h +++ b/cores/esp8266/WString.h @@ -238,8 +238,6 @@ class String { void toUpperCase(void); void trim(void); - int td_split(String delimiter, String** str_array); // v2.3 split String to String Array by multi-delimiters - // parsing/conversion long toInt(void) const; float toFloat(void) const; From 5c4ff27f3c746563656b2114f17329d67e480e81 Mon Sep 17 00:00:00 2001 From: ShinDaiIchi Date: Tue, 31 Jul 2018 05:17:07 +0700 Subject: [PATCH 5/8] Update WString.cpp --- cores/esp8266/WString.cpp | 51 --------------------------------------- 1 file changed, 51 deletions(-) diff --git a/cores/esp8266/WString.cpp b/cores/esp8266/WString.cpp index 8443552f36..edc8ab8b54 100644 --- a/cores/esp8266/WString.cpp +++ b/cores/esp8266/WString.cpp @@ -781,57 +781,6 @@ void String::trim(void) { buffer[len] = 0; } -/************************************************************/ -/* 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 */ // /*********************************************/ From 8544d30b14c218aa0c8a79ae4bd46ec2a305e7f0 Mon Sep 17 00:00:00 2001 From: ShinDaiIchi Date: Thu, 2 Aug 2018 19:21:28 +0700 Subject: [PATCH 6/8] Update ESP8266WiFiSTAClass::waitForConnectResult with connection's timeout and compatable old version. --- libraries/ESP8266WiFi/src/ESP8266WiFiSTA.cpp | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/libraries/ESP8266WiFi/src/ESP8266WiFiSTA.cpp b/libraries/ESP8266WiFi/src/ESP8266WiFiSTA.cpp index 91027abab7..c9bca77814 100644 --- a/libraries/ESP8266WiFi/src/ESP8266WiFiSTA.cpp +++ b/libraries/ESP8266WiFi/src/ESP8266WiFiSTA.cpp @@ -369,13 +369,13 @@ bool ESP8266WiFiSTAClass::getAutoReconnect() { * returns the status reached or disconnect if STA is off * @return wl_status_t */ -uint8_t ESP8266WiFiSTAClass::waitForConnectResult() { +uint8_t ESP8266WiFiSTAClass::waitForConnectResult(uint32_t wait_secs) { //1 and 3 have STA enabled if((wifi_get_opmode() & 1) == 0) { return WL_DISCONNECTED; } - int i = 0; - while((!status() || status() >= WL_DISCONNECTED) && i++ < 100) { + int i = 0; int try_times = wait_secs*10; + while((!status() || status() >= WL_DISCONNECTED) && ((wait_secs!=0)? (i++ < try_times): true )) { delay(100); } return status(); From 956510e61b2e2fc0d25914653831df83fc01017e Mon Sep 17 00:00:00 2001 From: ShinDaiIchi Date: Thu, 2 Aug 2018 19:21:40 +0700 Subject: [PATCH 7/8] Update ESP8266WiFiSTAClass::waitForConnectResult with connection's timeout and compatable old version. --- libraries/ESP8266WiFi/src/ESP8266WiFiSTA.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/libraries/ESP8266WiFi/src/ESP8266WiFiSTA.h b/libraries/ESP8266WiFi/src/ESP8266WiFiSTA.h index f94ba0a4d3..4a49108d4f 100644 --- a/libraries/ESP8266WiFi/src/ESP8266WiFiSTA.h +++ b/libraries/ESP8266WiFi/src/ESP8266WiFiSTA.h @@ -56,7 +56,7 @@ class ESP8266WiFiSTAClass { bool setAutoReconnect(bool autoReconnect); bool getAutoReconnect(); - uint8_t waitForConnectResult(); + uint8_t waitForConnectResult(uint32_t wait_secs=0); // STA network info IPAddress localIP(); From c5fec545e3755f4a7a5a6f5b219eafa46380c5a3 Mon Sep 17 00:00:00 2001 From: ShinDaiIchi Date: Fri, 10 Aug 2018 22:24:27 +0700 Subject: [PATCH 8/8] Update (wait_secs==0)? etc... --- libraries/ESP8266WiFi/src/ESP8266WiFiSTA.cpp | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/libraries/ESP8266WiFi/src/ESP8266WiFiSTA.cpp b/libraries/ESP8266WiFi/src/ESP8266WiFiSTA.cpp index c9bca77814..81560a4376 100644 --- a/libraries/ESP8266WiFi/src/ESP8266WiFiSTA.cpp +++ b/libraries/ESP8266WiFi/src/ESP8266WiFiSTA.cpp @@ -374,8 +374,9 @@ uint8_t ESP8266WiFiSTAClass::waitForConnectResult(uint32_t wait_secs) { if((wifi_get_opmode() & 1) == 0) { return WL_DISCONNECTED; } - int i = 0; int try_times = wait_secs*10; - while((!status() || status() >= WL_DISCONNECTED) && ((wait_secs!=0)? (i++ < try_times): true )) { + int i = 0; + int try_times = wait_secs*10; + while((!status() || status() >= WL_DISCONNECTED) && ((wait_secs==0)? true : (i++ < try_times))) { delay(100); } return status();