GR-peach example of Dropbox shared link access
Dependencies: HTTPClient mbed-rtos-initial-thread-larger-stack mbed-src
Fork of GR-peach-HTTPSClient by
main.cpp@1:2744673f6256, 2014-12-05 (annotated)
- Committer:
- takashikojo
- Date:
- Fri Dec 05 11:42:02 2014 +0000
- Revision:
- 1:2744673f6256
- Parent:
- 0:83075160de0e
Dropbox Shared Link access example, Initial version
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
takashikojo | 0:83075160de0e | 1 | #include "mbed.h" |
takashikojo | 0:83075160de0e | 2 | #include "EthernetInterface.h" |
takashikojo | 0:83075160de0e | 3 | #include "HTTPClient.h" |
takashikojo | 0:83075160de0e | 4 | |
takashikojo | 1:2744673f6256 | 5 | #define SHARED_LINK "https://www.dropbox.com/s/m856g2irwzb68uv/test.txt?dl=0" |
takashikojo | 1:2744673f6256 | 6 | |
takashikojo | 1:2744673f6256 | 7 | extern HTTPResult dropbox_get(const char *url, char *buff, int size) ; |
takashikojo | 0:83075160de0e | 8 | |
takashikojo | 0:83075160de0e | 9 | EthernetInterface eth; |
takashikojo | 0:83075160de0e | 10 | HTTPClient http; |
takashikojo | 0:83075160de0e | 11 | char recvBuff[1024*20]; |
takashikojo | 0:83075160de0e | 12 | |
takashikojo | 0:83075160de0e | 13 | int main() |
takashikojo | 0:83075160de0e | 14 | { |
takashikojo | 1:2744673f6256 | 15 | HTTPResult ret ; |
takashikojo | 0:83075160de0e | 16 | |
takashikojo | 1:2744673f6256 | 17 | printf("Dropbox Shared Link, Starting,...\n") ; |
takashikojo | 0:83075160de0e | 18 | |
takashikojo | 0:83075160de0e | 19 | eth.init(); //Use DHCP |
takashikojo | 0:83075160de0e | 20 | while(1) { |
takashikojo | 0:83075160de0e | 21 | printf("Trying\n") ; |
takashikojo | 1:2744673f6256 | 22 | if(eth.connect() == 0)break ; |
takashikojo | 0:83075160de0e | 23 | } |
takashikojo | 0:83075160de0e | 24 | printf("HTTP Client, IP Address is %s\n", eth.getIPAddress()); |
takashikojo | 0:83075160de0e | 25 | |
takashikojo | 0:83075160de0e | 26 | |
takashikojo | 1:2744673f6256 | 27 | printf("Shared Link: %s\n", SHARED_LINK); |
takashikojo | 1:2744673f6256 | 28 | memset(recvBuff, '\0', sizeof(recvBuff)) ; |
takashikojo | 1:2744673f6256 | 29 | ret = dropbox_get(SHARED_LINK, recvBuff, sizeof(recvBuff)); |
takashikojo | 1:2744673f6256 | 30 | if (ret == HTTP_OK) { |
takashikojo | 1:2744673f6256 | 31 | printf("Result: %s\n", recvBuff); |
takashikojo | 1:2744673f6256 | 32 | } else { |
takashikojo | 1:2744673f6256 | 33 | printf("Error - ret = %d - HTTP return code = %d\n", ret, http.getHTTPResponseCode()); |
takashikojo | 0:83075160de0e | 34 | } |
takashikojo | 0:83075160de0e | 35 | |
takashikojo | 0:83075160de0e | 36 | eth.disconnect(); |
takashikojo | 0:83075160de0e | 37 | |
takashikojo | 0:83075160de0e | 38 | while(1) { |
takashikojo | 0:83075160de0e | 39 | } |
takashikojo | 0:83075160de0e | 40 | } |