![](/media/cache/group/ep_srxDLMd.webp.50x50_q85.jpg)
Beispiel Abfrage Cloud Dienst Sunrise / Sunset
Dependencies: EthernetInterface MbedJSONValue mbed-rtos mbed
Fork of HTTP_GET by
Sunrise Sunset stellt ein API zur Verfügung, mittels dem die Sonnen Auf- und Untergangszeiten für einen bestimmten Ort abgefragt werden können.
Links
Beispiel: Abfrage für Zürich
http://api.sunrise-sunset.org/json?lat=47.3686498&lng=8.5391825
{"results": { "sunrise":"5:38:12 AM", "sunset":"5:31:12 PM", "solar_noon":"11:34:42 AM", "day_length":"11:53:00", "civil_twilight_begin":"5:07:47 AM", "civil_twilight_end":"6:01:38 PM", "nautical_twilight_begin":"4:32:04 AM", "nautical_twilight_end":"6:37:21 PM", "astronomical_twilight_begin":"3:55:32 AM", "astronomical_twilight_end":"7:13:52 PM" }, "status":"OK"}
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:cfe277d00d6b
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 | } |