1
- #include " weather.hpp"
2
1
#include " math.h"
3
2
#include < ArduinoJson.h>
4
3
#include < HTTPClient.h>
5
4
#include < WiFiClientSecure.h>
6
5
#include < memory>
7
6
#include < time.h>
7
+ #include " weather.hpp"
8
8
9
9
const char *root_cert =
10
10
" -----BEGIN CERTIFICATE-----\n "
@@ -42,8 +42,39 @@ const char *root_cert =
42
42
" jjxDah2nGN59PRbxYvnKkKj9\n "
43
43
" -----END CERTIFICATE-----\n " ;
44
44
45
- Weather::Weather (double latitude, double longitude)
45
+ Weather::Weather (float latitude, float longitude)
46
+ {
47
+ this ->num_hours = ESPWeatherNumHours;
48
+ this ->user_agent = ESPWeatherUserAgent;
49
+ this ->longitude = longitude;
50
+ this ->latitude = latitude;
51
+ this ->altitude = 0 ;
52
+ this ->local_time = new tm;
53
+ this ->expired_time = new tm;
54
+ this ->temperature = new WeatherData (this ->num_hours );
55
+ this ->dew_point = new WeatherData (this ->num_hours );
56
+ this ->precipitation = new WeatherData (this ->num_hours );
57
+ this ->wind_speeds = new WeatherData (this ->num_hours );
58
+ this ->wind_direction = new WeatherData (this ->num_hours );
59
+ this ->air_pressure = new WeatherData (this ->num_hours );
60
+ this ->cloudiness = new WeatherData (this ->num_hours );
61
+ this ->relative_humidity = new WeatherData (this ->num_hours );
62
+ this ->last_modified = " " ;
63
+ this ->symbol_code_next_1h = " " ;
64
+ this ->symbol_code_next_12h = " " ;
65
+ this ->symbol_code_next_6h = " " ;
66
+ this ->utc_offset = 0 ;
67
+ this ->daylight_saving = false ;
68
+ this ->expired_time ->tm_year = 0 ; // Years since 1900
69
+ this ->expired_time ->tm_mon = 0 ; // Months since January (0-11)
70
+ this ->expired_time ->tm_mday = 0 ; // Day of the month
71
+ this ->expired_time ->tm_hour = 0 ;
72
+ this ->expired_time ->tm_min = 0 ;
73
+ this ->expired_time ->tm_sec = 0 ;
74
+ }
75
+ Weather::Weather (uint8_t num_hours, float latitude, float longitude)
46
76
{
77
+ this ->num_hours = num_hours;
47
78
this ->user_agent = ESPWeatherUserAgent;
48
79
this ->longitude = longitude;
49
80
this ->latitude = latitude;
@@ -64,9 +95,46 @@ Weather::Weather(double latitude, double longitude)
64
95
this ->symbol_code_next_6h = " " ;
65
96
this ->utc_offset = 0 ;
66
97
this ->daylight_saving = false ;
98
+ this ->expired_time ->tm_year = 0 ; // Years since 1900
99
+ this ->expired_time ->tm_mon = 0 ; // Months since January (0-11)
100
+ this ->expired_time ->tm_mday = 0 ; // Day of the month
101
+ this ->expired_time ->tm_hour = 0 ;
102
+ this ->expired_time ->tm_min = 0 ;
103
+ this ->expired_time ->tm_sec = 0 ;
104
+ }
105
+ Weather::Weather (float latitude, float longitude, uint16_t altitude)
106
+ {
107
+ this ->num_hours = ESPWeatherNumHours;
108
+ this ->user_agent = ESPWeatherUserAgent;
109
+ this ->longitude = longitude;
110
+ this ->latitude = latitude;
111
+ this ->altitude = altitude;
112
+ this ->local_time = new tm;
113
+ this ->expired_time = new tm;
114
+ this ->temperature = new WeatherData (this ->num_hours );
115
+ this ->dew_point = new WeatherData (this ->num_hours );
116
+ this ->precipitation = new WeatherData (this ->num_hours );
117
+ this ->wind_speeds = new WeatherData (this ->num_hours );
118
+ this ->wind_direction = new WeatherData (this ->num_hours );
119
+ this ->air_pressure = new WeatherData (this ->num_hours );
120
+ this ->cloudiness = new WeatherData (this ->num_hours );
121
+ this ->relative_humidity = new WeatherData (this ->num_hours );
122
+ this ->last_modified = " " ;
123
+ this ->symbol_code_next_1h = " " ;
124
+ this ->symbol_code_next_12h = " " ;
125
+ this ->symbol_code_next_6h = " " ;
126
+ this ->daylight_saving = false ;
127
+ this ->utc_offset = 0 ;
128
+ this ->expired_time ->tm_year = 0 ; // Years since 1900
129
+ this ->expired_time ->tm_mon = 0 ; // Months since January (0-11)
130
+ this ->expired_time ->tm_mday = 0 ; // Day of the month
131
+ this ->expired_time ->tm_hour = 0 ;
132
+ this ->expired_time ->tm_min = 0 ;
133
+ this ->expired_time ->tm_sec = 0 ;
67
134
}
68
- Weather::Weather (double latitude, double longitude, uint16_t altitude)
135
+ Weather::Weather (uint8_t num_hours, float latitude, float longitude, uint16_t altitude)
69
136
{
137
+ this ->num_hours = num_hours;
70
138
this ->user_agent = ESPWeatherUserAgent;
71
139
this ->longitude = longitude;
72
140
this ->latitude = latitude;
@@ -87,6 +155,12 @@ Weather::Weather(double latitude, double longitude, uint16_t altitude)
87
155
this ->symbol_code_next_6h = " " ;
88
156
this ->daylight_saving = false ;
89
157
this ->utc_offset = 0 ;
158
+ this ->expired_time ->tm_year = 0 ; // Years since 1900
159
+ this ->expired_time ->tm_mon = 0 ; // Months since January (0-11)
160
+ this ->expired_time ->tm_mday = 0 ; // Day of the month
161
+ this ->expired_time ->tm_hour = 0 ;
162
+ this ->expired_time ->tm_min = 0 ;
163
+ this ->expired_time ->tm_sec = 0 ;
90
164
}
91
165
92
166
void Weather::set_daylight_saving (bool daylight_saving)
@@ -113,12 +187,12 @@ Weather::~Weather()
113
187
delete this ->relative_humidity ;
114
188
}
115
189
116
- void Weather::update_location (double latitude, double longitude)
190
+ void Weather::update_location (float latitude, float longitude)
117
191
{
118
192
this ->longitude = longitude;
119
193
this ->latitude = latitude;
120
194
}
121
- void Weather::update_location (double latitude, double longitude,
195
+ void Weather::update_location (float latitude, float longitude,
122
196
uint16_t altitude)
123
197
{
124
198
this ->longitude = longitude;
@@ -225,8 +299,7 @@ void Weather::update_data(void)
225
299
}
226
300
227
301
JsonDocument doc;
228
- DeserializationError error = deserializeJson (
229
- doc, https.getStream (), DeserializationOption::Filter (filter));
302
+ DeserializationError error = deserializeJson (doc, https.getStream (), DeserializationOption::Filter (filter));
230
303
231
304
#ifdef DEBUG_WEATHER
232
305
Serial.println (" Starting deserialization" );
@@ -249,14 +322,14 @@ void Weather::update_data(void)
249
322
return ;
250
323
}
251
324
JsonArray timeseries = doc[" properties" ][" timeseries" ];
252
- double *temps = new double [this ->num_hours + 1 ];
253
- double *precipitation = new double [this ->num_hours + 1 ];
254
- double *wind_speeds = new double [this ->num_hours + 1 ];
255
- double *wind_directions = new double [this ->num_hours + 1 ];
256
- double *air_pressure = new double [this ->num_hours + 1 ];
257
- double *cloudiness = new double [this ->num_hours + 1 ];
258
- double *relative_humidity = new double [this ->num_hours + 1 ];
259
- double *dew_point = new double [this ->num_hours + 1 ];
325
+ float *temps = new float [this ->num_hours + 1 ];
326
+ float *precipitation = new float [this ->num_hours + 1 ];
327
+ float *wind_speeds = new float [this ->num_hours + 1 ];
328
+ float *wind_directions = new float [this ->num_hours + 1 ];
329
+ float *air_pressure = new float [this ->num_hours + 1 ];
330
+ float *cloudiness = new float [this ->num_hours + 1 ];
331
+ float *relative_humidity = new float [this ->num_hours + 1 ];
332
+ float *dew_point = new float [this ->num_hours + 1 ];
260
333
JsonObject current_timeseries_data;
261
334
JsonObject current_timeseries_details;
262
335
JsonObject current_timeseries_next_hour_details;
0 commit comments