Example program for the Ethernet Shield V2.0 by SeeedStudio. The example gets an IP address via DHCP and then requests http://mbed.org/media/uploads/mbed_official/hello.txt

Dependencies:   WIZ820ioInterface mbed

Files at this revision

API Documentation at this revision

Comitter:
screamer
Date:
Fri Apr 11 13:07:20 2014 +0000
Child:
1:bb040724d21b
Commit message:
Initial commit

Changed in this revision

WIZ820ioInterface.lib Show annotated file Show diff for this revision Revisions of this file
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
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/WIZ820ioInterface.lib	Fri Apr 11 13:07:20 2014 +0000
@@ -0,0 +1,1 @@
+http://mbed.org/users/va009039/code/WIZ820ioInterface/#fb15c35d1e28
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/main.cpp	Fri Apr 11 13:07:20 2014 +0000
@@ -0,0 +1,51 @@
+#include "mbed.h"
+#include "WIZ820ioInterface.h"
+
+Serial pc(USBTX, USBRX);
+WIZ820ioInterface eth(D11, D12, D13, D10, NC);
+
+int main()
+{
+    wait(3);
+    pc.printf(">>> Get IP via DHCP...\n");
+    int s = eth.init(); // Use DHCP
+
+    if (s != NULL) {
+        pc.printf(">>> Could not initialise. Halting!\n");
+        exit(0);
+    }
+
+    while (1) {
+        s = eth.connect();
+
+        if (s == false || s < 0) {
+            pc.printf(">>> Could not connect to network. Retrying!\n");
+            wait(3);
+        } else {
+            break;
+        }
+    }
+
+    // successful DHCP
+    pc.printf(">>> Got IP Address: %s\n", eth.getIPAddress());
+
+    char http_cmd[] = "GET /media/uploads/mbed_official/hello.txt HTTP/1.0\n\n";
+    TCPSocketConnection sock;
+    sock.connect("mbed.org", 80);    
+    sock.send_all(http_cmd, sizeof(http_cmd)-1);
+    pc.printf(">>> Sent request to mbed.org\n");
+
+    char buffer[300];
+    int ret;
+    while (true) {
+        ret = sock.receive(buffer, sizeof(buffer)-1);
+        if (ret <= 0)
+            break;
+        buffer[ret] = '\0';
+        pc.printf(">>> Received %d chars from mbed.org:\n%s\n", ret, buffer);
+    }
+    sock.close();
+    
+    eth.disconnect();
+    return 0;
+}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/mbed.bld	Fri Apr 11 13:07:20 2014 +0000
@@ -0,0 +1,1 @@
+http://mbed.org/users/mbed_official/code/mbed/builds/6473597d706e
\ No newline at end of file