@@ -33,6 +33,12 @@ WundergroundClient::WundergroundClient(boolean _isMetric) {
33
33
isMetric = _isMetric;
34
34
}
35
35
36
+ // Added by fowlerk, 12/22/16, as an option to change metric setting other than at instantiation
37
+ void WundergroundClient::initMetric (boolean _isMetric) {
38
+ isMetric = _isMetric;
39
+ }
40
+ // end add fowlerk, 12/22/16
41
+
36
42
void WundergroundClient::updateConditions (String apiKey, String language, String country, String city) {
37
43
isForecast = false ;
38
44
doUpdate (" /api/" + apiKey + " /conditions/lang:" + language + " /q/" + country + " /" + city + " .json" );
@@ -59,7 +65,19 @@ void WundergroundClient::updateAstronomy(String apiKey, String language, String
59
65
60
66
// fowlerk added
61
67
void WundergroundClient::updateAlerts (String apiKey, String language, String country, String city) {
62
- isForecast = true ;
68
+ currentAlert = 0 ;
69
+ activeAlertsCnt = 0 ;
70
+ isForecast = false ;
71
+ isSimpleForecast = false ;
72
+ isCurrentObservation = false ;
73
+ isAlerts = true ;
74
+ if (country == " US" ) {
75
+ isAlertUS = true ;
76
+ isAlertEU = false ;
77
+ } else {
78
+ isAlertUS = false ;
79
+ isAlertEU = true ;
80
+ }
63
81
doUpdate (" /api/" + apiKey + " /alerts/lang:" + language + " /q/" + country + " /" + city + " .json" );
64
82
}
65
83
// end fowlerk add
@@ -182,14 +200,18 @@ void WundergroundClient::value(String value) {
182
200
isPM = true ;
183
201
}
184
202
else isPM = false ;
185
- sunriseTime = String (tempHour);
203
+ char tempHourBuff[3 ] = " " ; // fowlerk add for formatting, 12/22/16
204
+ sprintf (tempHourBuff, " %2d" , tempHour); // fowlerk add for formatting, 12/22/16
205
+ sunriseTime = String (tempHourBuff); // fowlerk add for formatting, 12/22/16
186
206
// sunriseTime = value;
187
207
}
188
208
if (currentKey == " minute" ) {
189
- sunriseTime += " :" + value;
190
- if (isPM) sunriseTime += " pm" ;
191
- else if (usePM) sunriseTime += " am" ;
192
- }
209
+ char tempMinBuff[3 ] = " " ; // fowlerk add for formatting, 12/22/16
210
+ sprintf (tempMinBuff, " %02d" , value.toInt ()); // fowlerk add for formatting, 12/22/16
211
+ sunriseTime += " :" + String (tempMinBuff); // fowlerk add for formatting, 12/22/16
212
+ if (isPM) sunriseTime += " pm" ;
213
+ else if (usePM) sunriseTime += " am" ;
214
+ }
193
215
}
194
216
195
217
@@ -201,14 +223,18 @@ void WundergroundClient::value(String value) {
201
223
isPM = true ;
202
224
}
203
225
else isPM = false ;
204
- sunsetTime = String (tempHour);
226
+ char tempHourBuff[3 ] = " " ; // fowlerk add for formatting, 12/22/16
227
+ sprintf (tempHourBuff, " %2d" , tempHour); // fowlerk add for formatting, 12/22/16
228
+ sunsetTime = String (tempHourBuff); // fowlerk add for formatting, 12/22/16
205
229
// sunsetTime = value;
206
230
}
207
231
if (currentKey == " minute" ) {
208
- sunsetTime += " :" + value;
209
- if (isPM) sunsetTime += " pm" ;
210
- else if (usePM) sunsetTime += " am" ;
211
- }
232
+ char tempMinBuff[3 ] = " " ; // fowlerk add for formatting, 12/22/16
233
+ sprintf (tempMinBuff, " %02d" , value.toInt ()); // fowlerk add for formatting, 12/22/16
234
+ sunsetTime += " :" + String (tempMinBuff); // fowlerk add for formatting, 12/22/16
235
+ if (isPM) sunsetTime += " pm" ;
236
+ else if (usePM) sunsetTime += " am" ;
237
+ }
212
238
}
213
239
214
240
if (currentParent == " moonrise" ) { // Has a Parent key and 2 sub-keys
@@ -219,24 +245,31 @@ void WundergroundClient::value(String value) {
219
245
isPM = true ;
220
246
}
221
247
else isPM = false ;
222
- moonriseTime = String (tempHour);
248
+ char tempHourBuff[3 ] = " " ; // fowlerk add for formatting, 12/22/16
249
+ sprintf (tempHourBuff, " %2d" , tempHour); // fowlerk add for formatting, 12/22/16
250
+ moonriseTime = String (tempHourBuff); // fowlerk add for formatting, 12/22/16
223
251
// moonriseTime = value;
224
252
}
225
253
if (currentKey == " minute" ) {
226
- moonriseTime += " :" + value;
227
- if (isPM) moonriseTime += " pm" ;
228
- else if (usePM) moonriseTime += " am" ;
229
-
230
- }
254
+ char tempMinBuff[3 ] = " " ; // fowlerk add for formatting, 12/22/16
255
+ sprintf (tempMinBuff, " %02d" , value.toInt ()); // fowlerk add for formatting, 12/22/16
256
+ moonriseTime += " :" + String (tempMinBuff); // fowlerk add for formatting, 12/22/16
257
+ if (isPM) moonriseTime += " pm" ;
258
+ else if (usePM) moonriseTime += " am" ;
259
+ }
231
260
}
232
261
233
262
if (currentParent == " moonset" ) { // Not used - has a Parent key and 2 sub-keys
234
263
if (currentKey == " hour" ) {
235
- moonsetTime = value;
236
- }
264
+ char tempHourBuff[3 ] = " " ; // fowlerk add for formatting, 12/22/16
265
+ sprintf (tempHourBuff, " %2d" , value.toInt ()); // fowlerk add for formatting, 12/22/16
266
+ moonsetTime = String (tempHourBuff); // fowlerk add for formatting, 12/22/16
267
+ }
237
268
if (currentKey == " minute" ) {
238
- moonsetTime += " :" + value;
239
- }
269
+ char tempMinBuff[3 ] = " " ; // fowlerk add for formatting, 12/22/16
270
+ sprintf (tempMinBuff, " %02d" , value.toInt ()); // fowlerk add for formatting, 12/22/16
271
+ moonsetTime += " :" + String (tempMinBuff); // fowlerk add for formatting, 12/22/16
272
+ }
240
273
}
241
274
242
275
if (currentKey == " wind_mph" ) {
@@ -299,6 +332,70 @@ void WundergroundClient::value(String value) {
299
332
UV = value;
300
333
}
301
334
335
+ // Active alerts...added 18-Dec-2016
336
+ if (currentKey == " type" && isAlerts) {
337
+ activeAlertsCnt++;
338
+ currentAlert++;
339
+ activeAlerts[currentAlert-1 ] = value;
340
+ Serial.print (" Alert type processed, value: " ); Serial.println (activeAlerts[currentAlert-1 ]);
341
+ }
342
+ if (currentKey == " description" && isAlerts && isAlertUS) {
343
+ activeAlertsText[currentAlert-1 ] = value;
344
+ Serial.print (" Alert description processed, value: " ); Serial.println (activeAlertsText[currentAlert-1 ]);
345
+ }
346
+ if (currentKey == " wtype_meteoalarm_name" && isAlerts && isAlertEU) {
347
+ activeAlertsText[currentAlert-1 ] = value;
348
+ Serial.print (" Alert description processed, value: " ); Serial.println (activeAlertsText[currentAlert-1 ]);
349
+ }
350
+ if (currentKey == " message" && isAlerts) {
351
+ activeAlertsMessage[currentAlert-1 ] = value;
352
+ Serial.print (" Alert msg length: " ); Serial.println (activeAlertsMessage[currentAlert-1 ].length ());
353
+ if (activeAlertsMessage[currentAlert-1 ].length () >= 511 ) {
354
+ activeAlertsMessageTrunc[currentAlert-1 ] = true ;
355
+ } else {
356
+ activeAlertsMessageTrunc[currentAlert-1 ] = false ;
357
+ }
358
+ Serial.print (" Alert message processed, value: " ); Serial.println (activeAlertsMessage[currentAlert-1 ]);
359
+ }
360
+ if (currentKey == " date" && isAlerts) {
361
+ activeAlertsStart[currentAlert-1 ] = value;
362
+ // Check last char for a "/"; the returned value sometimes includes this; if so, strip it (47 is a "/" char)
363
+ if (activeAlertsStart[currentAlert-1 ].charAt (activeAlertsStart[currentAlert-1 ].length ()-1 ) == 47 ) {
364
+ Serial.println (" ...last char is a slash..." );
365
+ activeAlertsStart[currentAlert-1 ] = activeAlertsStart[currentAlert-1 ].substring (0 ,(activeAlertsStart[currentAlert-1 ].length ()-1 ));
366
+ }
367
+ // For meteoalarms, the start field is returned with the UTC=0 by default (not used?)
368
+ if (isAlertEU && activeAlertsStart[currentAlert-1 ] == " 1970-01-01 00:00:00 GMT" ) {
369
+ activeAlertsStart[currentAlert-1 ] = " <Not specified>" ;
370
+ }
371
+ Serial.print (" Alert start processed, value: " ); Serial.println (activeAlertsStart[currentAlert-1 ]);
372
+ }
373
+ if (currentKey == " expires" && isAlerts) {
374
+ activeAlertsEnd[currentAlert-1 ] = value;
375
+ Serial.print (" Alert expiration processed, value: " ); Serial.println (activeAlertsEnd[currentAlert-1 ]);
376
+ }
377
+ if (currentKey == " phenomena" && isAlerts) {
378
+ activeAlertsPhenomena[currentAlert-1 ] = value;
379
+ Serial.print (" Alert phenomena processed, value: " ); Serial.println (activeAlertsPhenomena[currentAlert-1 ]);
380
+ }
381
+ if (currentKey == " significance" && isAlerts && isAlertUS) {
382
+ activeAlertsSignificance[currentAlert-1 ] = value;
383
+ Serial.print (" Alert significance processed, value: " ); Serial.println (activeAlertsSignificance[currentAlert-1 ]);
384
+ }
385
+ // Map meteoalarm level to the field for significance for consistency (used for European alerts)
386
+ if (currentKey == " level_meteoalarm" && isAlerts && isAlertEU) {
387
+ activeAlertsSignificance[currentAlert-1 ] = value;
388
+ Serial.print (" Meteo alert significance processed, value: " ); Serial.println (activeAlertsSignificance[currentAlert-1 ]);
389
+ }
390
+ // For meteoalarms only (European alerts); attribution must be displayed according to the T&C's of use
391
+ if (currentKey == " attribution" && isAlerts) {
392
+ activeAlertsAttribution[currentAlert-1 ] = value;
393
+ // Remove some of the markup in the attribution
394
+ activeAlertsAttribution[currentAlert-1 ].replace (" <a href='" ," " );
395
+ activeAlertsAttribution[currentAlert-1 ].replace (" </a>" ," " );
396
+ activeAlertsAttribution[currentAlert-1 ].replace (" /'>" ," " );
397
+ }
398
+
302
399
// end fowlerk add
303
400
304
401
if (currentKey == " dewpoint_f" && !isMetric) {
@@ -327,11 +424,21 @@ void WundergroundClient::value(String value) {
327
424
}
328
425
329
426
// Added forecastText key following...fowlerk, 12/3/16
330
- if (currentKey == " fcttext" && isForecast && currentForecastPeriod < MAX_FORECAST_PERIODS) {
427
+ if (currentKey == " fcttext" && isForecast && !isMetric && currentForecastPeriod < MAX_FORECAST_PERIODS) {
428
+ forecastText[currentForecastPeriod] = value;
429
+ }
430
+ // Added option for metric forecast following...fowlerk, 12/22/16
431
+ if (currentKey == " fcttext_metric" && isForecast && isMetric && currentForecastPeriod < MAX_FORECAST_PERIODS) {
331
432
forecastText[currentForecastPeriod] = value;
332
433
}
333
434
// end fowlerk add, 12/3/16
334
435
436
+ // Added PoP (probability of precipitation) key following...fowlerk, 12/22/16
437
+ if (currentKey == " pop" && isForecast && currentForecastPeriod < MAX_FORECAST_PERIODS) {
438
+ PoP[currentForecastPeriod] = value;
439
+ }
440
+ // end fowlerk add, 12/22/16
441
+
335
442
// The detailed forecast period has only one forecast per day with low/high for both
336
443
// night and day, starting at index 1.
337
444
int dailyForecastPeriod = (currentForecastPeriod - 1 ) * 2 ;
@@ -513,6 +620,48 @@ String WundergroundClient::getUV() {
513
620
String WundergroundClient::getObservationTime () {
514
621
return observationTime;
515
622
}
623
+
624
+ // Active alerts...added 18-Dec-2016
625
+ String WundergroundClient::getActiveAlerts (int alertIndex) {
626
+ return activeAlerts[alertIndex];
627
+ }
628
+
629
+ String WundergroundClient::getActiveAlertsText (int alertIndex) {
630
+ return activeAlertsText[alertIndex];
631
+ }
632
+
633
+ String WundergroundClient::getActiveAlertsMessage (int alertIndex) {
634
+ return activeAlertsMessage[alertIndex];
635
+ }
636
+
637
+ bool WundergroundClient::getActiveAlertsMessageTrunc (int alertIndex) {
638
+ return activeAlertsMessageTrunc[alertIndex];
639
+ }
640
+
641
+ String WundergroundClient::getActiveAlertsStart (int alertIndex) {
642
+ return activeAlertsStart[alertIndex];
643
+ }
644
+
645
+ String WundergroundClient::getActiveAlertsEnd (int alertIndex) {
646
+ return activeAlertsEnd[alertIndex];
647
+ }
648
+
649
+ String WundergroundClient::getActiveAlertsPhenomena (int alertIndex) {
650
+ return activeAlertsPhenomena[alertIndex];
651
+ }
652
+
653
+ String WundergroundClient::getActiveAlertsSignificance (int alertIndex) {
654
+ return activeAlertsSignificance[alertIndex];
655
+ }
656
+
657
+ String WundergroundClient::getActiveAlertsAttribution (int alertIndex) {
658
+ return activeAlertsAttribution[alertIndex];
659
+ }
660
+
661
+ int WundergroundClient::getActiveAlertsCnt () {
662
+ return activeAlertsCnt;
663
+ }
664
+
516
665
// end fowlerk add
517
666
518
667
@@ -555,9 +704,14 @@ String WundergroundClient::getForecastMonth(int period) {
555
704
}
556
705
557
706
String WundergroundClient::getForecastText (int period) {
558
- Serial.print (" Forecast period: " ); Serial.println (period);
707
+ // Serial.print("Forecast period: "); Serial.println(period);
559
708
return forecastText[period];
560
709
}
710
+
711
+ // Added PoP...12/22/16
712
+ String WundergroundClient::getPoP (int period) {
713
+ return PoP[period];
714
+ }
561
715
// end fowlerk add
562
716
563
717
@@ -603,4 +757,4 @@ String WundergroundClient::getMeteoconIcon(String iconText) {
603
757
if (iconText == " nt_tstorms" ) return " &" ;
604
758
605
759
return " )" ;
606
- }
760
+ }
0 commit comments