Beispiel Abfrage Cloud Dienst Sunrise / Sunset

Dependencies:   EthernetInterface MbedJSONValue mbed-rtos mbed

Fork of HTTP_GET by smd.iotkit2.ch

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"}
Revision:
3:aad64a4b6ff6
Parent:
2:c9e058ee6f87
Child:
5:cfe277d00d6b
--- a/main.cpp	Mon Jan 19 10:39:52 2015 +0000
+++ b/main.cpp	Wed Mar 11 13:01:58 2015 +0000
@@ -1,33 +1,27 @@
-/** Beispiel fuer Verwendung der HTTP Methoden (GET, POST, PUT, DELETE)
- *
- * Braucht ein Board mit Ethernet
+/** Beispiel HTTP GET
  */
 #include "mbed.h"
 #include "HTTPClient.h"
 #include "HTTPText.h"
 #include "EthernetInterface.h"
 
-Serial pc(USBTX, USBRX);
-
 EthernetInterface eth;
+// HTTPClient Hilfsklasse
 HTTPClient http;
+// I/O Buffer
 char message[6000];
-char str[512];
 
 DigitalOut myled(LED1);
 
 int main()
 {
-    pc.baud(9600);
-    printf("HTTP Client - Build " __DATE__ " - " __TIME__ "\r\n");
+    printf("HTTP Client - GET\n");
     eth.init();
     eth.connect();
 
     while(1) 
     {
         myled = 1;
-        printf( "GET http://developer.mbed.org/media/uploads/mbed_official/hello.txt\n" );
-        //int ret = http.get("https://raw.githubusercontent.com/mc-b/microHOME/master/README.md", message, sizeof(message));
         int ret = http.get("http://developer.mbed.org/media/uploads/mbed_official/hello.txt", message, sizeof(message));
         if ( !ret ) 
         {
@@ -39,48 +33,7 @@
         
         myled = 0;
 
-        //POST data
-        HTTPMap map;
-        HTTPText inText(str, 512);
-        map.put("Hello", "World");
-        map.put("test", "1234");
-        printf("\nTrying to post data...\n");
-        ret = http.post("http://httpbin.org/post", map, &inText);
-        if ( ! ret ) 
-        {
-            printf("Executed POST successfully - read %d characters\n", strlen(str));
-            printf("Result: %s\n", str);
-        } 
-        else 
-        {
-            printf("Error - ret = %d - HTTP return code = %d\n", ret, http.getHTTPResponseCode());
-        }
-
-        //PUT data
-        strcpy(str, "This is a PUT test!");
-        HTTPText outText(str);
-        //HTTPText inText(str, 512);
-        printf("\nTrying to put resource...\n");
-        ret = http.put("http://httpbin.org/put", outText, &inText);
-        if (!ret) {
-            printf("Executed PUT successfully - read %d characters\n", strlen(str));
-            printf("Result: %s\n", str);
-        } else {
-            printf("Error - ret = %d - HTTP return code = %d\n", ret, http.getHTTPResponseCode());
-        }
-
-        //DELETE data
-        //HTTPText inText(str, 512);
-        printf("\nTrying to delete resource...\n");
-        ret = http.del("http://httpbin.org/delete", &inText);
-        if (!ret) {
-            printf("Executed DELETE successfully - read %d characters\n", strlen(str));
-            printf("Result: %s\n", str);
-        } else {
-            printf("Error - ret = %d - HTTP return code = %d\n", ret, http.getHTTPResponseCode());
-        }
-
         wait(10);
     }
-    // eth.disconnect();
+    eth.disconnect();
 }