@@ -26,6 +26,8 @@ See more at http://blog.squix.ch
2626#include < ESP8266WiFi.h>
2727#include < WiFiClient.h>
2828#include " WundergroundClient.h"
29+ bool usePM = false ; // Set to true if you want to use AM/PM time disaply
30+ bool isPM = false ; // JJG added ///////////
2931
3032WundergroundClient::WundergroundClient (boolean _isMetric) {
3133 isMetric = _isMetric;
@@ -41,6 +43,13 @@ void WundergroundClient::updateForecast(String apiKey, String language, String c
4143 doUpdate (" /api/" + apiKey + " /forecast10day/lang:" + language + " /q/" + country + " /" + city + " .json" );
4244}
4345
46+ // JJG added ////////////////////////////////
47+ void WundergroundClient::updateAstronomy (String apiKey, String language, String country, String city) {
48+ isForecast = true ;
49+ doUpdate (" /api/" + apiKey + " /astronomy/lang:" + language + " /q/" + country + " /" + city + " .json" );
50+ }
51+ // end JJG add ////////////////////////////////////////////////////////////////////
52+
4453void WundergroundClient::doUpdate (String url) {
4554 JsonStreamingParser parser;
4655 parser.setListener (this );
@@ -109,7 +118,97 @@ void WundergroundClient::value(String value) {
109118 localEpoc = value.toInt ();
110119 localMillisAtUpdate = millis ();
111120 }
112- if (currentKey == " observation_time_rfc822" ) {
121+
122+ // JJG added ... //////////////////////// search for keys /////////////////////////
123+ if (currentKey == " percentIlluminated" ) {
124+ moonPctIlum = value;
125+ }
126+
127+ if (currentKey == " ageOfMoon" ) {
128+ moonAge = value;
129+ }
130+
131+ if (currentKey == " phaseofMoon" ) {
132+ moonPhase = value;
133+ }
134+
135+
136+ if (currentParent == " sunrise" ) { // Has a Parent key and 2 sub-keys
137+ if (currentKey == " hour" ) {
138+ int tempHour = value.toInt (); // do this to concert to 12 hour time (make it a function!)
139+ if (usePM && tempHour > 12 ){
140+ tempHour -= 12 ;
141+ isPM = true ;
142+ }
143+ else isPM = false ;
144+ sunriseTime = String (tempHour);
145+ // sunriseTime = value;
146+ }
147+ if (currentKey == " minute" ) {
148+ sunriseTime += " :" + value;
149+ if (isPM) sunriseTime += " pm" ;
150+ else if (usePM) sunriseTime += " am" ;
151+ }
152+ }
153+
154+
155+ if (currentParent == " sunset" ) { // Has a Parent key and 2 sub-keys
156+ if (currentKey == " hour" ) {
157+ int tempHour = value.toInt (); // do this to concert to 12 hour time (make it a function!)
158+ if (usePM && tempHour > 12 ){
159+ tempHour -= 12 ;
160+ isPM = true ;
161+ }
162+ else isPM = false ;
163+ sunsetTime = String (tempHour);
164+ // sunsetTime = value;
165+ }
166+ if (currentKey == " minute" ) {
167+ sunsetTime += " :" + value;
168+ if (isPM) sunsetTime += " pm" ;
169+ else if (usePM) sunsetTime += " am" ;
170+ }
171+ }
172+
173+ if (currentParent == " moonrise" ) { // Has a Parent key and 2 sub-keys
174+ if (currentKey == " hour" ) {
175+ int tempHour = value.toInt (); // do this to concert to 12 hour time (make it a function!)
176+ if (usePM && tempHour > 12 ){
177+ tempHour -= 12 ;
178+ isPM = true ;
179+ }
180+ else isPM = false ;
181+ moonriseTime = String (tempHour);
182+ // moonriseTime = value;
183+ }
184+ if (currentKey == " minute" ) {
185+ moonriseTime += " :" + value;
186+ if (isPM) moonriseTime += " pm" ;
187+ else if (usePM) moonriseTime += " am" ;
188+
189+ }
190+ }
191+
192+ if (currentParent == " moonset" ) { // Not used - has a Parent key and 2 sub-keys
193+ if (currentKey == " hour" ) {
194+ moonsetTime = value;
195+ }
196+ if (currentKey == " minute" ) {
197+ moonsetTime += " :" + value;
198+ }
199+ }
200+
201+ if (currentKey == " wind_mph" ) {
202+ windSpeed = value;
203+ }
204+
205+ if (currentKey == " wind_dir" ) {
206+ windDir = value;
207+ }
208+
209+ // end JJG add ////////////////////////////////////////////////////////////////////
210+
211+ if (currentKey == " observation_time_rfc822" ) {
113212 date = value.substring (0 , 16 );
114213 }
115214 if (currentKey == " temp_f" && !isMetric) {
@@ -239,6 +338,46 @@ long WundergroundClient::getCurrentEpoch() {
239338 return localEpoc + ((millis () - localMillisAtUpdate) / 1000 );
240339}
241340
341+ // JJG added ... /////////////////////////////////////////////////////////////////////////////////////////
342+ String WundergroundClient::getMoonPctIlum () {
343+ return moonPctIlum;
344+ }
345+
346+ String WundergroundClient::getMoonAge () {
347+ return moonAge;
348+ }
349+
350+ String WundergroundClient::getMoonPhase () {
351+ return moonPhase;
352+ }
353+
354+ String WundergroundClient::getSunriseTime () {
355+ return sunriseTime;
356+ }
357+
358+ String WundergroundClient::getSunsetTime () {
359+ return sunsetTime;
360+ }
361+
362+ String WundergroundClient::getMoonriseTime () {
363+ return moonriseTime;
364+ }
365+
366+ String WundergroundClient::getMoonsetTime () {
367+ return moonsetTime;
368+ }
369+
370+ String WundergroundClient::getWindSpeed () {
371+ return windSpeed;
372+ }
373+
374+ String WundergroundClient::getWindDir () {
375+ return windDir;
376+ }
377+
378+ // end JJG add ////////////////////////////////////////////////////////////////////////////////////////////
379+
380+
242381String WundergroundClient::getCurrentTemp () {
243382 return currentTemp;
244383}
0 commit comments