eth test

Dependencies:   HTTPClient mbed-rtos

Fork of HTTPClient_HelloWorld by Donatien Garnier

Files at this revision

API Documentation at this revision

Comitter:
brdarji
Date:
Wed Jan 06 08:54:22 2016 +0000
Parent:
2:270e2d0bb85a
Commit message:
eth_test

Changed in this revision

EthernetInterface.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-rtos.lib Show annotated file Show diff for this revision Revisions of this file
mbed-src.lib Show annotated file Show diff for this revision Revisions of this file
mbed.bld Show diff for this revision Revisions of this file
--- a/EthernetInterface.lib	Thu Aug 30 15:42:06 2012 +0000
+++ b/EthernetInterface.lib	Wed Jan 06 08:54:22 2016 +0000
@@ -1,1 +1,1 @@
-http://mbed.org/users/mbed_official/code/EthernetInterface/#a0ee3ae75cfa
+https://developer.mbed.org/teams/Edutech/code/EthernetInterface/#5906306597f5
--- a/main.cpp	Thu Aug 30 15:42:06 2012 +0000
+++ b/main.cpp	Wed Jan 06 08:54:22 2016 +0000
@@ -4,76 +4,35 @@
 
 EthernetInterface eth;
 HTTPClient http;
+Serial pc(P0_2, P0_3);
 char str[512];
 
+// For Static IP
+static const char* mbedIp       = "192.168.0.160";  //IP
+static const char* mbedMask     = "255.255.255.0";  // Mask
+static const char* mbedGateway  = "192.168.0.254";  //Gateway
+
 int main() 
 {
-    eth.init(); //Use DHCP
-
-    eth.connect();
-    
-    //GET data
-    printf("\nTrying to fetch page...\n");
-    int ret = http.get("http://mbed.org/media/uploads/donatien/hello.txt", str, 128);
-    if (!ret)
-    {
-      printf("Page fetched successfully - read %d characters\n", strlen(str));
-      printf("Result: %s\n", str);
-    }
-    else
-    {
-      printf("Error - ret = %d - HTTP return code = %d\n", ret, http.getHTTPResponseCode());
-    }
+//    eth.init(); //Use DHCP
     
-    //POST data
-    HTTPMap map;
-    HTTPText inText(str, 512);
-    map.put("Hello", "World");
-    map.put("test", "1234");
-    printf("\nTrying to post data...\n");
-    ret = http.post("http://httpbin.org/post", map, &inText);
-    if (!ret)
-    {
-      printf("Executed POST successfully - read %d characters\n", strlen(str));
-      printf("Result: %s\n", str);
-    }
-    else
-    {
-      printf("Error - ret = %d - HTTP return code = %d\n", ret, http.getHTTPResponseCode());
-    }
+    int s = eth.init(mbedIp,mbedMask,mbedGateway); //Use these parameters for static IP
     
-    //PUT data
-    strcpy(str, "This is a PUT test!");
-    HTTPText outText(str);
-    //HTTPText inText(str, 512);
-    printf("\nTrying to put resource...\n");
-    ret = http.put("http://httpbin.org/put", outText, &inText);
-    if (!ret)
+    if( s != NULL )
     {
-      printf("Executed PUT successfully - read %d characters\n", strlen(str));
-      printf("Result: %s\n", str);
-    }
-    else
-    {
-      printf("Error - ret = %d - HTTP return code = %d\n", ret, http.getHTTPResponseCode());
-    }
+        pc.printf( "Could not initialise. Will halt!\n\r" );        
+        exit( 0 );
+    }    
+        
+    s = eth.connect();
     
-    //DELETE data
-    //HTTPText inText(str, 512);
-    printf("\nTrying to delete resource...\n");
-    ret = http.del("http://httpbin.org/delete", &inText);
-    if (!ret)
+    if( s != NULL )
     {
-      printf("Executed DELETE successfully - read %d characters\n", strlen(str));
-      printf("Result: %s\n", str);
+        pc.printf( "Could not connect. Will halt!\n\r" );
+        exit( 0 );
     }
-    else
+    else 
     {
-      printf("Error - ret = %d - HTTP return code = %d\n", ret, http.getHTTPResponseCode());
+        pc.printf( "IP: %s\n\r", eth.getIPAddress() );    
     }
-    
-    eth.disconnect();  
-
-    while(1) {
-    }
-}
+}
\ No newline at end of file
--- a/mbed-rtos.lib	Thu Aug 30 15:42:06 2012 +0000
+++ b/mbed-rtos.lib	Wed Jan 06 08:54:22 2016 +0000
@@ -1,1 +1,1 @@
-http://mbed.org/users/mbed_official/code/mbed-rtos/#9654a71f5a90
+http://mbed.org/users/mbed_official/code/mbed-rtos/#79d2f32f753f
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/mbed-src.lib	Wed Jan 06 08:54:22 2016 +0000
@@ -0,0 +1,1 @@
+http://developer.mbed.org/teams/Edutech/code/mbed-src/#ade998f7ad0e
--- a/mbed.bld	Thu Aug 30 15:42:06 2012 +0000
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,1 +0,0 @@
-http://mbed.org/users/mbed_official/code/mbed/builds/976df7c37ad5
\ No newline at end of file