Skip to content

Commit a6a8b41

Browse files
committed
Added percentage of precipitation
1 parent 608cc48 commit a6a8b41

File tree

2 files changed

+56
-44
lines changed

2 files changed

+56
-44
lines changed

WundergroundClient.cpp

Lines changed: 25 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -151,7 +151,7 @@ void WundergroundClient::key(String key) {
151151
isForecast = false;
152152
isAlerts = true;
153153
}
154-
// end fowlerk add
154+
// end fowlerk add
155155
}
156156

157157
void WundergroundClient::value(String value) {
@@ -252,12 +252,12 @@ void WundergroundClient::value(String value) {
252252
if (currentKey == "observation_time_rfc822") {
253253
date = value.substring(0, 16);
254254
}
255-
// Begin add, fowlerk...04-Dec-2016
255+
// Begin add, fowlerk...04-Dec-2016
256256
if (currentKey == "observation_time") {
257257
observationTime = value;
258258
}
259-
// end add, fowlerk
260-
259+
// end add, fowlerk
260+
261261
if (currentKey == "temp_f" && !isMetric) {
262262
currentTemp = value;
263263
}
@@ -290,17 +290,17 @@ void WundergroundClient::value(String value) {
290290
if (currentKey == "feelslike_f" && !isMetric) {
291291
feelslike = value;
292292
}
293-
293+
294294
if (currentKey == "feelslike_c" && isMetric) {
295295
feelslike = value;
296296
}
297-
297+
298298
if (currentKey == "UV") {
299299
UV = value;
300300
}
301-
301+
302302
// end fowlerk add
303-
303+
304304
if (currentKey == "dewpoint_f" && !isMetric) {
305305
dewPoint = value;
306306
}
@@ -316,10 +316,14 @@ void WundergroundClient::value(String value) {
316316
if (currentKey == "period") {
317317
currentForecastPeriod = value.toInt();
318318
}
319+
if (currentKey == "pop" && isForecast && currentForecastPeriod < MAX_FORECAST_PERIODS) {
320+
Serial.println("Pop" + String(currentForecastPeriod) + ": " + value);
321+
forecastPop[currentForecastPeriod] = value;
322+
}
319323
// Modified below line to add check to ensure we are processing the 10-day forecast
320324
// before setting the forecastTitle (day of week of the current forecast day).
321325
// (The keyword title is used in both the current observation and the 10-day forecast.)
322-
// Modified by fowlerk
326+
// Modified by fowlerk
323327
// if (currentKey == "title" && currentForecastPeriod < MAX_FORECAST_PERIODS) { // Removed, fowlerk
324328
if (currentKey == "title" && isForecast && currentForecastPeriod < MAX_FORECAST_PERIODS) {
325329
Serial.println(String(currentForecastPeriod) + ": " + value);
@@ -331,7 +335,7 @@ void WundergroundClient::value(String value) {
331335
forecastText[currentForecastPeriod] = value;
332336
}
333337
// end fowlerk add, 12/3/16
334-
338+
335339
// The detailed forecast period has only one forecast per day with low/high for both
336340
// night and day, starting at index 1.
337341
int dailyForecastPeriod = (currentForecastPeriod - 1) * 2;
@@ -364,19 +368,19 @@ void WundergroundClient::value(String value) {
364368
currentForecastPeriod = 0;
365369
}
366370
forecastMonth[currentForecastPeriod] = value;
367-
}
371+
}
368372

369373
if (currentKey == "day" && isSimpleForecast && currentForecastPeriod < MAX_FORECAST_PERIODS) {
370374
// Added by fowlerk to handle transition from txtforecast to simpleforecast, as
371375
// the key "period" doesn't appear until after some of the key values needed and is
372376
// used as an array index.
373377
if (isSimpleForecast && currentForecastPeriod == 19) {
374378
currentForecastPeriod = 0;
375-
}
379+
}
376380
forecastDay[currentForecastPeriod] = value;
377381
}
378382
// end fowlerk add
379-
383+
380384
}
381385

382386
void WundergroundClient::endArray() {
@@ -543,19 +547,24 @@ String WundergroundClient::getForecastLowTemp(int period) {
543547
String WundergroundClient::getForecastHighTemp(int period) {
544548
return forecastHighTemp[period];
545549
}
550+
551+
String WundergroundClient::getForecastPrecipitationPercentage(int period) {
552+
return forecastPop[period];
553+
}
554+
546555
// fowlerk added...
547556
String WundergroundClient::getForecastDay(int period) {
548-
// Serial.print("Day period: "); Serial.println(period);
557+
// Serial.print("Day period: "); Serial.println(period);
549558
return forecastDay[period];
550559
}
551560

552561
String WundergroundClient::getForecastMonth(int period) {
553-
// Serial.print("Month period: "); Serial.println(period);
562+
// Serial.print("Month period: "); Serial.println(period);
554563
return forecastMonth[period];
555564
}
556565

557566
String WundergroundClient::getForecastText(int period) {
558-
Serial.print("Forecast period: "); Serial.println(period);
567+
Serial.print("Forecast period: "); Serial.println(period);
559568
return forecastText[period];
560569
}
561570
// end fowlerk add

WundergroundClient.h

Lines changed: 31 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -58,37 +58,38 @@ class WundergroundClient: public JsonListener {
5858
String pressure;
5959
String dewPoint;
6060
String precipitationToday;
61-
// fowlerk added...
62-
String feelslike;
63-
String UV;
64-
String observationTime; // fowlerk add, 04-Dec-2016
65-
// end fowlerk add
66-
61+
// fowlerk added...
62+
String feelslike;
63+
String UV;
64+
String observationTime; // fowlerk add, 04-Dec-2016
65+
// end fowlerk add
66+
6767
void doUpdate(String url);
6868

6969
// forecast
7070
boolean isForecast = false;
7171
boolean isSimpleForecast = false; // true; fowlerk
72-
boolean isCurrentObservation = false; // Added by fowlerk
73-
boolean isAlerts = false; // Added by fowlerk
72+
boolean isCurrentObservation = false; // Added by fowlerk
73+
boolean isAlerts = false; // Added by fowlerk
7474
int currentForecastPeriod;
7575
String forecastIcon [MAX_FORECAST_PERIODS];
7676
String forecastTitle [MAX_FORECAST_PERIODS];
7777
String forecastLowTemp [MAX_FORECAST_PERIODS];
7878
String forecastHighTemp [MAX_FORECAST_PERIODS];
79-
// fowlerk added...
80-
String forecastDay [MAX_FORECAST_PERIODS/2];
81-
String forecastMonth [MAX_FORECAST_PERIODS/2];
82-
String forecastText [MAX_FORECAST_PERIODS];
83-
// end fowlerk add
79+
String forecastPop[MAX_FORECAST_PERIODS];
80+
// fowlerk added...
81+
String forecastDay [MAX_FORECAST_PERIODS/2];
82+
String forecastMonth [MAX_FORECAST_PERIODS/2];
83+
String forecastText [MAX_FORECAST_PERIODS];
84+
// end fowlerk add
8485

8586
public:
8687
WundergroundClient(boolean isMetric);
8788
void updateConditions(String apiKey, String language, String country, String city);
8889
void updateConditions(String apiKey, String language, String zmwCode);
8990
void updateForecast(String apiKey, String language, String country, String city);
9091
void updateAstronomy(String apiKey, String language, String country, String city);
91-
void updateAlerts(String apiKey, String language, String country, String city); // Added by fowlerk, 18-Dec-2016
92+
void updateAlerts(String apiKey, String language, String country, String city); // Added by fowlerk, 18-Dec-2016
9293
// JJG added
9394
String getHours();
9495
String getMinutes();
@@ -124,13 +125,13 @@ class WundergroundClient: public JsonListener {
124125
String getDewPoint();
125126

126127
String getPrecipitationToday();
127-
// fowlerk added...
128-
String getFeelsLike();
129-
130-
String getUV();
131-
132-
String getObservationTime(); // fowlerk add, 04-Dec-2016
133-
// end fowlerk add
128+
// fowlerk added...
129+
String getFeelsLike();
130+
131+
String getUV();
132+
133+
String getObservationTime(); // fowlerk add, 04-Dec-2016
134+
// end fowlerk add
134135

135136
String getForecastIcon(int period);
136137

@@ -139,13 +140,15 @@ class WundergroundClient: public JsonListener {
139140
String getForecastLowTemp(int period);
140141

141142
String getForecastHighTemp(int period);
142-
// fowlerk added...
143-
String getForecastDay(int period);
144-
145-
String getForecastMonth(int period);
146-
147-
String getForecastText(int period);
148-
// end fowlerk add
143+
144+
String getForecastPrecipitationPercentage(int period);
145+
// fowlerk added...
146+
String getForecastDay(int period);
147+
148+
String getForecastMonth(int period);
149+
150+
String getForecastText(int period);
151+
// end fowlerk add
149152

150153
virtual void whitespace(char c);
151154

0 commit comments

Comments
 (0)