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
3 changes: 1 addition & 2 deletions cores/esp8266/WString.h
Original file line number Diff line number Diff line change
Expand Up @@ -237,8 +237,7 @@ class String {
void toLowerCase(void);
void toUpperCase(void);
void trim(void);

// parsing/conversion

long toInt(void) const;
float toFloat(void) const;

Expand Down
5 changes: 3 additions & 2 deletions libraries/ESP8266WiFi/src/ESP8266WiFiSTA.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -369,12 +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;
}
while(status() == WL_DISCONNECTED) {
int i = 0; int try_times = wait_secs*10;
Copy link
Collaborator

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

while((!status() || status() >= WL_DISCONNECTED) && ((wait_secs!=0)? (i++ < try_times): true )) {
Copy link
Collaborator

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) )

delay(100);
}
return status();
Expand Down
2 changes: 1 addition & 1 deletion libraries/ESP8266WiFi/src/ESP8266WiFiSTA.h
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down