-
Notifications
You must be signed in to change notification settings - Fork 1
/
weather.h
51 lines (42 loc) · 1.75 KB
/
weather.h
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
struct Weather {
char iconH[10];
char tempH[10];
char feelsLikeH[10];
char humidityH[6];
char iconD[10];
char tempMinD[10];
char tempMaxD[10];
char humidityD[6];
char iconD1[10];
char tempMinD1[10];
char tempMaxD1[10];
char humidityD1[6];
char updated[20];
};
struct Location {
char town[30];
char url[200];
uint16_t count;
Weather weather;
};
void fillWeatherFromJson(Weather* weather) {
int tempH = (int) round(json["current"]["temp"]);
int feelsLikeH = (int) round(json["current"]["feels_like"]);
boolean tempHLower = tempH < feelsLikeH;
sprintf(weather->iconH, "%s", (const char*) json["current"]["weather"][0]["icon"]);
sprintf(weather->tempH, "%2i C", tempHLower ? tempH : feelsLikeH);
sprintf(weather->feelsLikeH, "%2i C", tempHLower ? feelsLikeH : tempH);
sprintf(weather->humidityH, "%3i %%", (int) json["current"]["humidity"]);
sprintf(weather->iconD, "%s", (const char*) json["daily"][0]["weather"][0]["icon"]);
sprintf(weather->tempMinD, "%2i C", (int) round(json["daily"][0]["temp"]["min"]));
sprintf(weather->tempMaxD, "%2i C", (int) round(json["daily"][0]["temp"]["max"]));
sprintf(weather->humidityD, "%3i %%", (int) json["daily"][0]["humidity"]);
sprintf(weather->iconD1, "%s", (const char*) json["daily"][1]["weather"][0]["icon"]);
sprintf(weather->tempMinD1, "%2i C", (int) round(json["daily"][1]["temp"]["min"]));
sprintf(weather->tempMaxD1, "%2i C", (int) round(json["daily"][1]["temp"]["max"]));
sprintf(weather->humidityD1, "%3i %%", (int) json["daily"][1]["humidity"]);
int timezone_offset = (int) json["timezone_offset"];
int dt = (int) json["current"]["dt"];
int t = dt + timezone_offset;
sprintf(weather->updated, "MAJ : %02d/%02d %02d:%02d", day(t), month(t), hour(t), minute(t));
}