-
Notifications
You must be signed in to change notification settings - Fork 1
/
weather.h
40 lines (33 loc) · 1.7 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
struct Weather {
char iconH1[10];
char tempH1[10];
char feelsLikeH1[10];
char humidityH1[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];
};
void fillWeatherFromJson(Weather* weather) {
sprintf(weather->iconH1, "%s", (const char*) weatherJson["hourly"][1]["weather"][0]["icon"]);
sprintf(weather->tempH1, "%2i\xb0", (int) round((double) weatherJson["hourly"][1]["temp"]));
sprintf(weather->feelsLikeH1, "%2i\xb0", (int) round((double) weatherJson["hourly"][1]["feels_like"]));
sprintf(weather->humidityH1, "%3i %%", (int) weatherJson["hourly"][1]["humidity"]);
sprintf(weather->iconD, "%s", (const char*) weatherJson["daily"][0]["weather"][0]["icon"]);
sprintf(weather->tempMinD, "%2i\xb0", (int) round((double) weatherJson["daily"][0]["temp"]["min"]));
sprintf(weather->tempMaxD, "%2i\xb0", (int) round((double) weatherJson["daily"][0]["temp"]["max"]));
sprintf(weather->humidityD, "%3i %%", (int) weatherJson["daily"][0]["humidity"]);
sprintf(weather->iconD1, "%s", (const char*) weatherJson["daily"][1]["weather"][0]["icon"]);
sprintf(weather->tempMinD1, "%2i\xb0", (int) round((double) weatherJson["daily"][1]["temp"]["min"]));
sprintf(weather->tempMaxD1, "%2i\xb0", (int) round((double) weatherJson["daily"][1]["temp"]["max"]));
sprintf(weather->humidityD1, "%3i %%", (int) weatherJson["daily"][1]["humidity"]);
int timezone_offset = (int) weatherJson["timezone_offset"];
int dt = (int) weatherJson["current"]["dt"];
int t = dt + timezone_offset;
sprintf(weather->updated, "MAJ : %02d/%02d %02d:%02d", day(t), month(t), hour(t), minute(t));
}