http
Dependencies: EthernetInterface HTTPClient mbed-rtos mbed
Diff: main.cpp
- Revision:
- 1:d29e4c5d19bb
- Parent:
- 0:7c79134d4f23
- Child:
- 2:b28641cc3ee0
--- a/main.cpp Fri Sep 12 17:14:15 2014 +0000 +++ b/main.cpp Fri Sep 26 11:07:31 2014 +0000 @@ -1,79 +1,47 @@ #include "mbed.h" #include "EthernetInterface.h" #include "HTTPClient.h" - + EthernetInterface eth; HTTPClient http; + +DigitalOut myled(LED2); + char str[512]; - -int main() + +const char *url = "http://10.2.202.171/"; + +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()); - } - - //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 r = 0; + int flash = 0; + myled = 0; + + eth.init(); + eth.connect(); + + while (true) { + r = http.get(url, str, 32); + + if (r > 0) { + std::printf("Error %d - HTTP return code %d\n", r, http.getHTTPResponseCode()); + goto fail; } - - //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) - { - 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()); + + flash = std::atoi(str); + + for (int i = 0; i < flash; i++) { + myled = 1; + wait(0.1); + myled = 0; + wait(0.1); } - - //DELETE data - //HTTPText inText(str, 512); - printf("\nTrying to delete resource...\n"); - ret = http.del("http://httpbin.org/delete", &inText); - if (!ret) - { - printf("Executed DELETE 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.disconnect(); - - while(1) {} -} - \ No newline at end of file + + wait(1.0); + } + +fail: + eth.disconnect(); + + while(1) {} +} \ No newline at end of file