Free Wed Editor CoffeeFreeHTML15.0
Dependencies: WIZnetInterface mbed
Fork of WIZ_Proto_Makers_4th_Lab1 by
Revision 3:eb6b286cf2bd, committed 2016-02-17
- Comitter:
- Ricky_Kwon
- Date:
- Wed Feb 17 06:32:47 2016 +0000
- Parent:
- 2:6a79ff33db7f
- Commit message:
- WIZ Proto Makers 4th Lab 1
Changed in this revision
main.cpp | Show annotated file Show diff for this revision Revisions of this file |
mbed.bld | Show annotated file Show diff for this revision Revisions of this file |
--- a/main.cpp Wed Feb 03 03:16:46 2016 +0000 +++ b/main.cpp Wed Feb 17 06:32:47 2016 +0000 @@ -3,58 +3,66 @@ #define WEB_SERVER_PORT 80 -char send_dat[]="HTTP/1.1 200 OK\r\n"\ - "Content-Type: text/html\r\n"\ - "Connection: close\r\n\r\n"\ - "<html>\r\n"\ - "<body>"\ - "Hello world"\ - "</body>\r\n"\ - "</html>\r\n"; - +char HTTP[1024]={0,}; +char HTML[1024]={0,}; + +Serial pc(USBTX, USBRX); int main (void) { - printf("Wait a second...\r\n"); - uint8_t mac_addr[6] = {0x00, 0x08, 0xDC, 0x00, 0x01, 0x02}; - const char ip_addr[] = "192.168.0.222"; - const char mask_addr[] = "255.255.255.0"; - const char gateway_addr[] = "192.168.0.1"; + pc.printf("Wait a second...\n\r"); + uint8_t mac_addr[6] = {0x00, 0x08, 0xDC, 0x00, 0x05, 0x01}; +// const char ip_addr[] = "192.168.0.222"; +// const char mask_addr[] = "255.255.255.0"; +// const char gateway_addr[] = "192.168.0.1"; EthernetInterface eth; - //eth.init(mac_addr); //Use DHCP - eth.init(mac_addr, ip_addr, mask_addr, gateway_addr); //Use Static + eth.init(mac_addr); //Use DHCP + //eth.init(mac_addr, ip_addr, mask_addr, gateway_addr); //Use Static eth.connect(); - printf("Server IP Address is %s\r\n", eth.getIPAddress()); + pc.printf("Server IP Address is %s\n\r", eth.getIPAddress()); TCPSocketServer server; server.bind(WEB_SERVER_PORT); server.listen(); + + sprintf(HTML, "<!DOCTYPE html>\r\n"\ + "<html>\n\r"\ + "<body>\n\r"\ + "<form action=\"1\"><input type=\"submit\" value=\"up\" /></form>\n\r"\ + "<form action=\"2\"><input type=\"submit\" value=\"down\" /></form>\n\r"\ + "<form action=\"3\"><input type=\"submit\" value=\"forward\" /></form>\n\r"\ + "</body>\n\r"\ + "</html>\n\r"); + + sprintf(HTTP, "HTTP/1.1 200 OK \n\r"\ + "Content-Length: %d\n\r"\ + "Content-Type: text/html\n\r"\ + "Connection: close\n\r\n\r", strlen(HTML)); while (true) { - printf("Wait for new connection...\r\n"); + pc.printf("Wait for new connection...\n\r"); TCPSocketConnection client; server.accept(client); client.set_blocking(false, 15000); // Timeout after (1.5)s - printf("Connection from: %s\r\n", client.get_address()); - char buffer[256]; + //pc.printf("Connection from: %s\n\r", client.get_address()); + char buffer[1024]; while (true) { - - wait(0.5); int n = client.receive_all(buffer, sizeof(buffer)); if (n <= 0) break; - //buffer[n] = '\0'; + buffer[n] = '\0'; - printf("rev_dat : %s\r\n", buffer); + //pc.printf("rev_dat : %s\n\r", buffer); if((buffer[0]=='G')&&(buffer[1]=='E')&&(buffer[2]=='T')&&(buffer[3]==' '))// GET_Request { - client.send(send_dat, sizeof(send_dat)); - printf("send_dat : %s\r\n", send_dat); + client.send(HTTP, strlen(HTTP)); + client.send(HTML, strlen(HTML)); + //pc.printf("send_dat : %s\n\r", send_dat); } - + if (n <= 0) break; } client.close();
--- a/mbed.bld Wed Feb 03 03:16:46 2016 +0000 +++ b/mbed.bld Wed Feb 17 06:32:47 2016 +0000 @@ -1,1 +1,1 @@ -http://mbed.org/users/mbed_official/code/mbed/builds/6f327212ef96 \ No newline at end of file +http://mbed.org/users/mbed_official/code/mbed/builds/252557024ec3 \ No newline at end of file