diff --git a/examples/esp32_ipv6.ino b/examples/esp32_ipv6.ino index b4e9bc1..2d097eb 100644 --- a/examples/esp32_ipv6.ino +++ b/examples/esp32_ipv6.ino @@ -10,22 +10,41 @@ void setup() { Serial.begin(115200); - WiFi.begin(ssid, pass); - Serial.println("Connecting to WiFi .."); - - while (WiFi.status() != WL_CONNECTED) - { - Serial.print('.'); - delay(1000); - } - - WiFi.enableIpV6(); - delay(3000); - - Serial.println("Connected to the WiFi network"); - Serial.println(WiFi.localIPv6()); - - update_dns_record(sub_domain, Authorization, get_global_ipv6_address().toString()); + #if ESP_ARDUINO_VERSION_MAJOR >= 3 + WiFi.enableIPv6(); + WiFi.begin(ssid, pass); + Serial.println("Connecting to WiFi .."); + + while (WiFi.status() != WL_CONNECTED) + { + Serial.print('.'); + delay(1000); + } + + delay(3000); + + Serial.println("Connected to the WiFi network"); + Serial.println(WiFi.linkLocalIPv6()); + + update_dns_record(sub_domain, Authorization, get_global_ipv6_address()); + #else + WiFi.begin(ssid, pass); + Serial.println("Connecting to WiFi .."); + + while (WiFi.status() != WL_CONNECTED) + { + Serial.print('.'); + delay(1000); + } + + WiFi.enableIpV6(); + delay(3000); + + Serial.println("Connected to the WiFi network"); + Serial.println(WiFi.localIPv6()); + + update_dns_record(sub_domain, Authorization, get_global_ipv6_address().toString()); + #endif } void loop() diff --git a/library.properties b/library.properties index 0d1d4dd..4ba7600 100644 --- a/library.properties +++ b/library.properties @@ -1,2 +1,2 @@ name = esp-ddns -version = 1.2.2 +version = 1.2.3 diff --git a/src/esp_ddns.cpp b/src/esp_ddns.cpp index e1ba1f6..33d9670 100644 --- a/src/esp_ddns.cpp +++ b/src/esp_ddns.cpp @@ -34,19 +34,51 @@ String get_global_ipv4_address(void) return global_ipv4_address; } -IPv6Address get_global_ipv6_address(void) -{ - esp_ip6_addr_t ipv6_address; - - esp_netif_t* get_esp_interface_netif(esp_interface_t interface); - - if(esp_netif_get_ip6_global(get_esp_interface_netif(ESP_IF_WIFI_STA), &ipv6_address)) +#if ESP_ARDUINO_VERSION_MAJOR >= 3 + String get_global_ipv6_address(void) { - return IPv6Address(); + String global_ipv6_address = ""; + + if (WiFi.status() == WL_CONNECTED) + { + HTTPClient http; + + http.begin(api_get_global_ipv6_address.c_str()); + + uint16_t http_response_code = http.GET(); + String response = http.getString(); + + http.end(); + + Serial.print("HTTP Response Code: "); + Serial.println(http_response_code); + Serial.print("Response: "); + Serial.println(response); + + global_ipv6_address = response; + } + else + { + Serial.println("Wifi Disconnected"); + } + + return global_ipv6_address; } - - return IPv6Address(ipv6_address.addr); -} +#else + IPv6Address get_global_ipv6_address(void) + { + esp_ip6_addr_t ipv6_address; + + esp_netif_t* get_esp_interface_netif(esp_interface_t interface); + + if(esp_netif_get_ip6_global(get_esp_interface_netif(ESP_IF_WIFI_STA), &ipv6_address)) + { + return IPv6Address(); + } + + return IPv6Address(ipv6_address.addr); + } +#endif String get_root_domain(String sub_domain) { diff --git a/src/esp_ddns.h b/src/esp_ddns.h index e3a2b29..dd52217 100644 --- a/src/esp_ddns.h +++ b/src/esp_ddns.h @@ -2,6 +2,7 @@ #define __ESP_DDNS_H #include +#include #include #include @@ -11,7 +12,11 @@ String get_root_domain_id(String root_domain, String Authorization); String get_sub_domain_id(String sub_domain, String Authorization); String get_dns_record_type(String ip_address); -IPv6Address get_global_ipv6_address(void); +#if ESP_ARDUINO_VERSION_MAJOR >= 3 + String get_global_ipv6_address(void); +#else + IPv6Address get_global_ipv6_address(void); +#endif void update_dns_record(String sub_domain, String Authorization, String ip_address);