Beispiel HTTP GET
Dependencies: EthernetInterface mbed-rtos mbed
Fork of IoTKit_HTTPClient by
main.cpp@0:fb5060c39dd1, 2014-02-02 (annotated)
- Committer:
- WiredHome
- Date:
- Sun Feb 02 18:16:51 2014 +0000
- Revision:
- 0:fb5060c39dd1
- Child:
- 1:2e29a33cd918
Simple demo of HTTPClient
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() { |
WiredHome | 0:fb5060c39dd1 | 14 | pc.baud(460800); |
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 | } |