compile ok 20140330 , update mbed and mbed-rtos
Dependencies: C12832 EthernetInterface HTTPClient mbed-rtos mbed MbedJSONValue
Fork of HTTPClient_HelloWorld by
main.cpp@4:b157cc2de561, 2014-04-25 (annotated)
- Committer:
- lamadio
- Date:
- Fri Apr 25 19:13:39 2014 +0000
- Revision:
- 4:b157cc2de561
- Parent:
- 2:270e2d0bb85a
- Child:
- 5:6d5842b97059
Fetch from dweet
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
donatien | 0:0e0debc29569 | 1 | #include "mbed.h" |
donatien | 0:0e0debc29569 | 2 | #include "EthernetInterface.h" |
donatien | 0:0e0debc29569 | 3 | #include "HTTPClient.h" |
lamadio | 4:b157cc2de561 | 4 | #include "C12832.h" |
lamadio | 4:b157cc2de561 | 5 | #include "picojson.h" |
donatien | 0:0e0debc29569 | 6 | |
donatien | 1:d263603373ac | 7 | EthernetInterface eth; |
donatien | 1:d263603373ac | 8 | HTTPClient http; |
lamadio | 4:b157cc2de561 | 9 | char str[2048]; |
lamadio | 4:b157cc2de561 | 10 | C12832 lcd(p5, p7, p6, p8, p11); |
donatien | 1:d263603373ac | 11 | |
donatien | 0:0e0debc29569 | 12 | int main() |
donatien | 0:0e0debc29569 | 13 | { |
donatien | 0:0e0debc29569 | 14 | eth.init(); //Use DHCP |
donatien | 0:0e0debc29569 | 15 | eth.connect(); |
donatien | 0:0e0debc29569 | 16 | |
donatien | 0:0e0debc29569 | 17 | //GET data |
lamadio | 4:b157cc2de561 | 18 | lcd.printf("\nTrying to fetch page...\n"); |
lamadio | 4:b157cc2de561 | 19 | int ret = http.get("https://dweet.io/get/latest/dweet/for/modern-wheel", str, sizeof(str)); |
donatien | 0:0e0debc29569 | 20 | if (!ret) |
donatien | 0:0e0debc29569 | 21 | { |
lamadio | 4:b157cc2de561 | 22 | //lcd.printf("Page fetched successfully - read %d characters\n", strlen(str)); |
lamadio | 4:b157cc2de561 | 23 | //lcd.printf("Result: %s\n", str); |
lamadio | 4:b157cc2de561 | 24 | picojson::value v; |
lamadio | 4:b157cc2de561 | 25 | const char* start = str; |
lamadio | 4:b157cc2de561 | 26 | const char* end = (const char*)(str + strlen(str)); |
lamadio | 4:b157cc2de561 | 27 | std::string err = picojson::parse(v, start, end); |
lamadio | 4:b157cc2de561 | 28 | if (! err.empty()) |
lamadio | 4:b157cc2de561 | 29 | { |
lamadio | 4:b157cc2de561 | 30 | lcd.printf("Error - %s", err.c_str()); |
lamadio | 4:b157cc2de561 | 31 | } |
donatien | 0:0e0debc29569 | 32 | } |
donatien | 0:0e0debc29569 | 33 | else |
donatien | 0:0e0debc29569 | 34 | { |
lamadio | 4:b157cc2de561 | 35 | lcd.printf("Error - ret = %d - HTTP return code = %d\n", ret, http.getHTTPResponseCode()); |
donatien | 2:270e2d0bb85a | 36 | } |
donatien | 2:270e2d0bb85a | 37 | |
lamadio | 4:b157cc2de561 | 38 | while(1) |
donatien | 2:270e2d0bb85a | 39 | { |
donatien | 2:270e2d0bb85a | 40 | } |
donatien | 0:0e0debc29569 | 41 | eth.disconnect(); |
donatien | 0:0e0debc29569 | 42 | } |