Skip to content

Commit 8240efa

Browse files
authored
Merge pull request #55 from tbpyro/master
Support for windspeed in km/h and mph
2 parents 6ffb10f + 4846192 commit 8240efa

File tree

2 files changed

+52
-39
lines changed

2 files changed

+52
-39
lines changed

WundergroundClient.cpp

Lines changed: 34 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -174,7 +174,7 @@ void WundergroundClient::key(String key) {
174174
isForecast = false;
175175
isAlerts = true;
176176
}
177-
// end fowlerk add
177+
// end fowlerk add
178178
}
179179

180180
void WundergroundClient::value(String value) {
@@ -252,7 +252,7 @@ void WundergroundClient::value(String value) {
252252
else isPM = false;
253253
char tempHourBuff[3] = ""; // fowlerk add for formatting, 12/22/16
254254
sprintf(tempHourBuff, "%2d", tempHour); // fowlerk add for formatting, 12/22/16
255-
moonriseTime = String(tempHourBuff); // fowlerk add for formatting, 12/22/16
255+
moonriseTime = String(tempHourBuff); // fowlerk add for formatting, 12/22/16
256256
// moonriseTime = value;
257257
}
258258
if (currentKey == "minute") {
@@ -268,7 +268,7 @@ void WundergroundClient::value(String value) {
268268
if (currentKey == "hour") {
269269
char tempHourBuff[3] = ""; // fowlerk add for formatting, 12/22/16
270270
sprintf(tempHourBuff, "%2d", value.toInt()); // fowlerk add for formatting, 12/22/16
271-
moonsetTime = String(tempHourBuff); // fowlerk add for formatting, 12/22/16
271+
moonsetTime = String(tempHourBuff); // fowlerk add for formatting, 12/22/16
272272
}
273273
if (currentKey == "minute") {
274274
char tempMinBuff[3] = ""; // fowlerk add for formatting, 12/22/16
@@ -277,8 +277,12 @@ void WundergroundClient::value(String value) {
277277
}
278278
}
279279

280-
if (currentKey == "wind_mph") {
281-
windSpeed = value;
280+
if (currentKey == "wind_mph" && !isMetric) {
281+
windSpeed = value + "mph";
282+
}
283+
284+
if (currentKey == "wind_kph" && isMetric) {
285+
windSpeed = value + "km/h";
282286
}
283287

284288
if (currentKey == "wind_dir") {
@@ -287,15 +291,19 @@ void WundergroundClient::value(String value) {
287291

288292
// end JJG add ////////////////////////////////////////////////////////////////////
289293

290-
if (currentKey == "observation_time_rfc822") {
294+
if (currentKey == "local_time_rfc822") {
291295
date = value.substring(0, 16);
292296
}
293-
// Begin add, fowlerk...04-Dec-2016
297+
298+
if (currentKey == "observation_time_rfc822") {
299+
observationDate = value.substring(0, 16);
300+
}
301+
// Begin add, fowlerk...04-Dec-2016
294302
if (currentKey == "observation_time") {
295303
observationTime = value;
296304
}
297-
// end add, fowlerk
298-
305+
// end add, fowlerk
306+
299307
if (currentKey == "temp_f" && !isMetric) {
300308
currentTemp = value;
301309
}
@@ -328,15 +336,15 @@ void WundergroundClient::value(String value) {
328336
if (currentKey == "feelslike_f" && !isMetric) {
329337
feelslike = value;
330338
}
331-
339+
332340
if (currentKey == "feelslike_c" && isMetric) {
333341
feelslike = value;
334342
}
335-
343+
336344
if (currentKey == "UV") {
337345
UV = value;
338346
}
339-
347+
340348
// Active alerts...added 18-Dec-2016
341349
if (currentKey == "type" && isAlerts) {
342350
activeAlertsCnt++;
@@ -400,9 +408,9 @@ void WundergroundClient::value(String value) {
400408
activeAlertsAttribution[currentAlert-1].replace("</a>","");
401409
activeAlertsAttribution[currentAlert-1].replace("/'>"," ");
402410
}
403-
411+
404412
// end fowlerk add
405-
413+
406414
if (currentKey == "dewpoint_f" && !isMetric) {
407415
dewPoint = value;
408416
}
@@ -421,7 +429,7 @@ void WundergroundClient::value(String value) {
421429
// Modified below line to add check to ensure we are processing the 10-day forecast
422430
// before setting the forecastTitle (day of week of the current forecast day).
423431
// (The keyword title is used in both the current observation and the 10-day forecast.)
424-
// Modified by fowlerk
432+
// Modified by fowlerk
425433
// if (currentKey == "title" && currentForecastPeriod < MAX_FORECAST_PERIODS) { // Removed, fowlerk
426434
if (currentKey == "title" && isForecast && currentForecastPeriod < MAX_FORECAST_PERIODS) {
427435
Serial.println(String(currentForecastPeriod) + ": " + value);
@@ -437,13 +445,13 @@ void WundergroundClient::value(String value) {
437445
forecastText[currentForecastPeriod] = value;
438446
}
439447
// end fowlerk add, 12/3/16
440-
448+
441449
// Added PoP (probability of precipitation) key following...fowlerk, 12/22/16
442450
if (currentKey == "pop" && isForecast && currentForecastPeriod < MAX_FORECAST_PERIODS) {
443451
PoP[currentForecastPeriod] = value;
444452
}
445453
// end fowlerk add, 12/22/16
446-
454+
447455
// The detailed forecast period has only one forecast per day with low/high for both
448456
// night and day, starting at index 1.
449457
int dailyForecastPeriod = (currentForecastPeriod - 1) * 2;
@@ -476,19 +484,19 @@ void WundergroundClient::value(String value) {
476484
currentForecastPeriod = 0;
477485
}
478486
forecastMonth[currentForecastPeriod] = value;
479-
}
487+
}
480488

481489
if (currentKey == "day" && isSimpleForecast && currentForecastPeriod < MAX_FORECAST_PERIODS) {
482490
// Added by fowlerk to handle transition from txtforecast to simpleforecast, as
483491
// the key "period" doesn't appear until after some of the key values needed and is
484492
// used as an array index.
485493
if (isSimpleForecast && currentForecastPeriod == 19) {
486494
currentForecastPeriod = 0;
487-
}
495+
}
488496
forecastDay[currentForecastPeriod] = value;
489497
}
490498
// end fowlerk add
491-
499+
492500
}
493501

494502
void WundergroundClient::endArray() {
@@ -549,6 +557,9 @@ String WundergroundClient::getSeconds() {
549557
String WundergroundClient::getDate() {
550558
return date;
551559
}
560+
String WundergroundClient::getObservationDate() {
561+
return observationDate;
562+
}
552563
long WundergroundClient::getCurrentEpoch() {
553564
return localEpoc + ((millis() - localMillisAtUpdate) / 1000);
554565
}
@@ -699,17 +710,17 @@ String WundergroundClient::getForecastHighTemp(int period) {
699710
}
700711
// fowlerk added...
701712
String WundergroundClient::getForecastDay(int period) {
702-
// Serial.print("Day period: "); Serial.println(period);
713+
// Serial.print("Day period: "); Serial.println(period);
703714
return forecastDay[period];
704715
}
705716

706717
String WundergroundClient::getForecastMonth(int period) {
707-
// Serial.print("Month period: "); Serial.println(period);
718+
// Serial.print("Month period: "); Serial.println(period);
708719
return forecastMonth[period];
709720
}
710721

711722
String WundergroundClient::getForecastText(int period) {
712-
// Serial.print("Forecast period: "); Serial.println(period);
723+
// Serial.print("Forecast period: "); Serial.println(period);
713724
return forecastText[period];
714725
}
715726

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
@@ -108,12 +109,13 @@ class WundergroundClient: public JsonListener {
108109
void updateAstronomy(String apiKey, String language, String country, String city);
109110
void updateAlerts(String apiKey, String language, String country, String city); // Added by fowlerk, 18-Dec-2016
110111
void initMetric(boolean isMetric); // Added by fowlerk, 12/22/16, as an option to change metric setting other than at instantiation
111-
112+
112113
// JJG added
113114
String getHours();
114115
String getMinutes();
115116
String getSeconds();
116117
String getDate();
118+
String getObservationDate();
117119
// JJG added ... ///////////////////function name to string ////////////////////////////
118120
String getMoonPctIlum();
119121
String getMoonAge();
@@ -146,9 +148,9 @@ class WundergroundClient: public JsonListener {
146148
String getPrecipitationToday();
147149
// fowlerk added...
148150
String getFeelsLike();
149-
151+
150152
String getUV();
151-
153+
152154
String getObservationTime(); // fowlerk add, 04-Dec-2016
153155
// end fowlerk add
154156

@@ -161,33 +163,33 @@ class WundergroundClient: public JsonListener {
161163
String getForecastHighTemp(int period);
162164
// fowlerk added...
163165
String getForecastDay(int period);
164-
166+
165167
String getForecastMonth(int period);
166-
168+
167169
String getForecastText(int period);
168-
170+
169171
String getPoP(int period);
170-
172+
171173
int getActiveAlertsCnt();
172-
174+
173175
String getActiveAlerts(int alertIndex);
174-
176+
175177
String getActiveAlertsText(int alertIndex);
176-
178+
177179
String getActiveAlertsMessage(int alertIndex);
178180

179181
bool getActiveAlertsMessageTrunc(int alertIndex);
180-
182+
181183
String getActiveAlertsStart(int alertIndex);
182-
184+
183185
String getActiveAlertsEnd(int alertIndex);
184-
186+
185187
String getActiveAlertsPhenomena(int alertIndex);
186-
188+
187189
String getActiveAlertsSignificance(int alertIndex);
188190

189191
String getActiveAlertsAttribution(int alertIndex);
190-
192+
191193
// end fowlerk add
192194

193195
virtual void whitespace(char c);

0 commit comments

Comments
 (0)