Skip to content

Instantly share code, notes, and snippets.

@NaotoKumagai
Created November 19, 2016 10:41
Show Gist options
  • Save NaotoKumagai/32aa524a1b4ceba4bd4e5c5ef42a25a3 to your computer and use it in GitHub Desktop.
Save NaotoKumagai/32aa524a1b4ceba4bd4e5c5ef42a25a3 to your computer and use it in GitHub Desktop.
ESP-WROOM-02でグローバルIPを取得
String findPublicIP() {
WiFiClient client;
if (client.connect("api.ipify.org", 80)) {
//Serial.println("connected");
client.println("GET /?format=txt HTTP/1.0");
client.println("Host: api.ipify.org");
client.println();
} else {
Serial.println("connection failed");
}
delay(50);
int a = 1;
while (client.connected()) {
a = a + 1;
String line = client.readStringUntil('\n');
if (a == 10) {
Serial.println(line);
return line;
}
}
return "";
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment