@@ -32,13 +32,13 @@ OpenWeatherMapForecast::OpenWeatherMapForecast() {
3232
3333}
3434
35- void OpenWeatherMapForecast::updateForecasts (OpenWeatherMapForecastData *data, String appId, String location, uint8_t maxForecasts) {
35+ uint8_t OpenWeatherMapForecast::updateForecasts (OpenWeatherMapForecastData *data, String appId, String location, uint8_t maxForecasts) {
3636 String units = metric ? " metric" : " imperial" ;
3737 this ->maxForecasts = maxForecasts;
38- doUpdate (data, " http://api.openweathermap.org/data/2.5/forecast?q=" + location + " &appid=" + appId + " &units=" + units + " &lang=" + language);
38+ return doUpdate (data, " http://api.openweathermap.org/data/2.5/forecast?q=" + location + " &appid=" + appId + " &units=" + units + " &lang=" + language);
3939}
4040
41- void OpenWeatherMapForecast::doUpdate (OpenWeatherMapForecastData *data, String url) {
41+ uint8_t OpenWeatherMapForecast::doUpdate (OpenWeatherMapForecastData *data, String url) {
4242 unsigned long lostTest = 10000UL ;
4343 unsigned long lost_do = millis ();
4444 this ->weatherItemCounter = 0 ;
@@ -80,6 +80,7 @@ void OpenWeatherMapForecast::doUpdate(OpenWeatherMapForecastData *data, String u
8080 }
8181 }
8282 this ->data = nullptr ;
83+ return currentForecast;
8384}
8485
8586void OpenWeatherMapForecast::whitespace (char c) {
@@ -101,11 +102,31 @@ void OpenWeatherMapForecast::value(String value) {
101102 // {"dt":1527066000, uint32_t observationTime;
102103 if (currentKey == " dt" ) {
103104 data[currentForecast].observationTime = value.toInt ();
105+
106+ if (allowedHoursCount > 0 ) {
107+ time_t time = data[currentForecast].observationTime ;
108+ struct tm * timeInfo;
109+ timeInfo = localtime (&time);
110+ uint8_t currentHour = timeInfo->tm_hour ;
111+ for (uint8_t i = 0 ; i < allowedHoursCount; i++) {
112+ if (currentHour == allowedHours[i]) {
113+ isCurrentForecastAllowed = true ;
114+ return ;
115+ }
116+ }
117+ isCurrentForecastAllowed = false ;
118+ return ;
119+ }
120+ }
121+ if (!isCurrentForecastAllowed) {
122+ return ;
104123 }
105124 // "main":{
106125 // "temp":17.35, float temp;
107126 if (currentKey == " temp" ) {
108127 data[currentForecast].temp = value.toFloat ();
128+ // initialize potentially empty values:
129+ data[currentForecast].rain = 0 ;;
109130 }
110131 // "temp_min":16.89, float tempMin;
111132 if (currentKey == " temp_min" ) {
@@ -167,6 +188,10 @@ void OpenWeatherMapForecast::value(String value) {
167188 if (currentKey == " deg" ) {
168189 data[currentForecast].windDeg = value.toFloat ();
169190 }
191+ // rain: {3h: 0.055}, float rain;
192+ if (currentKey == " 3h" ) {
193+ data[currentForecast].rain = value.toFloat ();
194+ }
170195 // },"sys":{"pod":"d"}
171196 // dt_txt: "2018-05-23 09:00:00" String observationTimeText;
172197 if (currentKey == " dt_txt" ) {
0 commit comments