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
Hardware Configuration
WIZwiki-W7500 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
Revision 1:a5d5ddadd7e7, committed 2016-01-25
- Comitter:
- Ricky_Kwon
- Date:
- Mon Jan 25 05:11:13 2016 +0000
- Parent:
- 0:807cbe212e24
- Commit message:
- Wizwiki-W7500 DDNS
Changed in this revision
DDNSClient.cpp | Show annotated file Show diff for this revision Revisions of this file |
DDNSClient.h | Show annotated file Show diff for this revision Revisions of this file |
--- a/DDNSClient.cpp Thu Oct 29 00:26:47 2015 +0000 +++ b/DDNSClient.cpp Mon Jan 25 05:11:13 2016 +0000 @@ -6,6 +6,9 @@ { noip_ddns = "dynupdate.no-ip.com"; noip_ddns_port = 80; + + check_ip = "checkip.dyndns.com"; + check_ip_port = 80; } DDNSClient::~DDNSClient() { @@ -28,27 +31,27 @@ printf("Sended message to server :\r\n"); #endif snprintf(buf, sizeof(buf), "GET /nic/update?hostname=%s&myip=%s HTTP/1.0\r\n", _hostname, _ip); - DDNSupdate.send_all(buf, strlen(buf)); + DDNSupdate.send(buf, strlen(buf)); #ifdef DEBUG - printf("%s\r\n", buf); + printf("%s", buf); #endif snprintf(buf, sizeof(buf), "Host: dynupdate.no-ip.com\r\n"); //Write request - DDNSupdate.send_all(buf, strlen(buf)); + DDNSupdate.send(buf, strlen(buf)); #ifdef DEBUG - printf("%s\r\n", buf); + printf("%s", buf); #endif snprintf(buf, sizeof(buf), "Authorization: Basic %s\r\n", _idpass); //Write request - DDNSupdate.send_all(buf, strlen(buf)); + DDNSupdate.send(buf, strlen(buf)); #ifdef DEBUG - printf("%s\r\n", buf); + printf("%s", buf); #endif snprintf(buf, sizeof(buf), "User-Agent: mbed client/1.0 ricky@wiznet.co.kr\r\n\r\n"); //Write request - DDNSupdate.send_all(buf, strlen(buf)); + DDNSupdate.send(buf, strlen(buf)); #ifdef DEBUG - printf("%s\r\n", buf); + printf("%s", buf); #endif #ifdef DEBUG @@ -62,12 +65,66 @@ printf("%s", buf); #endif + wait(5.0); + memset(buf, 0, sizeof(buf)); + DDNSupdate.receive_all(buf, sizeof(buf)); +#ifdef DEBUG + printf("%s", buf); +#endif + DDNSupdate.close(); } -void DDNSClient::userSetNoIP(char* idpass, char* hostname, char* ip) +void DDNSClient::userSetNoIP(char* idpass, char* hostname) { _hostname = hostname; - _ip = ip; _idpass = idpass; } +void DDNSClient::checkIp(void) +{ + char buf[1024]={0,}; + char* tok; + +#ifdef DEBUG + printf("Checiking IP...\r\n"); +#endif + while (CheckIp.connect(check_ip, check_ip_port) < 0) { + #ifdef DEBUG + printf("Unable to connect to (%s) on port (%d)\r\n", check_ip, check_ip_port); + #endif + wait(0.5); + } +#ifdef DEBUG + printf("Sended message to server :\r\n"); +#endif + snprintf(buf, sizeof(buf), "GET / HTTP/1.0\r\n", _hostname, _ip); + CheckIp.send(buf, strlen(buf)); +#ifdef DEBUG + printf("%s", buf); +#endif + snprintf(buf, sizeof(buf), "Host: checkip.dyndns.com\r\n\r\n"); + CheckIp.send(buf, strlen(buf)); +#ifdef DEBUG + printf("%s", buf); +#endif + +#ifdef DEBUG + printf("Received message from server :\r\n"); +#endif + + wait(3.0); + memset(buf, 0, sizeof(buf)); + CheckIp.receive_all(buf, sizeof(buf)); +#ifdef DEBUG + printf("%s", buf); +#endif + + tok = strstr(buf, "Address: "); + tok = strtok(tok+9, "<"); + _ip = tok; + +#ifdef DEBUG + printf("IP:%s", tok); +#endif + CheckIp.close(); +} \ No newline at end of file
--- a/DDNSClient.h Thu Oct 29 00:26:47 2015 +0000 +++ b/DDNSClient.h Mon Jan 25 05:11:13 2016 +0000 @@ -10,13 +10,17 @@ ~DDNSClient(); void updateNoIP(void); - void userSetNoIP(char* idpass, char* hostname, char* ip); - + void userSetNoIP(char* idpass, char* hostname); + void checkIp(void); private: TCPSocketConnection DDNSupdate; + TCPSocketConnection CheckIp; char* noip_ddns; + char* check_ip; int noip_ddns_port; + int check_ip_port; + char* _hostname; char* _ip; char* _idpass;