Created
November 19, 2016 10:41
-
-
Save NaotoKumagai/32aa524a1b4ceba4bd4e5c5ef42a25a3 to your computer and use it in GitHub Desktop.
ESP-WROOM-02でグローバルIPを取得
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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