Skip to content

Commit

Permalink
added non blocking delayless localIP function
Browse files Browse the repository at this point in the history
  • Loading branch information
MYusufY authored Nov 30, 2024
1 parent 03b4a91 commit cf77427
Showing 1 changed file with 23 additions and 0 deletions.
23 changes: 23 additions & 0 deletions libraries/WiFiS3/src/WiFi.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -356,6 +356,29 @@ IPAddress CWifi::localIP() {
return local_IP;
}

IPAddress CWifi::localIPNonBlocking(unsigned long timeoutMs) {
modem.begin();
string res = "";
unsigned long start = millis();
IPAddress local_IP(0, 0, 0, 0);

while (local_IP == IPAddress(0, 0, 0, 0) && millis() - start < timeoutMs) {
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)) {
local_IP.fromString(res.c_str());
}
} else if (atoi(res.c_str()) == 2) {
if (modem.write(string(PROMPT(_IPSOFTAP)), res, CMD(_IPSOFTAP))) {
local_IP.fromString(res.c_str());
}
}
}
}
return local_IP;
}


/* -------------------------------------------------------------------------- */
IPAddress CWifi::subnetMask() {
/* -------------------------------------------------------------------------- */
Expand Down

0 comments on commit cf77427

Please sign in to comment.