Skip to content

Commit 4846192

Browse files
author
Tobias
committed
- Wunderground.getDate() now returns the actual locale date (key "local_time_rfc822") and not longer the observation time
- Observation time is now delivered by Wunderground.getObservationDate()
1 parent 5eb3c3e commit 4846192

File tree

2 files changed

+48
-39
lines changed

2 files changed

+48
-39
lines changed

WundergroundClient.cpp

Lines changed: 30 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -169,7 +169,7 @@ void WundergroundClient::key(String key) {
169169
isForecast = false;
170170
isAlerts = true;
171171
}
172-
// end fowlerk add
172+
// end fowlerk add
173173
}
174174

175175
void WundergroundClient::value(String value) {
@@ -247,7 +247,7 @@ void WundergroundClient::value(String value) {
247247
else isPM = false;
248248
char tempHourBuff[3] = ""; // fowlerk add for formatting, 12/22/16
249249
sprintf(tempHourBuff, "%2d", tempHour); // fowlerk add for formatting, 12/22/16
250-
moonriseTime = String(tempHourBuff); // fowlerk add for formatting, 12/22/16
250+
moonriseTime = String(tempHourBuff); // fowlerk add for formatting, 12/22/16
251251
// moonriseTime = value;
252252
}
253253
if (currentKey == "minute") {
@@ -263,7 +263,7 @@ void WundergroundClient::value(String value) {
263263
if (currentKey == "hour") {
264264
char tempHourBuff[3] = ""; // fowlerk add for formatting, 12/22/16
265265
sprintf(tempHourBuff, "%2d", value.toInt()); // fowlerk add for formatting, 12/22/16
266-
moonsetTime = String(tempHourBuff); // fowlerk add for formatting, 12/22/16
266+
moonsetTime = String(tempHourBuff); // fowlerk add for formatting, 12/22/16
267267
}
268268
if (currentKey == "minute") {
269269
char tempMinBuff[3] = ""; // fowlerk add for formatting, 12/22/16
@@ -275,7 +275,7 @@ void WundergroundClient::value(String value) {
275275
if (currentKey == "wind_mph" && !isMetric) {
276276
windSpeed = value + "mph";
277277
}
278-
278+
279279
if (currentKey == "wind_kph" && isMetric) {
280280
windSpeed = value + "km/h";
281281
}
@@ -286,15 +286,19 @@ void WundergroundClient::value(String value) {
286286

287287
// end JJG add ////////////////////////////////////////////////////////////////////
288288

289-
if (currentKey == "observation_time_rfc822") {
289+
if (currentKey == "local_time_rfc822") {
290290
date = value.substring(0, 16);
291291
}
292-
// Begin add, fowlerk...04-Dec-2016
292+
293+
if (currentKey == "observation_time_rfc822") {
294+
observationDate = value.substring(0, 16);
295+
}
296+
// Begin add, fowlerk...04-Dec-2016
293297
if (currentKey == "observation_time") {
294298
observationTime = value;
295299
}
296-
// end add, fowlerk
297-
300+
// end add, fowlerk
301+
298302
if (currentKey == "temp_f" && !isMetric) {
299303
currentTemp = value;
300304
}
@@ -327,15 +331,15 @@ void WundergroundClient::value(String value) {
327331
if (currentKey == "feelslike_f" && !isMetric) {
328332
feelslike = value;
329333
}
330-
334+
331335
if (currentKey == "feelslike_c" && isMetric) {
332336
feelslike = value;
333337
}
334-
338+
335339
if (currentKey == "UV") {
336340
UV = value;
337341
}
338-
342+
339343
// Active alerts...added 18-Dec-2016
340344
if (currentKey == "type" && isAlerts) {
341345
activeAlertsCnt++;
@@ -399,9 +403,9 @@ void WundergroundClient::value(String value) {
399403
activeAlertsAttribution[currentAlert-1].replace("</a>","");
400404
activeAlertsAttribution[currentAlert-1].replace("/'>"," ");
401405
}
402-
406+
403407
// end fowlerk add
404-
408+
405409
if (currentKey == "dewpoint_f" && !isMetric) {
406410
dewPoint = value;
407411
}
@@ -420,7 +424,7 @@ void WundergroundClient::value(String value) {
420424
// Modified below line to add check to ensure we are processing the 10-day forecast
421425
// before setting the forecastTitle (day of week of the current forecast day).
422426
// (The keyword title is used in both the current observation and the 10-day forecast.)
423-
// Modified by fowlerk
427+
// Modified by fowlerk
424428
// if (currentKey == "title" && currentForecastPeriod < MAX_FORECAST_PERIODS) { // Removed, fowlerk
425429
if (currentKey == "title" && isForecast && currentForecastPeriod < MAX_FORECAST_PERIODS) {
426430
Serial.println(String(currentForecastPeriod) + ": " + value);
@@ -436,13 +440,13 @@ void WundergroundClient::value(String value) {
436440
forecastText[currentForecastPeriod] = value;
437441
}
438442
// end fowlerk add, 12/3/16
439-
443+
440444
// Added PoP (probability of precipitation) key following...fowlerk, 12/22/16
441445
if (currentKey == "pop" && isForecast && currentForecastPeriod < MAX_FORECAST_PERIODS) {
442446
PoP[currentForecastPeriod] = value;
443447
}
444448
// end fowlerk add, 12/22/16
445-
449+
446450
// The detailed forecast period has only one forecast per day with low/high for both
447451
// night and day, starting at index 1.
448452
int dailyForecastPeriod = (currentForecastPeriod - 1) * 2;
@@ -475,19 +479,19 @@ void WundergroundClient::value(String value) {
475479
currentForecastPeriod = 0;
476480
}
477481
forecastMonth[currentForecastPeriod] = value;
478-
}
482+
}
479483

480484
if (currentKey == "day" && isSimpleForecast && currentForecastPeriod < MAX_FORECAST_PERIODS) {
481485
// Added by fowlerk to handle transition from txtforecast to simpleforecast, as
482486
// the key "period" doesn't appear until after some of the key values needed and is
483487
// used as an array index.
484488
if (isSimpleForecast && currentForecastPeriod == 19) {
485489
currentForecastPeriod = 0;
486-
}
490+
}
487491
forecastDay[currentForecastPeriod] = value;
488492
}
489493
// end fowlerk add
490-
494+
491495
}
492496

493497
void WundergroundClient::endArray() {
@@ -548,6 +552,9 @@ String WundergroundClient::getSeconds() {
548552
String WundergroundClient::getDate() {
549553
return date;
550554
}
555+
String WundergroundClient::getObservationDate() {
556+
return observationDate;
557+
}
551558
long WundergroundClient::getCurrentEpoch() {
552559
return localEpoc + ((millis() - localMillisAtUpdate) / 1000);
553560
}
@@ -698,17 +705,17 @@ String WundergroundClient::getForecastHighTemp(int period) {
698705
}
699706
// fowlerk added...
700707
String WundergroundClient::getForecastDay(int period) {
701-
// Serial.print("Day period: "); Serial.println(period);
708+
// Serial.print("Day period: "); Serial.println(period);
702709
return forecastDay[period];
703710
}
704711

705712
String WundergroundClient::getForecastMonth(int period) {
706-
// Serial.print("Month period: "); Serial.println(period);
713+
// Serial.print("Month period: "); Serial.println(period);
707714
return forecastMonth[period];
708715
}
709716

710717
String WundergroundClient::getForecastText(int period) {
711-
// Serial.print("Forecast period: "); Serial.println(period);
718+
// Serial.print("Forecast period: "); Serial.println(period);
712719
return forecastText[period];
713720
}
714721

@@ -761,4 +768,4 @@ String WundergroundClient::getMeteoconIcon(String iconText) {
761768
if (iconText == "nt_tstorms") return "&";
762769

763770
return ")";
764-
}
771+
}

WundergroundClient.h

Lines changed: 18 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@ class WundergroundClient: public JsonListener {
4141
int gmtOffset = 1;
4242
long localMillisAtUpdate;
4343
String date = "-";
44+
String observationDate = "-";
4445
boolean isMetric = true;
4546
String currentTemp;
4647
// JJG added ... ////////////////////////////////// define returns /////////////////////////////////
@@ -65,7 +66,7 @@ class WundergroundClient: public JsonListener {
6566
String UV;
6667
String observationTime; // fowlerk add, 04-Dec-2016
6768
// end fowlerk add
68-
69+
6970
void doUpdate(String url);
7071

7172
// forecast
@@ -107,12 +108,13 @@ class WundergroundClient: public JsonListener {
107108
void updateAstronomy(String apiKey, String language, String country, String city);
108109
void updateAlerts(String apiKey, String language, String country, String city); // Added by fowlerk, 18-Dec-2016
109110
void initMetric(boolean isMetric); // Added by fowlerk, 12/22/16, as an option to change metric setting other than at instantiation
110-
111+
111112
// JJG added
112113
String getHours();
113114
String getMinutes();
114115
String getSeconds();
115116
String getDate();
117+
String getObservationDate();
116118
// JJG added ... ///////////////////function name to string ////////////////////////////
117119
String getMoonPctIlum();
118120
String getMoonAge();
@@ -145,9 +147,9 @@ class WundergroundClient: public JsonListener {
145147
String getPrecipitationToday();
146148
// fowlerk added...
147149
String getFeelsLike();
148-
150+
149151
String getUV();
150-
152+
151153
String getObservationTime(); // fowlerk add, 04-Dec-2016
152154
// end fowlerk add
153155

@@ -160,33 +162,33 @@ class WundergroundClient: public JsonListener {
160162
String getForecastHighTemp(int period);
161163
// fowlerk added...
162164
String getForecastDay(int period);
163-
165+
164166
String getForecastMonth(int period);
165-
167+
166168
String getForecastText(int period);
167-
169+
168170
String getPoP(int period);
169-
171+
170172
int getActiveAlertsCnt();
171-
173+
172174
String getActiveAlerts(int alertIndex);
173-
175+
174176
String getActiveAlertsText(int alertIndex);
175-
177+
176178
String getActiveAlertsMessage(int alertIndex);
177179

178180
bool getActiveAlertsMessageTrunc(int alertIndex);
179-
181+
180182
String getActiveAlertsStart(int alertIndex);
181-
183+
182184
String getActiveAlertsEnd(int alertIndex);
183-
185+
184186
String getActiveAlertsPhenomena(int alertIndex);
185-
187+
186188
String getActiveAlertsSignificance(int alertIndex);
187189

188190
String getActiveAlertsAttribution(int alertIndex);
189-
191+
190192
// end fowlerk add
191193

192194
virtual void whitespace(char c);

0 commit comments

Comments
 (0)