![](/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@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 | } |