compile ok 20140330 , update mbed and mbed-rtos
Dependencies: C12832 EthernetInterface HTTPClient mbed-rtos mbed MbedJSONValue
Fork of HTTPClient_HelloWorld by
Diff: main.cpp
- Revision:
- 4:b157cc2de561
- Parent:
- 2:270e2d0bb85a
- Child:
- 5:6d5842b97059
--- a/main.cpp Sun Mar 30 13:58:02 2014 +0000 +++ b/main.cpp Fri Apr 25 19:13:39 2014 +0000 @@ -1,79 +1,42 @@ #include "mbed.h" #include "EthernetInterface.h" #include "HTTPClient.h" +#include "C12832.h" +#include "picojson.h" EthernetInterface eth; HTTPClient http; -char str[512]; +char str[2048]; +C12832 lcd(p5, p7, p6, p8, p11); 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); + lcd.printf("\nTrying to fetch page...\n"); + int ret = http.get("https://dweet.io/get/latest/dweet/for/modern-wheel", str, sizeof(str)); 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); + //lcd.printf("Page fetched successfully - read %d characters\n", strlen(str)); + //lcd.printf("Result: %s\n", str); + picojson::value v; + const char* start = str; + const char* end = (const char*)(str + strlen(str)); + std::string err = picojson::parse(v, start, end); + if (! err.empty()) + { + lcd.printf("Error - %s", err.c_str()); + } } else { - printf("Error - ret = %d - HTTP return code = %d\n", ret, http.getHTTPResponseCode()); - } - - //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()); + lcd.printf("Error - ret = %d - HTTP return code = %d\n", ret, http.getHTTPResponseCode()); } - //DELETE data - //HTTPText inText(str, 512); - printf("\nTrying to delete resource...\n"); - ret = http.del("http://httpbin.org/delete", &inText); - if (!ret) + while(1) { - 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) { - } }