I want to Know , if i can Get Public IP of my Router through ESP8266 ?
ESP8266 Connects --> Router --> ESP Gets to Know Public IP and Stores it.
Is there any Arduino Code Lines for this ?
Explore... Chat... Share...
void GetExternalIP()
{
WiFiClient client;
if (!client.connect("api.ipify.org", 80)) {
Serial.println("Failed to connect with 'api.ipify.org' !");
}
else {
int timeout = millis() + 5000;
client.print("GET /?format=json HTTP/1.1\r\nHost: api.ipify.org\r\n\r\n");
while (client.available() == 0) {
if (timeout - millis() < 0) {
Serial.println(">>> Client Timeout !");
client.stop();
return;
}
}
int size;
while ((size = client.available()) > 0) {
uint8_t* msg = (uint8_t*)malloc(size);
size = client.read(msg, size);
Serial.write(msg, size);
free(msg);
}
}
}
void GetExternalIP()
{
WiFiClient client;
if (!client.connect("api.ipify.org", 80)) {
Serial.println("Failed to connect with 'api.ipify.org' !");
}
else
{
int timeout = millis() + 5000;
client.print("GET /?format=json HTTP/1.1\r\nHost: api.ipify.org\r\n\r\n");
while (client.available() == 0) {
if (timeout - millis() < 0) {
Serial.println(">>> Client Timeout !");
client.stop();
return;
}
}
int size;
while ((size = client.available()) > 0) {
uint8_t* msg = (uint8_t*)malloc(size);
size = client.read(msg, size);
Serial.write(msg, size);
terminal.flush();
terminal.write(msg, size);
terminal.flush();
free(msg);
}
}
}
It takes about 20-25 seconds for home assistant c[…]
I tried to upgrade tof my sonoff basic R2 with the[…]
a problem Perhaps you want to define "Probl[…]
Rebooting your router will not give you a faster I[…]
There are no other notifications from esptool.py i[…]
Using the Arduino IDE, you'll learn how to set up […]
In this project, you will post to Twitter using an[…]
In this project, we will build a water level contr[…]
I guess I'm late, but I had the same problem and f[…]
Last night I received my first D1 Minis for a lear[…]
Although I am aware that this is an old post, I fe[…]