Fix automatic ip adress esp

This commit is contained in:
2024-06-04 14:40:06 +02:00
parent 7539892131
commit 8cd2b00eb0
5 changed files with 27 additions and 14 deletions

View File

@@ -33,8 +33,12 @@ const char* Connectivity::fetchIPAddress() {
int httpCode = http.GET();
if (httpCode > 0) {
if (httpCode == HTTP_CODE_OK) {
// If successful (code 200), read the response body and store the IP address
ipAddress = strdup(http.getString().c_str());
// If successful (code 200), read the response body and parse the IP address
String response = http.getString();
StaticJsonDocument<200> doc;
deserializeJson(doc, response);
const char* ip = doc["ip"]; // Extract the IP address
ipAddress = strdup(ip);
}
} else {
Serial.printf("GET request failed, error: %s\n", http.errorToString(httpCode).c_str());