Dynamic DNS Update Library (DDNS_Generic)

Working libraries, libraries being ported and related hardware
Post Reply
khoih-prog
Posts: 102
Joined: Thu Feb 27, 2020 7:54 am
Location: Toronto

Dynamic DNS Update Library (DDNS_Generic)

Post by khoih-prog »

DDNS_Generic Library

How To Install Using Arduino Library Manager


Why do we need this Async DDNS_Generic Library

Many of us are using Dynamic DNS service because Dynamic IP addresses is much cheaper than the expensive static IP address.

Dynamic IP addresses present a problem if we wants to provide a service to other users on the Internet, such as a web service, Blynk Local Server, etc. As the IP address may change frequently (due to power outtage/surge, power on/off, DSL/Fiber issues, etc.), the corresponding domain names must be quickly re-mapped in the DNS, to maintain accessibility using a well-known URL.

Many providers offer commercial or free Dynamic DNS service for this scenario. The automatic reconfiguration is generally implemented in the user's router or computer, which runs software to update the DDNS service. The communication between the user's equipment and the provider is not standardized, although a few standard web-based methods of updating have emerged over time.

This Library is created to automatically update your DDNS Domains with the latest dynamic IP address, using one of the many available boards / shields. See Currently Supported Boards.

The time between checks to update the DDNS Service is configurable to match your use case, and is set in the examples at 10 minutes.

The DDNS_Generic code is very short, can be immersed in your Projects and to be called in the loop() code.

It currently supports DuckDNS, No-ip, DynDNS, Dynu, enom, all-inkl, selfhost.de, dyndns.it, strato, freemyip, afraid.org. Expansion to support more DDNS sevice providers is very easy and can be done by yourself.

This DDNS_Generic Library is based on and modified from Ayush Sharma's EasyDDNS Library to add support to many boards and shields besides ESP32 and ESP8266.

Initial Releases v1.0.0

1. Initial coding for Generic boards using many different WiFi/Ethernet modules/shields.
2. Add more examples

Currently Supported Boards

- ESP8266
- ESP32
- AdaFruit Feather nRF52832, nRF52840 Express, BlueFruit Sense, Itsy-Bitsy nRF52840 Express, Metro nRF52840 Express, NINA_B302_ublox, NINA_B112_ublox etc..
- Arduino SAMD21 (ZERO, MKR, NANO_33_IOT, etc.).
- Adafruit SAM21 (Itsy-Bitsy M0, Metro M0, Feather M0, Gemma M0, etc.).
- Adafruit SAM51 (Itsy-Bitsy M4, Metro M4, Grand Central M4, Feather M4 Express, etc.).
- Seeeduino SAMD21/SAMD51 boards (SEEED_WIO_TERMINAL, SEEED_FEMTO_M0, SEEED_XIAO_M0, Wio_Lite_MG126, WIO_GPS_BOARD, SEEEDUINO_ZERO, SEEEDUINO_LORAWAN, SEEED_GROVE_UI_WIRELESS, etc.)
- STM32 (Nucleo-144, Nucleo-64, Nucleo-32, Discovery, STM32F1, STM32F3, STM32F4, STM32H7, STM32L0, etc.).
- SAM DUE
- STM32F/L/H/G/WB/MP1 (Nucleo-64 L053R8,Nucleo-144, Nucleo-64, Nucleo-32, Discovery, STM32Fx, STM32H7, STM32Lx, STM32Gx, STM32WB, STM32MP1, etc.) having 64K+ Flash program memory.

Currently Supported WiFi Modules/Shields

- ESP8266 built-in WiFi
- ESP32 built-in WiFi
- WiFiNINA using WiFiNINA or WiFiNINA_Generic library.
- ESP8266-AT, ESP32-AT WiFi shields using WiFiEspAT or ESP8266_AT_WebServer library.

Currently Supported Ethernet Modules/Shields

- W5x00's using Ethernet, EthernetLarge, Ethernet2 or Ethernet3 Library.
- ENC28J60 using new EthernetENC and UIPEthernet library
- LAN8742A using STM32duino LwIP,STM32duino STM32Ethernet libraries

Sample Code

This is the STM32_Ethernet_DuckDNS_Client example

Code: Select all

#include "defines.h"

void onUpdateCallback(const char* oldIP, const char* newIP)
{
  Serial.print("DDNSGeneric - IP Change Detected: ");
  Serial.println(newIP);
}

void setup()
{
  Serial.begin(115200);
  while (!Serial);

  Serial.print("\nStart STM32_Ethernet_DuckDNS_Client on " + String(BOARD_NAME));
  Serial.println(" with " + String(SHIELD_TYPE));

  // For other boards, to change if necessary
#if ( !USE_BUILTIN_ETHERNET && USE_ETHERNET )
    // Must use library patch for Ethernet library
    Ethernet.init (USE_THIS_SS_PIN);  
#endif

  // 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());

  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);
}

Debug Termimal Output Samples

1. This is terminal debug output when running STM32_Ethernet_DuckDNS_Client example on Adafruit nRF52 NRF52840_FEATHER.

Code: Select all

Start DuckDNS_Client on NUCLEO_F767ZI with LAN8742A using STM32Ethernet Library

HTTP WebServer is @ IP : 192.168.2.83
[DDNS] Access whatismyipaddress
[DDNS] httpCode = 200
[DDNS] Current Public IP = aaa.bbb.ccc.ddd
[DDNS] response = aaa.bbb.ccc.ddd
[DDNS] Sending HTTP_GET to duckdns
[DDNS] HTTP_GET = http://www.duckdns.org/update?domains=account.duckdns.org&token=token&ip=aaa.bbb.ccc.ddd
[DDNS] httpCode = 200
DDNSGeneric - IP Change Detected: aaa.bbb.ccc.ddd
[DDNS] Updated IP = aaa.bbb.ccc.ddd
2. This is terminal debug output when running No-ip_Client example on STM32F7 Nucleo-144 NUCLEO_F767ZI.

Code: Select all

Start No-ip_Client on NUCLEO_F767ZI with LAN8742A using STM32Ethernet Library

HTTP WebServer is @ IP : 192.168.2.84
[DDNS] Access whatismyipaddress
[DDNS] httpCode = 200
[DDNS] Current Public IP = aaa.bbb.ccc.ddd
[DDNS] response = aaa.bbb.ccc.ddd
[DDNS] Sending HTTP_GET to noip
[DDNS] HTTP_GET = http://account:password@dynupdate.no-ip.com/nic/update?hostname=hostname.ddns.net&myip=aaa.bbb.ccc.ddd
[DDNS] httpCode = 200
DDNSGeneric - IP Change Detected: aaa.bbb.ccc.ddd
[DDNS] Updated IP = aaa.bbb.ccc.ddd
[DDNS] Access whatismyipaddress
[DDNS] httpCode = 200
[DDNS] Current Public IP = aaa.bbb.ccc.ddd
[DDNS] response = aaa.bbb.ccc.ddd
Post Reply

Return to “Libraries & Hardware”