@@ -57,6 +57,13 @@ void WundergroundClient::updateAstronomy(String apiKey, String language, String
57
57
}
58
58
// end JJG add ////////////////////////////////////////////////////////////////////
59
59
60
+ // fowlerk added
61
+ void WundergroundClient::updateAlerts (String apiKey, String language, String country, String city) {
62
+ isForecast = true ;
63
+ doUpdate (" /api/" + apiKey + " /alerts/lang:" + language + " /q/" + country + " /" + city + " .json" );
64
+ }
65
+ // end fowlerk add
66
+
60
67
void WundergroundClient::doUpdate (String url) {
61
68
JsonStreamingParser parser;
62
69
parser.setListener (this );
@@ -112,12 +119,39 @@ void WundergroundClient::startDocument() {
112
119
113
120
void WundergroundClient::key (String key) {
114
121
currentKey = String (key);
122
+ // Restructured following logic to accomodate the multiple types of JSON returns based on the API. This was necessary since several
123
+ // keys are reused between various types of API calls, resulting in confusing returns in the original function. Various booleans
124
+ // now indicate whether the JSON stream being processed is part of the text forecast (txt_forecast), the first section of the 10-day
125
+ // forecast API that contains detailed text for the forecast period; the simple forecast (simpleforecast), the second section of the
126
+ // 10-day forecast API that contains such data as forecast highs/lows, conditions, precipitation / probabilities; the current
127
+ // observations (current_observation), from the observations API call; or alerts (alerts), for the future) weather alerts API call.
128
+ // Added by fowlerk...18-Dec-2016
115
129
if (currentKey == " txt_forecast" ) {
116
- isSimpleForecast = false ;
130
+ isForecast = true ;
131
+ isCurrentObservation = false ; // fowlerk
132
+ isSimpleForecast = false ; // fowlerk
133
+ isAlerts = false ; // fowlerk
117
134
}
118
135
if (currentKey == " simpleforecast" ) {
119
136
isSimpleForecast = true ;
137
+ isCurrentObservation = false ; // fowlerk
138
+ isForecast = false ; // fowlerk
139
+ isAlerts = false ; // fowlerk
120
140
}
141
+ // Added by fowlerk...
142
+ if (currentKey == " current_observation" ) {
143
+ isCurrentObservation = true ;
144
+ isSimpleForecast = false ;
145
+ isForecast = false ;
146
+ isAlerts = false ;
147
+ }
148
+ if (currentKey == " alerts" ) {
149
+ isCurrentObservation = false ;
150
+ isSimpleForecast = false ;
151
+ isForecast = false ;
152
+ isAlerts = true ;
153
+ }
154
+ // end fowlerk add
121
155
}
122
156
123
157
void WundergroundClient::value (String value) {
@@ -218,6 +252,12 @@ void WundergroundClient::value(String value) {
218
252
if (currentKey == " observation_time_rfc822" ) {
219
253
date = value.substring (0 , 16 );
220
254
}
255
+ // Begin add, fowlerk...04-Dec-2016
256
+ if (currentKey == " observation_time" ) {
257
+ observationTime = value;
258
+ }
259
+ // end add, fowlerk
260
+
221
261
if (currentKey == " temp_f" && !isMetric) {
222
262
currentTemp = value;
223
263
}
@@ -229,7 +269,8 @@ void WundergroundClient::value(String value) {
229
269
Serial.println (String (currentForecastPeriod) + " : " + value + " :" + currentParent);
230
270
forecastIcon[currentForecastPeriod] = value;
231
271
}
232
- if (!isForecast) {
272
+ // if (!isForecast) { // Removed by fowlerk
273
+ if (isCurrentObservation && !(isForecast || isSimpleForecast)) { // Added by fowlerk
233
274
weatherIcon = value;
234
275
}
235
276
}
@@ -245,6 +286,21 @@ void WundergroundClient::value(String value) {
245
286
if (currentKey == " pressure_in" && !isMetric) {
246
287
pressure = value + " in" ;
247
288
}
289
+ // fowlerk added...
290
+ if (currentKey == " feelslike_f" && !isMetric) {
291
+ feelslike = value;
292
+ }
293
+
294
+ if (currentKey == " feelslike_c" && isMetric) {
295
+ feelslike = value;
296
+ }
297
+
298
+ if (currentKey == " UV" ) {
299
+ UV = value;
300
+ }
301
+
302
+ // end fowlerk add
303
+
248
304
if (currentKey == " dewpoint_f" && !isMetric) {
249
305
dewPoint = value;
250
306
}
@@ -260,10 +316,22 @@ void WundergroundClient::value(String value) {
260
316
if (currentKey == " period" ) {
261
317
currentForecastPeriod = value.toInt ();
262
318
}
263
- if (currentKey == " title" && currentForecastPeriod < MAX_FORECAST_PERIODS) {
319
+ // Modified below line to add check to ensure we are processing the 10-day forecast
320
+ // before setting the forecastTitle (day of week of the current forecast day).
321
+ // (The keyword title is used in both the current observation and the 10-day forecast.)
322
+ // Modified by fowlerk
323
+ // if (currentKey == "title" && currentForecastPeriod < MAX_FORECAST_PERIODS) { // Removed, fowlerk
324
+ if (currentKey == " title" && isForecast && currentForecastPeriod < MAX_FORECAST_PERIODS) {
264
325
Serial.println (String (currentForecastPeriod) + " : " + value);
265
326
forecastTitle[currentForecastPeriod] = value;
266
327
}
328
+
329
+ // Added forecastText key following...fowlerk, 12/3/16
330
+ if (currentKey == " fcttext" && isForecast && currentForecastPeriod < MAX_FORECAST_PERIODS) {
331
+ forecastText[currentForecastPeriod] = value;
332
+ }
333
+ // end fowlerk add, 12/3/16
334
+
267
335
// The detailed forecast period has only one forecast per day with low/high for both
268
336
// night and day, starting at index 1.
269
337
int dailyForecastPeriod = (currentForecastPeriod - 1 ) * 2 ;
@@ -287,6 +355,28 @@ void WundergroundClient::value(String value) {
287
355
forecastLowTemp[dailyForecastPeriod] = value;
288
356
}
289
357
}
358
+ // fowlerk added...to pull month/day from the forecast period
359
+ if (currentKey == " month" && isSimpleForecast && currentForecastPeriod < MAX_FORECAST_PERIODS) {
360
+ // Added by fowlerk to handle transition from txtforecast to simpleforecast, as
361
+ // the key "period" doesn't appear until after some of the key values needed and is
362
+ // used as an array index.
363
+ if (isSimpleForecast && currentForecastPeriod == 19 ) {
364
+ currentForecastPeriod = 0 ;
365
+ }
366
+ forecastMonth[currentForecastPeriod] = value;
367
+ }
368
+
369
+ if (currentKey == " day" && isSimpleForecast && currentForecastPeriod < MAX_FORECAST_PERIODS) {
370
+ // Added by fowlerk to handle transition from txtforecast to simpleforecast, as
371
+ // the key "period" doesn't appear until after some of the key values needed and is
372
+ // used as an array index.
373
+ if (isSimpleForecast && currentForecastPeriod == 19 ) {
374
+ currentForecastPeriod = 0 ;
375
+ }
376
+ forecastDay[currentForecastPeriod] = value;
377
+ }
378
+ // end fowlerk add
379
+
290
380
}
291
381
292
382
void WundergroundClient::endArray () {
@@ -410,6 +500,21 @@ String WundergroundClient::getPressure() {
410
500
String WundergroundClient::getDewPoint () {
411
501
return dewPoint;
412
502
}
503
+ // fowlerk added...
504
+ String WundergroundClient::getFeelsLike () {
505
+ return feelslike;
506
+ }
507
+
508
+ String WundergroundClient::getUV () {
509
+ return UV;
510
+ }
511
+
512
+ // Added by fowlerk, 04-Dec-2016
513
+ String WundergroundClient::getObservationTime () {
514
+ return observationTime;
515
+ }
516
+ // end fowlerk add
517
+
413
518
414
519
String WundergroundClient::getPrecipitationToday () {
415
520
return precipitationToday;
@@ -438,6 +543,23 @@ String WundergroundClient::getForecastLowTemp(int period) {
438
543
String WundergroundClient::getForecastHighTemp (int period) {
439
544
return forecastHighTemp[period];
440
545
}
546
+ // fowlerk added...
547
+ String WundergroundClient::getForecastDay (int period) {
548
+ // Serial.print("Day period: "); Serial.println(period);
549
+ return forecastDay[period];
550
+ }
551
+
552
+ String WundergroundClient::getForecastMonth (int period) {
553
+ // Serial.print("Month period: "); Serial.println(period);
554
+ return forecastMonth[period];
555
+ }
556
+
557
+ String WundergroundClient::getForecastText (int period) {
558
+ Serial.print (" Forecast period: " ); Serial.println (period);
559
+ return forecastText[period];
560
+ }
561
+ // end fowlerk add
562
+
441
563
442
564
String WundergroundClient::getMeteoconIcon (String iconText) {
443
565
if (iconText == " chanceflurries" ) return " F" ;
0 commit comments