@@ -57,6 +57,13 @@ void WundergroundClient::updateAstronomy(String apiKey, String language, String
5757}
5858// end JJG add ////////////////////////////////////////////////////////////////////
5959
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+
6067void WundergroundClient::doUpdate (String url) {
6168 JsonStreamingParser parser;
6269 parser.setListener (this );
@@ -112,12 +119,39 @@ void WundergroundClient::startDocument() {
112119
113120void WundergroundClient::key (String key) {
114121 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
115129 if (currentKey == " txt_forecast" ) {
116- isSimpleForecast = false ;
130+ isForecast = true ;
131+ isCurrentObservation = false ; // fowlerk
132+ isSimpleForecast = false ; // fowlerk
133+ isAlerts = false ; // fowlerk
117134 }
118135 if (currentKey == " simpleforecast" ) {
119136 isSimpleForecast = true ;
137+ isCurrentObservation = false ; // fowlerk
138+ isForecast = false ; // fowlerk
139+ isAlerts = false ; // fowlerk
120140 }
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
121155}
122156
123157void WundergroundClient::value (String value) {
@@ -218,6 +252,12 @@ void WundergroundClient::value(String value) {
218252 if (currentKey == " observation_time_rfc822" ) {
219253 date = value.substring (0 , 16 );
220254 }
255+ // Begin add, fowlerk...04-Dec-2016
256+ if (currentKey == " observation_time" ) {
257+ observationTime = value;
258+ }
259+ // end add, fowlerk
260+
221261 if (currentKey == " temp_f" && !isMetric) {
222262 currentTemp = value;
223263 }
@@ -229,7 +269,8 @@ void WundergroundClient::value(String value) {
229269 Serial.println (String (currentForecastPeriod) + " : " + value + " :" + currentParent);
230270 forecastIcon[currentForecastPeriod] = value;
231271 }
232- if (!isForecast) {
272+ // if (!isForecast) { // Removed by fowlerk
273+ if (isCurrentObservation && !(isForecast || isSimpleForecast)) { // Added by fowlerk
233274 weatherIcon = value;
234275 }
235276 }
@@ -245,6 +286,21 @@ void WundergroundClient::value(String value) {
245286 if (currentKey == " pressure_in" && !isMetric) {
246287 pressure = value + " in" ;
247288 }
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+
248304 if (currentKey == " dewpoint_f" && !isMetric) {
249305 dewPoint = value;
250306 }
@@ -260,10 +316,22 @@ void WundergroundClient::value(String value) {
260316 if (currentKey == " period" ) {
261317 currentForecastPeriod = value.toInt ();
262318 }
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) {
264325 Serial.println (String (currentForecastPeriod) + " : " + value);
265326 forecastTitle[currentForecastPeriod] = value;
266327 }
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+
267335 // The detailed forecast period has only one forecast per day with low/high for both
268336 // night and day, starting at index 1.
269337 int dailyForecastPeriod = (currentForecastPeriod - 1 ) * 2 ;
@@ -287,6 +355,28 @@ void WundergroundClient::value(String value) {
287355 forecastLowTemp[dailyForecastPeriod] = value;
288356 }
289357 }
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+
290380}
291381
292382void WundergroundClient::endArray () {
@@ -410,6 +500,21 @@ String WundergroundClient::getPressure() {
410500String WundergroundClient::getDewPoint () {
411501 return dewPoint;
412502}
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+
413518
414519String WundergroundClient::getPrecipitationToday () {
415520 return precipitationToday;
@@ -438,6 +543,23 @@ String WundergroundClient::getForecastLowTemp(int period) {
438543String WundergroundClient::getForecastHighTemp (int period) {
439544 return forecastHighTemp[period];
440545}
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+
441563
442564String WundergroundClient::getMeteoconIcon (String iconText) {
443565 if (iconText == " chanceflurries" ) return " F" ;
0 commit comments