Skip to content

Commit 15b5a8b

Browse files
authored
Merge pull request #35 from a1rb4Ck/master
Added sun, moon, and local time
2 parents a7f4957 + 7a9c0b8 commit 15b5a8b

File tree

2 files changed

+163
-1
lines changed

2 files changed

+163
-1
lines changed

WundergroundClient.cpp

Lines changed: 140 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -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

3032
WundergroundClient::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+
4453
void 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+
242381
String WundergroundClient::getCurrentTemp() {
243382
return currentTemp;
244383
}

WundergroundClient.h

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,17 @@ class WundergroundClient: public JsonListener {
4040
String date = "-";
4141
boolean isMetric = true;
4242
String currentTemp;
43+
// JJG added ... ////////////////////////////////// define returns /////////////////////////////////
44+
String moonPctIlum; // not used
45+
String moonAge; // make this a long?
46+
String moonPhase;
47+
String sunriseTime;
48+
String sunsetTime;
49+
String moonriseTime;
50+
String moonsetTime;
51+
String windSpeed;
52+
String windDir;
53+
// end JJG add ////////////////////////////////////////////////////////////////////////////////////
4354
String weatherIcon;
4455
String weatherText;
4556
String humidity;
@@ -60,10 +71,22 @@ class WundergroundClient: public JsonListener {
6071
WundergroundClient(boolean isMetric);
6172
void updateConditions(String apiKey, String language, String country, String city);
6273
void updateForecast(String apiKey, String language, String country, String city);
74+
void updateAstronomy(String apiKey, String language, String country, String city); // JJG added
6375
String getHours();
6476
String getMinutes();
6577
String getSeconds();
6678
String getDate();
79+
// JJG added ... ///////////////////function name to string ////////////////////////////
80+
String getMoonPctIlum();
81+
String getMoonAge();
82+
String getMoonPhase();
83+
String getSunriseTime();
84+
String getSunsetTime();
85+
String getMoonriseTime();
86+
String getMoonsetTime();
87+
String getWindSpeed();
88+
String getWindDir();
89+
// end JJG add ///////////////////////////////////////////////////////////////////////
6790
long getCurrentEpoch();
6891

6992
String getCurrentTemp();

0 commit comments

Comments
 (0)