
DNS Web Client for WIZnet Academu
Dependencies: WIZnetInterface mbed
Revision 0:02f6cd2ee811, committed 2016-04-04
- Comitter:
- joon874
- Date:
- Mon Apr 04 06:34:53 2016 +0000
- Commit message:
- DNS web Client for WIZnetacademy
Changed in this revision
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/WIZnetInterface.lib Mon Apr 04 06:34:53 2016 +0000 @@ -0,0 +1,1 @@ +https://developer.mbed.org/teams/IOP/code/WIZnetInterface/#1a89f410e1e4
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/main.cpp Mon Apr 04 06:34:53 2016 +0000 @@ -0,0 +1,90 @@ +#include "mbed.h" +#include "EthernetInterface.h" + +DigitalOut myled1(LED1,1); +DigitalOut myled2(LED2,1); + +#define ECHO_SERVER_PORT 80 // HTTP default Port 80 +char ServerName[] = "naver.com"; +char http_cmd[] = "GET / HTTP/1.0\r\n\r\n"; + +#define BUFFER_SIZE 2048 +char buffer[BUFFER_SIZE]; + + +// Intitialize the Ethernet Client Library +EthernetInterface eth; + + +int main() { + + printf("-- Welcome WIZwiki-W7500 Platform -- \r\n"); + + myled1 = 0; + + // Enter a MAC Address for your Platform + uint8_t mac_addr[6] = {0x00, 0x08, 0xDC, 0x03, 0x04, 0x02}; + + // Initializing MAX Address + eth.init(mac_addr); + + do{ + printf(" Link - Wait... \r\n"); + wait(1); + }while(!eth.ethernet_link()); + printf("-- Ethetnet PHY Link - Done -- \r\n"); + + if (eth.connect() < 0 ) + printf("-- EThernet Connect - Fail -- \r\n"); + else + { + printf("-- Assigned Network Information -- \r\n"); + printf(" IP : %s\r\n\r\n", eth.getIPAddress()); + printf(" MASK : %s\r\n\r\n", eth.getNetworkMask()); + printf(" GW : %s\r\n\r\n", eth.getGateway()); + } + + // Initialize the TCP Socket Connection + TCPSocketConnection sock; + + if(sock.connect(ServerName, ECHO_SERVER_PORT) < 0) + printf("-- Connect - Fail -- \r\n"); + else + { + printf("-- Connect - Connected -- \r\n"); + wait(3); + while(sock.is_connected() == false) + { + printf(" ."); + } + sock.send_all(http_cmd, sizeof(http_cmd)); + } + + while(true) { + + int n = sock.receive_all(buffer, BUFFER_SIZE); + + if(n < 0) + break; + else + { + for(int i=0; i<n; i++) + printf("%c", buffer[i]); + } + + if(sock.is_connected() == false){ + sock.close(); + + myled1 = 1; + + while(1) { + myled2 = 1; + wait(0.5); + myled2 = 0; + wait(0.5); + } + } + + } + +} \ No newline at end of file
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/mbed.bld Mon Apr 04 06:34:53 2016 +0000 @@ -0,0 +1,1 @@ +http://mbed.org/users/mbed_official/code/mbed/builds/99a22ba036c9 \ No newline at end of file