Working
Dependencies: EthernetInterface HTTPClient mbed-rtos mbed
Fork of Sample_HTTPClient by
main.cpp@1:e2d91c62f2b4, 2014-05-21 (annotated)
- Committer:
- bhakti08
- Date:
- Wed May 21 04:07:24 2014 +0000
- Revision:
- 1:e2d91c62f2b4
- Parent:
- 0:fb5060c39dd1
Sample HTTP Client
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
WiredHome | 0:fb5060c39dd1 | 1 | #include "mbed.h" |
WiredHome | 0:fb5060c39dd1 | 2 | #include "HTTPClient.h" |
WiredHome | 0:fb5060c39dd1 | 3 | #include "EthernetInterface.h" |
WiredHome | 0:fb5060c39dd1 | 4 | |
WiredHome | 0:fb5060c39dd1 | 5 | Serial pc(USBTX, USBRX); |
WiredHome | 0:fb5060c39dd1 | 6 | |
WiredHome | 0:fb5060c39dd1 | 7 | EthernetInterface eth; |
WiredHome | 0:fb5060c39dd1 | 8 | HTTPClient http; |
WiredHome | 0:fb5060c39dd1 | 9 | char message[2000]; |
WiredHome | 0:fb5060c39dd1 | 10 | |
WiredHome | 0:fb5060c39dd1 | 11 | DigitalOut myled(LED1); |
WiredHome | 0:fb5060c39dd1 | 12 | |
WiredHome | 0:fb5060c39dd1 | 13 | int main() { |
bhakti08 | 1:e2d91c62f2b4 | 14 | pc.baud(9600); |
WiredHome | 0:fb5060c39dd1 | 15 | printf("HTTP Client - Build " __DATE__ " - " __TIME__ "\r\n"); |
WiredHome | 0:fb5060c39dd1 | 16 | eth.init(); |
WiredHome | 0:fb5060c39dd1 | 17 | eth.connect(); |
WiredHome | 0:fb5060c39dd1 | 18 | |
WiredHome | 0:fb5060c39dd1 | 19 | while(1) { |
WiredHome | 0:fb5060c39dd1 | 20 | myled = 1; |
WiredHome | 0:fb5060c39dd1 | 21 | int ret = http.get("http://mbed.org/media/uploads/mbed_official/hello.txt", message, sizeof(message)); |
WiredHome | 0:fb5060c39dd1 | 22 | if (!ret) { |
WiredHome | 0:fb5060c39dd1 | 23 | printf("Success - read %d characters.\r\n", strlen(message)); |
WiredHome | 0:fb5060c39dd1 | 24 | printf("%s\r\n", message); |
WiredHome | 0:fb5060c39dd1 | 25 | } |
WiredHome | 0:fb5060c39dd1 | 26 | myled = 0; |
WiredHome | 0:fb5060c39dd1 | 27 | wait(10); |
WiredHome | 0:fb5060c39dd1 | 28 | } |
WiredHome | 0:fb5060c39dd1 | 29 | // eth.disconnect(); |
WiredHome | 0:fb5060c39dd1 | 30 | } |