Skip to content

Instantly share code, notes, and snippets.

@gresan-gits
Created February 16, 2020 09:50
Show Gist options
  • Save gresan-gits/f35e798fb03efa2f1bed47dcfe950a52 to your computer and use it in GitHub Desktop.
Save gresan-gits/f35e798fb03efa2f1bed47dcfe950a52 to your computer and use it in GitHub Desktop.
ESP32 GET IP
#include <WiFi.h>
#include <HTTPClient.h>
const char* ssid = "Xuong May Tran Bam";
const char* password = "123456789";
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() {
if ((WiFi.status() == WL_CONNECTED)) { //Check the current connection status
HTTPClient http;
http.begin("https://api.ipify.org/?format=json"); //Specify the URL
int httpCode = http.GET(); //Make the request
if (httpCode > 0) { //Check for the returning code
String payload = http.getString();
Serial.println(httpCode);
Serial.println(payload);
}
else {
Serial.println("Error on HTTP request");
}
http.end(); //Free the resources
}
delay(30000);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment