Skip to content

Update WiFiMulti.cpp #1220

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

Merged
merged 3 commits into from
Apr 6, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 5 additions & 4 deletions libraries/WiFi/src/WiFiMulti.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ bool WiFiMulti::addAP(const char* ssid, const char *passphrase)
return APlistAdd(ssid, passphrase);
}

uint8_t WiFiMulti::run(void)
uint8_t WiFiMulti::run(uint32_t connectTimeout)
{

int8_t scanResult;
Expand Down Expand Up @@ -117,9 +117,10 @@ uint8_t WiFiMulti::run(void)

WiFi.begin(bestNetwork.ssid, bestNetwork.passphrase, bestChannel, bestBSSID);
status = WiFi.status();

// wait for connection or fail
while(status != WL_CONNECTED && status != WL_NO_SSID_AVAIL && status != WL_CONNECT_FAILED) {

auto startTime = millis();
// wait for connection, fail, or timeout
while(status != WL_CONNECTED && status != WL_NO_SSID_AVAIL && status != WL_CONNECT_FAILED && (millis() - startTime) <= connectTimeout) {
delay(10);
status = WiFi.status();
}
Expand Down
2 changes: 1 addition & 1 deletion libraries/WiFi/src/WiFiMulti.h
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ class WiFiMulti

bool addAP(const char* ssid, const char *passphrase = NULL);

uint8_t run(void);
uint8_t run(uint32_t connectTimeout=5000);

private:
std::vector<WifiAPlist_t> APlist;
Expand Down