Introduction: Arduino DDNS (Dynamic DNS) by Open-Electronics.org

This device captures the IP address of your network and it publish on site DynDNS.com. All without PC. It allow a remote access to your LAN even if the IP address of the connections changes.
For logistics reasons the provider can not assign a IP fixed for all users, so many users, especially private, work with a dynamic IP or public IP: in practice when they connect modem or router, to their connection is assigned an IP address that, when the connection will’be closed, can be used by other users. This makes impossible to contact a remote computer or device connected to a LAN Internet.

Step 1: Schematics

Our device is essentially a publisher of IP address. Everything is made from a circuit that incorporates an Ethernet interface WIZnet WIZ811MJ, managed by an Atmega328 microcontroller programmed with the Arduino bootloader, so it all works like an Arduino and you can use the Arduino IDE. The Atmega I/O PB2, PB3, PB4 and PB5 are dedicated to dialogue with the Ethernet module and provide a full four-wire SPI bus. The microcontroller is programmed using the special interface TTL / USB from SparkFun.

R1, R2: 470 ohm
R3: 10 kohm
C1: 100 nF
C2: 470 μF 25 VL
C3: 100 nF
C4: 470 μF 16 VL
U1: WIZNET
U2: ATMEGA328P (with Arduino bootloader)
U3: LD1086V33
P1: Microswitch
LD1: LED 3 mm yellow
LD2: LED 3 mm red
D1: 1N4007
power jack
Dip socket 14+14
Break away headers male 6 via
Break away headers female 2x10 via (2 pz)

Step 2: How Works


The main program sends the request to the IP address http://checkip.dyndns.com/ site. Now prepare the process of submitting to the site www.dyndns.com, which provides for the opening of a session onthe web page on, where will send data strings containing user name and password, thena string containing the Current IP connection. Cyclically the microcontroller check the IP to see if the address is changed, then, if it’s true, sends the new IP to www.dyndns.com

We use a dedicated circuit but the project can be replicated using an Arduino UNO and a Ethernet Shield.

Step 3: The Arduino Sketch

This is the complete sketch.
You can download the source code from open-electronics.org or in this page.

Download the DDNS sketch for Arduino


