Skip to content

WiFiS3: Add timeout for localIP #433

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

Closed
wants to merge 2 commits into from
Closed
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
6 changes: 2 additions & 4 deletions libraries/WiFiS3/src/WiFi.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -329,11 +329,10 @@ IPAddress CWifi::localIP() {
/* -------------------------------------------------------------------------- */
modem.begin();
string res = "";
int attempts = 0;
IPAddress local_IP(0,0,0,0);

unsigned long start_time = millis();
do {
delay(100);
if(modem.write(string(PROMPT(_MODE)),res, "%s" , CMD_READ(_MODE))) {
if(atoi(res.c_str()) == 1) {
if(modem.write(string(PROMPT(_IPSTA)),res, "%s%d\r\n" , CMD_WRITE(_IPSTA), IP_ADDR)) {
Expand All @@ -349,9 +348,8 @@ IPAddress CWifi::localIP() {
}
}
}
attempts++;
}
while(local_IP == IPAddress(0,0,0,0) && attempts < 50);
while((local_IP == IPAddress(0,0,0,0)) && (millis() - start_time < _timeout));

return local_IP;
}
Expand Down
Loading