Skip to content

Commit

Permalink
Support for arduino-esp32 v3
Browse files Browse the repository at this point in the history
  • Loading branch information
themdeee committed Jul 9, 2024
1 parent c9256bd commit 6cf4162
Show file tree
Hide file tree
Showing 4 changed files with 85 additions and 29 deletions.
51 changes: 35 additions & 16 deletions examples/esp32_ipv6.ino
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down
2 changes: 1 addition & 1 deletion library.properties
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
name = esp-ddns
version = 1.2.2
version = 1.2.3
54 changes: 43 additions & 11 deletions src/esp_ddns.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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)
{
Expand Down
7 changes: 6 additions & 1 deletion src/esp_ddns.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
#define __ESP_DDNS_H

#include <regex>
#include <WiFi.h>
#include <HTTPClient.h>
#include <ArduinoJson.h>

Expand All @@ -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);

Expand Down

0 comments on commit 6cf4162

Please sign in to comment.