/* DynDNS
created 2011
by Boris Landoni
This example code is in the public domain.
http://www.open-electronics.org
http://www.futurashop.it
*/
http://username:password@members.dyndns.org/nic/
update?hostname=yourhostname&myip=ipaddress
#include <Ethernet.h>
#include <WString.h>
#include <EEPROM.h>
#define UPDATE_INTERVAL 30000
// if the connection is good wait 30 seconds should not be less than 5
int ledR = 8;
int ledG = 9;
unsigned long pubblica=0;
byte mac[] = { 0x54,0x55,0x58,0x10,0x00,0x24 };
byte ip[] = { 192, 168, 0, 98 };
byte domainaddrip[]= { 208, 78, 70, 70 }; //http://checkip.dyndns.com/
byte ipAddr[4];
byte domaindydns[]= { 204, 13, 248, 112 }; // members.dyndns.org
char hostname[ ] = "xxxxxxx.getmyip.com";
char userpwdb64[ ] = "xxxxxxxxxxxxxxxxxx";
//http://www.functions-online.com/base64_encode.html
use-> username:password
String ipadsl = String(20);
String ipadslold = String(20);
String inString = String(51);
const char* ip_to_str(const uint8_t*);
Client client(domainaddrip, 80);
Client clientdyn(domaindydns, 80);
void setup()
{
pinMode(ledR, OUTPUT);
pinMode(ledG, OUTPUT);
Ethernet.begin(mac, ip);
Serial.begin(9600);
Serial.println("*********Start*******");
delay(1000);
}
void loop()
{
if (millis() < pubblica) pubblica = millis();
if ((millis() - pubblica) > UPDATE_INTERVAL){
Serial.print("tempo trascorso dall'accensione ");
Serial.println(millis());
Serial.println(pubblica);
pubblica = millis();
acquisisciip();
}
}
void acquisisciip()
{
int timeout=0;
int skip=0;
ipadsl="";
inString="";
digitalWrite(ledG, HIGH);
Serial.print("connecting to ");
if (client.connect()) {
Serial.println("connected");
client.println("GET / HTTP/1.0");
client.print("HOST: ");
client.println("www.dyndns.com");
client.println();
} else {
Serial.println("connection failed");
}
while (!client.available() && timeout<50)
{
timeout++;
Serial.print("Time out ");
Serial.println(timeout);
delay(100);
}
while (client.available())
{
char c = client.read();
skip++;
if (skip>220)
{
if ((inString.length())<50) inString.append(c);
}
}
client.flush();
if ((inString.length())>5){
if (inString.contains("Address")){
int from=(inString.indexOf("Address")+9);
int lunghe=inString.length();
int to=(lunghe-16);
ipadsl=inString.substring(from,to);
Serial.print("IP rilevato dal sito: >");
Serial.print(ipadsl);
Serial.println("<");
}
}
if (!client.connected()){
Serial.println("disconnecting.");
client.stop();
delay (1000);
Serial.print("lunghezza IP ");
Serial.println(ipadsl.length());
if ((strlen(ipadsl))!=0){
Serial.print("IP nuovo : >");
Serial.print(ipadsl);
Serial.println("<");
for (int i=0; i<(ipadsl.length()); i++) {
//salva in memoria l'indirizzo acquisito
ipadslold[i] = EEPROM.read(i);
}
Serial.print("IP vecchio: >");
Serial.print(ipadslold);
Serial.println("<");
if (strcmp(ipadsl,ipadslold)){
Serial.println("IP diverso PUBBLICO");
digitalWrite(ledR, HIGH);
pubblicaip();
digitalWrite(ledR, LOW);
}
else
{
Serial.println("IP uguale");
}
digitalWrite(ledG, LOW);
for (int i=0; i<(ipadsl.length()); i++) {
//salva in memoria l'indirizzo acquisito
EEPROM.write(i, ipadsl[i]);
}
}
}
}
void pubblicaip()
{
int timeout=0;
Serial.print("connecting to ");
Serial.println(ip_to_str(domaindydns));
Serial.print("IP da pubblicare ");
Serial.println(ipadsl);
if (clientdyn.connect()) {
Serial.println("connected");
clientdyn.print("GET /nic/update?hostname=");
clientdyn.print(hostname);
clientdyn.print("&myip=");
clientdyn.print(ipadsl);
clientdyn.println(" HTTP/1.0 ");
clientdyn.print("Host: ");
clientdyn.println(ip_to_str(domaindydns));
clientdyn.print("Authorization: Basic ");
clientdyn.println(userpwdb64);
clientdyn.println
("User-Agent: futura - arduinodydns - 1.1");
clientdyn.println();
} else {
Serial.println("connection failed");
}
while (!clientdyn.available() && timeout<50) {
timeout++;
Serial.print("Time out ");
Serial.println(timeout);
delay(100);
}
while (clientdyn.available()) {
if (clientdyn.available())
{
char c = clientdyn.read();
Serial.print(c);
}
}
if (!clientdyn.connected()){
Serial.println();
Serial.println("disconnecting.");
clientdyn.stop();
}
}
//This is just a little utility function
//to format an IP address as a string.
const char* ip_to_str(const uint8_t* ipAddr)
{
static char buf[16];
sprintf(buf, "%d.%d.%d.%d\0", ipAddr[0],
ipAddr[1], ipAddr[2], ipAddr[3]);
return buf;
}   


Comments

author
q2dg (author)2015-04-05

Dyndns isn't free no more...

author
hoddy (author)2013-01-08

Hello looks like a great project any chance of updated version of the code?

author
hun1 (author)2011-11-11

Quick question, what program are you using for your electronic schematic and pcb layout? is it eagle?

author
technolando (author)hun12011-11-11

Hi, I used Circad for the schematic and Easy PC (NumberOne) for the PCB.

author
technolando (author)2011-04-11

Hi Ideanator, I'm sorry, I will increase the documentation today. I don't want do spam, but the circuit is very simple.

author
The Ideanator (author)2011-04-10

This ible has promise I just don't see it yet, it also is a borderline spam. If you put full build instructions down and demonstrated how to get it working and use the thing instead of posting schematics, board art, and a short blurb about it and your site, you could have an awesome post AND get lots more traffic to your site (way more than this ible would get you in its current state). Hope that helps!