This repository has been archived by the owner on Jan 29, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 2
/
DuckDNS_Client.ino
141 lines (104 loc) · 3.71 KB
/
DuckDNS_Client.ino
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
/****************************************************************************************************************************
DuckDNS_Client.ino
For all Generic boards such as ESP8266, ESP32, SAM DUE, SAMD21/SAMD51, nRF52, STM32F/L/H/G/WB/MP1, AVR, megaAVR, Teensy
with WiFiNINA, ESP8266/ESP32 WiFi, ESP8266-AT, W5x00, ENC28J60, built-in Ethernet LAN8742A, WT32_ETH01
DDNS_Generic is a library to update DDNS IP address for DDNS services such as
duckdns, noip, dyndns, dynu, enom, all-inkl, selfhost.de, dyndns.it, strato, freemyip, afraid.org, ovh.com
Based on and modified from
1) EasyDDNS (https://github.com/ayushsharma82/EasyDDNS)
2) ArduinoHttpClient (https://github.com/arduino-libraries/ArduinoHttpClient)
Built by Khoi Hoang https://github.com/khoih-prog/DDNS_Generic
Licensed under MIT license
*****************************************************************************************************************************/
#include "defines.h"
#if (ESP8266 || ESP32 || USE_WIFI_NINA || DDNS_USING_WIFI)
int status = WL_IDLE_STATUS; // the Wifi radio's status
#endif
void onUpdateCallback(const char* oldIP, const char* newIP)
{
Serial.print(F("DDNSGeneric - IP Change Detected: "));
Serial.println(newIP);
}
void initEthernet()
{
// For other boards, to change if necessary
#if ( USE_ETHERNET_GENERIC || USE_ETHERNET_ENC )
// Must use library patch for Ethernet, Ethernet2, EthernetLarge libraries
Ethernet.init (USE_THIS_SS_PIN);
#endif // #if ( USE_ETHERNET_GENERIC || USE_ETHERNET_ENC )
// start the ethernet connection and the server:
// Use DHCP dynamic IP and random mac
uint16_t index = millis() % NUMBER_OF_MAC;
// Use Static IP
//Ethernet.begin(mac[index], ip);
Ethernet.begin(mac[index]);
Serial.print(F("\nHTTP WebServer is @ IP : "));
Serial.println(Ethernet.localIP());
}
void setup()
{
Serial.begin(115200);
while (!Serial && millis() < 5000)
Serial.print("\nStart DuckDNS_Client on " + String(BOARD_NAME));
Serial.println(" with " + String(SHIELD_TYPE));
Serial.println(DDNS_GENERIC_VERSION);
#if DDNS_USING_WIFI_AT
// initialize serial for ESP module
EspSerial.begin(115200);
// initialize ESP module
WiFi.init(&EspSerial);
Serial.println(F("WiFi shield init done"));
#endif
#if (ESP8266 || ESP32)
WiFi.mode(WIFI_STA);
#elif USE_WIFI_NINA
if (WiFi.status() == WL_NO_MODULE)
{
Serial.println(F("WiFi shield not present"));
// don't continue
while (true);
}
#elif (DDNS_USING_WIFI)
if (WiFi.status() == WL_NO_SHIELD)
{
Serial.println(F("WiFi shield not present"));
// don't continue
while (true);
}
#endif
#if USE_WIFI_NINA
String fv = WiFi.firmwareVersion();
if (fv < WIFI_FIRMWARE_LATEST_VERSION)
{
Serial.println(F("Please upgrade the firmware"));
}
#endif
#if DDNS_USING_WIFI
WiFi.begin(ssid, password);
Serial.println("Connecting to WiFi SSID: " + String(ssid));
while (WiFi.status() != WL_CONNECTED)
{
delay(500);
Serial.print(".");
}
Serial.print(F("\nHTTP WebServer is @ IP : "));
Serial.println(WiFi.localIP());
#elif (DDNS_USING_ETHERNET)
initEthernet();
#endif
server.begin();
DDNSGeneric.service("duckdns"); // Enter your DDNS Service Name - "duckdns" / "noip"
/*
For DDNS Providers where you get a token:
DDNSGeneric.client("domain", "token");
For DDNS Providers where you get username and password: ( Leave the password field empty "" if not required )
DDNSGeneric.client("domain", "username", "password");
*/
DDNSGeneric.client("account.duckdns.org", "12345678-1234-1234-1234-123456789012");
DDNSGeneric.onUpdate(onUpdateCallback);
}
void loop()
{
// Check for New Ip Every 10 mins.
DDNSGeneric.update(600000);
}