From cf77427b9d936fd5bbcabc13b16452cf28c56d06 Mon Sep 17 00:00:00 2001 From: Yusuf YILDIRIM <122603576+MYusufY@users.noreply.github.com> Date: Sat, 30 Nov 2024 21:08:13 +0300 Subject: [PATCH] added non blocking delayless localIP function --- libraries/WiFiS3/src/WiFi.cpp | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/libraries/WiFiS3/src/WiFi.cpp b/libraries/WiFiS3/src/WiFi.cpp index 7e73b94f..0a9992ce 100644 --- a/libraries/WiFiS3/src/WiFi.cpp +++ b/libraries/WiFiS3/src/WiFi.cpp @@ -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() { /* -------------------------------------------------------------------------- */