![](/media/cache/group/ep_srxDLMd.webp.50x50_q85.jpg)
10.1 Kombiniert die Übung 6.4 Wenn sich jemand nähert, Lauflicht einschalten mit dem Yahoo Weather Dienst, dass bei Unterwarnungen das Lauflicht eingeschaltet wird.
Dependencies: EthernetInterface mbed-rtos mbed spxml
Fork of YahooWeather by
main.cpp@3:aad64a4b6ff6, 2015-03-11 (annotated)
- Committer:
- stefan1691
- Date:
- Wed Mar 11 13:01:58 2015 +0000
- Revision:
- 3:aad64a4b6ff6
- Parent:
- 2:c9e058ee6f87
- Child:
- 5:f81113cbe930
Beispiel HTTP GET
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
stefan1691 | 3:aad64a4b6ff6 | 1 | /** Beispiel HTTP GET |
marcel1691 | 1:2e29a33cd918 | 2 | */ |
WiredHome | 0:fb5060c39dd1 | 3 | #include "mbed.h" |
WiredHome | 0:fb5060c39dd1 | 4 | #include "HTTPClient.h" |
marcel1691 | 1:2e29a33cd918 | 5 | #include "HTTPText.h" |
WiredHome | 0:fb5060c39dd1 | 6 | #include "EthernetInterface.h" |
WiredHome | 0:fb5060c39dd1 | 7 | |
WiredHome | 0:fb5060c39dd1 | 8 | EthernetInterface eth; |
stefan1691 | 3:aad64a4b6ff6 | 9 | // HTTPClient Hilfsklasse |
WiredHome | 0:fb5060c39dd1 | 10 | HTTPClient http; |
stefan1691 | 3:aad64a4b6ff6 | 11 | // I/O Buffer |
marcel1691 | 1:2e29a33cd918 | 12 | char message[6000]; |
WiredHome | 0:fb5060c39dd1 | 13 | |
WiredHome | 0:fb5060c39dd1 | 14 | DigitalOut myled(LED1); |
WiredHome | 0:fb5060c39dd1 | 15 | |
marcel1691 | 1:2e29a33cd918 | 16 | int main() |
marcel1691 | 1:2e29a33cd918 | 17 | { |
stefan1691 | 3:aad64a4b6ff6 | 18 | printf("HTTP Client - GET\n"); |
WiredHome | 0:fb5060c39dd1 | 19 | eth.init(); |
WiredHome | 0:fb5060c39dd1 | 20 | eth.connect(); |
WiredHome | 0:fb5060c39dd1 | 21 | |
marcel1691 | 1:2e29a33cd918 | 22 | while(1) |
marcel1691 | 1:2e29a33cd918 | 23 | { |
WiredHome | 0:fb5060c39dd1 | 24 | myled = 1; |
marcel1691 | 1:2e29a33cd918 | 25 | int ret = http.get("http://developer.mbed.org/media/uploads/mbed_official/hello.txt", message, sizeof(message)); |
marcel1691 | 1:2e29a33cd918 | 26 | if ( !ret ) |
marcel1691 | 1:2e29a33cd918 | 27 | { |
WiredHome | 0:fb5060c39dd1 | 28 | printf("Success - read %d characters.\r\n", strlen(message)); |
WiredHome | 0:fb5060c39dd1 | 29 | printf("%s\r\n", message); |
WiredHome | 0:fb5060c39dd1 | 30 | } |
marcel1691 | 1:2e29a33cd918 | 31 | else |
marcel1691 | 1:2e29a33cd918 | 32 | printf("Error - ret = %d - HTTP return code = %d\n", ret, http.getHTTPResponseCode()); |
marcel1691 | 1:2e29a33cd918 | 33 | |
WiredHome | 0:fb5060c39dd1 | 34 | myled = 0; |
marcel1691 | 1:2e29a33cd918 | 35 | |
WiredHome | 0:fb5060c39dd1 | 36 | wait(10); |
WiredHome | 0:fb5060c39dd1 | 37 | } |
stefan1691 | 3:aad64a4b6ff6 | 38 | eth.disconnect(); |
WiredHome | 0:fb5060c39dd1 | 39 | } |