eth test
Dependencies: HTTPClient mbed-rtos
Fork of HTTPClient_HelloWorld by
Diff: main.cpp
- Revision:
- 3:cde1ce546553
- Parent:
- 2:270e2d0bb85a
--- 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