-
Notifications
You must be signed in to change notification settings - Fork 9
Expand file tree
/
Copy pathopenweathermap.h
More file actions
51 lines (41 loc) · 1.17 KB
/
openweathermap.h
File metadata and controls
51 lines (41 loc) · 1.17 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
/**
* This is a library for the openweathermap.org api, made for spark core (http://spark.io).
*
* It uses the API described at http://openweathermap.org/API
*/
#ifndef _SPARKWEATHER
#define _SPARKWEATHER
#include "application.h"
#include "JsonParser.h"
#include "HttpClient.h"
typedef struct weather_response_t {
long temp_high;
long temp_low;
String descr;
long conditionCode; // see http://openweathermap.org/wiki/API/Weather_Condition_Codes
bool isSuccess;
// defaults:
weather_response_t(): temp_high(255), temp_low(255), conditionCode(-1), isSuccess(false) {};
} weather_response_t;
class Weather {
public:
Weather(String location, HttpClient* client, String apiKey);
bool update(weather_response_t& response);
void setCelsius();
void setFahrenheit();
// for cache:
weather_response_t cachedUpdate();
private:
ArduinoJson::Parser::JsonParser<70> parser; // occupies 70 * 4 bytes
http_request_t request;
String location;
String apiKey;
String unitsForTemperature;
HttpClient* client;
bool parse(String& json, weather_response_t& response);
// cache:
unsigned long weather_sync_interval;
unsigned long lastsync;
weather_response_t lastReponse;
};
#endif