8000 Update ESP8266WiFiSTAClass::waitForConnectResult() for the same behavior with ESP32. by ShinDaiIchi · Pull Request #4985 · esp8266/Arduino · GitHub
[go: up one dir, main page]

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
Prev Previous commit
Next Next commit
Update (wait_secs==0)? etc...
  • Loading branch information
ShinDaiIchi authored Aug 10, 2018
commit c5fec545e3755f4a7a5a6f5b219eafa46380c5a3
5 changes: 3 additions & 2 deletions libraries/ESP8266WiFi/src/ESP8266WiFiSTA.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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))) {
Copy link
Contributor

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;
  }
}

  

Copy link
Collaborator

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

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