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:
Mon Jun 09 13:23:14 2014 +0000
Parent:
3:2d0986d5542e
Child:
5:9dc9b597e8fb
Commit message:
Detect and retry socket connect on failure; Update to the latest mbed SDK

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	Fri Apr 11 16:24:53 2014 +0000
+++ b/main.cpp	Mon Jun 09 13:23:14 2014 +0000
@@ -29,7 +29,7 @@
         s = eth.connect(); // Connect to network
 
         if (s == false || s < 0) {
-            printf(">>> Could not connect to network. Retrying!\n");
+            printf(">>> Could not connect to network! Retrying ...\n");
             wait(3);
         } else {
             break;
@@ -38,11 +38,16 @@
     printf(">>> Got IP address: %s\n", eth.getIPAddress());
 
     // Prepare the http request to mbed.org
+    printf(">>> Open socket to mbed.org:80\n");
     char http_cmd[] = "GET /media/uploads/mbed_official/hello.txt HTTP/1.0\n\n";
     TCPSocketConnection sock;
-    sock.connect("mbed.org", 80);    
+    
+    while (sock.connect("mbed.org", 80) == -1) {
+        printf(">>> Unable to open socket! Retrying ...\n");
+    };
+    
+    printf(">>> Request %s\n", http_cmd);
     sock.send_all(http_cmd, sizeof(http_cmd)-1);
-    printf(">>> Sent request to mbed.org\n");
 
     // Read the response
     char buffer[300];
@@ -54,9 +59,13 @@
         buffer[ret] = '\0';
         printf(">>> Received %d chars from mbed.org:\n%s\n", ret, buffer);
     }
+
+    printf(">>> Close socket\n");
     sock.close();
     
     // Disconnect from network
+    printf(">>> Disconnect from network\n");
     eth.disconnect();
+
     return 0;
 }
--- a/mbed.bld	Fri Apr 11 16:24:53 2014 +0000
+++ b/mbed.bld	Mon Jun 09 13:23:14 2014 +0000
@@ -1,1 +1,1 @@
-http://mbed.org/users/mbed_official/code/mbed/builds/6473597d706e
\ No newline at end of file
+http://mbed.org/users/mbed_official/code/mbed/builds/0b3ab51c8877
\ No newline at end of file