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"}
Committer:
stefan1691
Date:
Wed May 27 16:08:21 2015 +0000
Revision:
5:cfe277d00d6b
Parent:
1:2e29a33cd918
Beispiel Abfrage Cloud Dienst Sunrise / Sunset

Who changed what in which revision?

UserRevisionLine numberNew contents of line
marcel1691 1:2e29a33cd918 1 #ifndef HTTPFILE_H
marcel1691 1:2e29a33cd918 2 #define HTTPFILE_H
marcel1691 1:2e29a33cd918 3 #if 1
marcel1691 1:2e29a33cd918 4 #include <mbed.h>
marcel1691 1:2e29a33cd918 5 #include "../IHTTPData.h"
marcel1691 1:2e29a33cd918 6
marcel1691 1:2e29a33cd918 7
marcel1691 1:2e29a33cd918 8 class HTTPFile : public IHTTPDataIn {
marcel1691 1:2e29a33cd918 9
marcel1691 1:2e29a33cd918 10 public:
marcel1691 1:2e29a33cd918 11 HTTPFile(char* filename);
marcel1691 1:2e29a33cd918 12
marcel1691 1:2e29a33cd918 13 /** Closes the file, should be called once the http connection is closed.
marcel1691 1:2e29a33cd918 14 */
marcel1691 1:2e29a33cd918 15 void close();
marcel1691 1:2e29a33cd918 16
marcel1691 1:2e29a33cd918 17 protected:
marcel1691 1:2e29a33cd918 18
marcel1691 1:2e29a33cd918 19 friend class HTTPClient;
marcel1691 1:2e29a33cd918 20
marcel1691 1:2e29a33cd918 21 /** Reset stream to its beginning
marcel1691 1:2e29a33cd918 22 * Called by the HTTPClient on each new request
marcel1691 1:2e29a33cd918 23 */
marcel1691 1:2e29a33cd918 24 virtual void writeReset();
marcel1691 1:2e29a33cd918 25
marcel1691 1:2e29a33cd918 26 /** Write a piece of data transmitted by the server
marcel1691 1:2e29a33cd918 27 * @param[in] buf Pointer to the buffer from which to copy the data
marcel1691 1:2e29a33cd918 28 * @param[in] len Length of the buffer
marcel1691 1:2e29a33cd918 29 * @returns number of bytes written.
marcel1691 1:2e29a33cd918 30 */
marcel1691 1:2e29a33cd918 31 virtual int write(const char* buf, size_t len);
marcel1691 1:2e29a33cd918 32
marcel1691 1:2e29a33cd918 33 /** Set MIME type
marcel1691 1:2e29a33cd918 34 * @param[in] type Internet media type from Content-Type header
marcel1691 1:2e29a33cd918 35 */
marcel1691 1:2e29a33cd918 36 virtual void setDataType(const char* type);
marcel1691 1:2e29a33cd918 37
marcel1691 1:2e29a33cd918 38 /** Determine whether the data is chunked
marcel1691 1:2e29a33cd918 39 * Recovered from Transfer-Encoding header
marcel1691 1:2e29a33cd918 40 * @param[in] chunked indicates the transfer is chunked.
marcel1691 1:2e29a33cd918 41 */
marcel1691 1:2e29a33cd918 42 virtual void setIsChunked(bool chunked);
marcel1691 1:2e29a33cd918 43
marcel1691 1:2e29a33cd918 44 /** If the data is not chunked, set its size
marcel1691 1:2e29a33cd918 45 * From Content-Length header
marcel1691 1:2e29a33cd918 46 * @param[in] len defines the size of the non-chunked transfer.
marcel1691 1:2e29a33cd918 47 */
marcel1691 1:2e29a33cd918 48 virtual void setDataLen(size_t len);
marcel1691 1:2e29a33cd918 49 private:
marcel1691 1:2e29a33cd918 50 FILE *file;
marcel1691 1:2e29a33cd918 51 size_t m_len;
marcel1691 1:2e29a33cd918 52 bool m_chunked;
marcel1691 1:2e29a33cd918 53 };
marcel1691 1:2e29a33cd918 54 #endif
marcel1691 1:2e29a33cd918 55 #endif // HTTPFILE_H