WIZ Proto Makers 3th TCP
Dependencies: WIZnetInterface mbed
Fork of WIZwiki-W7500-lecture1-tcp by
Revision 0:d7c890f9ee69, committed 2015-06-25
- Comitter:
- joon874
- Date:
- Thu Jun 25 03:01:49 2015 +0000
- Child:
- 1:2f7108c02fc9
- Commit message:
- TCP Client Example to get weather info on WIZwiki-W7500
Changed in this revision
| main.cpp | Show annotated file Show diff for this revision Revisions of this file |
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/main.cpp Thu Jun 25 03:01:49 2015 +0000
@@ -0,0 +1,43 @@
+#include "mbed.h"
+#include "EthernetInterface.h"
+
+int main() {
+
+ int phy_link;
+ printf("Wait a second...\r\n");
+ uint8_t mac_addr[6] = {0x00, 0x08, 0xDC, 0x00, 0x01, 0x02};
+
+ EthernetInterface eth;
+ eth.init(mac_addr); //Use DHCP
+ eth.connect();
+
+ do{
+ phy_link = eth.ethernet_link();
+ printf("...");
+ wait(2);
+ }while(!phy_link);
+ printf("\r\n");
+
+ printf("IP Address is %s\r\n", eth.getIPAddress());
+
+ TCPSocketConnection sock;
+ sock.connect("api.openweathermap.org", 80);
+
+
+ char http_cmd[] = "GET /data/2.5/weather?q=Seoul,kr HTTP/1.0\n\n";
+ sock.send_all(http_cmd, sizeof(http_cmd)-1);
+
+ char buffer[400];
+ int ret;
+ while (true) {
+ ret = sock.receive(buffer, sizeof(buffer)-1);
+ if (ret <= 0) break;
+ buffer[ret] = '\0';
+ printf("Received %d chars from server: %s\n", ret, buffer);
+ }
+
+ sock.close();
+
+ eth.disconnect();
+
+}
\ No newline at end of file
