#include <WiFi.h>
#include <HTTPClient.h>
const char* ssid = "Wokwi-GUEST";
const char* password = "";
void setup() {
Serial.begin(115200);
WiFi.begin(ssid, password);
while (WiFi.status() != WL_CONNECTED) {
delay(1000);
Serial.println("Connecting to WiFi..");
}
Serial.println("Connected to the WiFi network");
}
void loop() {
Serial.print("Public IP: ");
Serial.println(GetPublicIP());
delay(30000);
}
String GetPublicIP(){
if ((WiFi.status() == WL_CONNECTED)) { //Check the current connection status
HTTPClient http;
String status;
http.begin("https://api.ipify.org"); //Specify the URL
status = http.GET() > 0 ? http.getString() : "N\A";
http.end(); //Free the resources
return status;
}
}