Last active
January 30, 2022 16:53
-
-
Save webprice/567e6fc98e49f6fe470723780aa4addf to your computer and use it in GitHub Desktop.
ddnames arduino example program to send the updated ip address of the device
This file contains 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
#include <ESP8266HTTPClient.h> | |
#include <ESP8266WiFi.h> | |
const char* ssid = "YourSSID"; //your wifi SSID | |
const char* password = "YourWiFiPassword"; | |
byte tries = 10; | |
// Trying to connect to wireless AP | |
void setup() { | |
Serial.begin(115200); | |
WiFi.begin(ssid, password); | |
while (--tries && WiFi.status() != WL_CONNECTED) { | |
delay(500); | |
Serial.print("."); | |
} | |
if (WiFi.status() != WL_CONNECTED) | |
{ | |
Serial.println("Can't connect to WiFi.."); | |
} | |
else | |
{ | |
// Connection established | |
// Show local IP address | |
Serial.println(""); | |
Serial.println("WiFi connected"); | |
Serial.println("IP address: "); | |
Serial.println(WiFi.localIP()); | |
} | |
} | |
void loop() { | |
if (WiFi.status() == WL_CONNECTED) { | |
WiFiClient client; | |
HTTPClient http; | |
http.begin(client,"https://ddnames.com:80/ip.php"); | |
int httpCode = http.GET(); | |
if (httpCode > 0) { | |
String payload = http.getString(); | |
Serial.println(payload); | |
http.end(); | |
delay(3000); | |
HTTPClient http2; | |
http2.begin(client,"https://ddnames.com:8000/update"); | |
http2.addHeader("Content-Type", "application/json"); | |
int httpCode2 = http2.POST("{\"email\":\"yourEmailHere\", \"apikey\":\"yourApikey\", \"domain\": \"yourdomain.tld\", \"ipaddress\": \""+ payload +"\"}"); | |
String payload2 = http2.getString(); | |
Serial.println(httpCode2); | |
Serial.println(payload2); | |
Serial.println("{\"email\":\"your@mail.com\", \"apikey\":\"yourApikey\", \"domain\": \"yourdomain.tld\", \"ipaddress\": \""+ payload +"\"}"); | |
http2.end(); | |
}} | |
delay(5000); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment