DDNS use No-IP

Dependents:   TCPEchoClient-WIZwiki-W7500

Prerequisite

This is DDNS_NoIP Library. DDNS(Dynamic DNS) host name is linked up to the uesr's dynamic IP address. Whenever the IP changes a dynamic DNS client will send an update to No-IP with the current IP address and then No-IP propagates the DNS change to the internet within seconds.


DDNS Configuration

NoIP Site

https://www.noip.com/ /media/uploads/joon874/1.png

/media/uploads/joon874/14.png

Hardware Configuration

WIZwiki-W7500 Pin map

pin map


Software

DDNS

/* Set ID Pass and Hostname */
void userSetNoIP(char* idpass, char* hostname);

/* Upload DDNS IP Address */
void updateNoIP(void);

/* Check DDNS IP Address */
void checkIp(void);


Caution

Committer:
Ricky_Kwon
Date:
Thu Oct 29 00:26:47 2015 +0000
Revision:
0:807cbe212e24
Child:
1:a5d5ddadd7e7
DDNS use No-IP

Who changed what in which revision?

UserRevisionLine numberNew contents of line
Ricky_Kwon 0:807cbe212e24 1 #include "mbed.h"
Ricky_Kwon 0:807cbe212e24 2 #include "EthernetInterface.h"
Ricky_Kwon 0:807cbe212e24 3 #include "DDNSClient.h"
Ricky_Kwon 0:807cbe212e24 4 #define DEBUG
Ricky_Kwon 0:807cbe212e24 5 DDNSClient::DDNSClient()
Ricky_Kwon 0:807cbe212e24 6 {
Ricky_Kwon 0:807cbe212e24 7 noip_ddns = "dynupdate.no-ip.com";
Ricky_Kwon 0:807cbe212e24 8 noip_ddns_port = 80;
Ricky_Kwon 0:807cbe212e24 9 }
Ricky_Kwon 0:807cbe212e24 10 DDNSClient::~DDNSClient()
Ricky_Kwon 0:807cbe212e24 11 {
Ricky_Kwon 0:807cbe212e24 12
Ricky_Kwon 0:807cbe212e24 13 }
Ricky_Kwon 0:807cbe212e24 14 void DDNSClient::updateNoIP(void)
Ricky_Kwon 0:807cbe212e24 15 {
Ricky_Kwon 0:807cbe212e24 16 char buf[1024]={0,};
Ricky_Kwon 0:807cbe212e24 17
Ricky_Kwon 0:807cbe212e24 18 #ifdef DEBUG
Ricky_Kwon 0:807cbe212e24 19 printf("Updating NoIP...\r\n");
Ricky_Kwon 0:807cbe212e24 20 #endif
Ricky_Kwon 0:807cbe212e24 21 while (DDNSupdate.connect(noip_ddns, noip_ddns_port) < 0) {
Ricky_Kwon 0:807cbe212e24 22 #ifdef DEBUG
Ricky_Kwon 0:807cbe212e24 23 printf("Unable to connect to (%s) on port (%d)\r\n", noip_ddns, noip_ddns_port);
Ricky_Kwon 0:807cbe212e24 24 #endif
Ricky_Kwon 0:807cbe212e24 25 wait(0.5);
Ricky_Kwon 0:807cbe212e24 26 }
Ricky_Kwon 0:807cbe212e24 27 #ifdef DEBUG
Ricky_Kwon 0:807cbe212e24 28 printf("Sended message to server :\r\n");
Ricky_Kwon 0:807cbe212e24 29 #endif
Ricky_Kwon 0:807cbe212e24 30 snprintf(buf, sizeof(buf), "GET /nic/update?hostname=%s&myip=%s HTTP/1.0\r\n", _hostname, _ip);
Ricky_Kwon 0:807cbe212e24 31 DDNSupdate.send_all(buf, strlen(buf));
Ricky_Kwon 0:807cbe212e24 32 #ifdef DEBUG
Ricky_Kwon 0:807cbe212e24 33 printf("%s\r\n", buf);
Ricky_Kwon 0:807cbe212e24 34 #endif
Ricky_Kwon 0:807cbe212e24 35
Ricky_Kwon 0:807cbe212e24 36 snprintf(buf, sizeof(buf), "Host: dynupdate.no-ip.com\r\n"); //Write request
Ricky_Kwon 0:807cbe212e24 37 DDNSupdate.send_all(buf, strlen(buf));
Ricky_Kwon 0:807cbe212e24 38 #ifdef DEBUG
Ricky_Kwon 0:807cbe212e24 39 printf("%s\r\n", buf);
Ricky_Kwon 0:807cbe212e24 40 #endif
Ricky_Kwon 0:807cbe212e24 41
Ricky_Kwon 0:807cbe212e24 42 snprintf(buf, sizeof(buf), "Authorization: Basic %s\r\n", _idpass); //Write request
Ricky_Kwon 0:807cbe212e24 43 DDNSupdate.send_all(buf, strlen(buf));
Ricky_Kwon 0:807cbe212e24 44 #ifdef DEBUG
Ricky_Kwon 0:807cbe212e24 45 printf("%s\r\n", buf);
Ricky_Kwon 0:807cbe212e24 46 #endif
Ricky_Kwon 0:807cbe212e24 47
Ricky_Kwon 0:807cbe212e24 48 snprintf(buf, sizeof(buf), "User-Agent: mbed client/1.0 ricky@wiznet.co.kr\r\n\r\n"); //Write request
Ricky_Kwon 0:807cbe212e24 49 DDNSupdate.send_all(buf, strlen(buf));
Ricky_Kwon 0:807cbe212e24 50 #ifdef DEBUG
Ricky_Kwon 0:807cbe212e24 51 printf("%s\r\n", buf);
Ricky_Kwon 0:807cbe212e24 52 #endif
Ricky_Kwon 0:807cbe212e24 53
Ricky_Kwon 0:807cbe212e24 54 #ifdef DEBUG
Ricky_Kwon 0:807cbe212e24 55 printf("Received message from server :\r\n");
Ricky_Kwon 0:807cbe212e24 56 #endif
Ricky_Kwon 0:807cbe212e24 57
Ricky_Kwon 0:807cbe212e24 58 wait(5.0);
Ricky_Kwon 0:807cbe212e24 59 memset(buf, 0, sizeof(buf));
Ricky_Kwon 0:807cbe212e24 60 DDNSupdate.receive_all(buf, sizeof(buf));
Ricky_Kwon 0:807cbe212e24 61 #ifdef DEBUG
Ricky_Kwon 0:807cbe212e24 62 printf("%s", buf);
Ricky_Kwon 0:807cbe212e24 63 #endif
Ricky_Kwon 0:807cbe212e24 64
Ricky_Kwon 0:807cbe212e24 65 DDNSupdate.close();
Ricky_Kwon 0:807cbe212e24 66
Ricky_Kwon 0:807cbe212e24 67 }
Ricky_Kwon 0:807cbe212e24 68 void DDNSClient::userSetNoIP(char* idpass, char* hostname, char* ip)
Ricky_Kwon 0:807cbe212e24 69 {
Ricky_Kwon 0:807cbe212e24 70 _hostname = hostname;
Ricky_Kwon 0:807cbe212e24 71 _ip = ip;
Ricky_Kwon 0:807cbe212e24 72 _idpass = idpass;
Ricky_Kwon 0:807cbe212e24 73 }