Refactoring

This commit is contained in:
2024-06-03 16:17:27 +02:00
parent 7264811444
commit ffb90c001d
4 changed files with 10 additions and 9 deletions

View File

@@ -24,6 +24,7 @@ const char* getServerURL = "http://145.92.8.132:443/get-ip";
String ipAddress = ""; // string that will hold the server's IP address
const char* Connectivity::fetchIPAddress() {
char* ipAddress = NULL; // Declare ipAddress as a char*
if (WiFi.status() == WL_CONNECTED) {
HTTPClient http;
WiFiClient client;
@@ -33,7 +34,7 @@ const char* Connectivity::fetchIPAddress() {
if (httpCode > 0) {
if (httpCode == HTTP_CODE_OK) {
// If successful (code 200), read the response body and store the IP address
ipAddress = http.getString();
ipAddress = strdup(http.getString().c_str());
}
} else {
Serial.printf("GET request failed, error: %s\n", http.errorToString(httpCode).c_str());