Skip to content

Commit cce9612

Browse files
committed
Turned project into a library
1 parent 956fe44 commit cce9612

File tree

6 files changed

+148
-100
lines changed

6 files changed

+148
-100
lines changed

TimeClient.cpp

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,8 +41,11 @@ void TimeClient::updateTime() {
4141
client.print(String("GET / HTTP/1.1\r\n") +
4242
String("Host: www.google.com\r\n") +
4343
String("Connection: close\r\n\r\n"));
44-
while(!client.available()) {
44+
int repeatCounter = 0;
45+
while(!client.available() && repeatCounter < 10) {
4546
delay(1000);
47+
Serial.println(".");
48+
repeatCounter++;
4649
}
4750

4851
String line;

WundergroundClient.cpp

Lines changed: 58 additions & 60 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ void WundergroundClient::updateConditions(String apiKey, String country, String
4040

4141
void WundergroundClient::updateForecast(String apiKey, String country, String city) {
4242
isForecast = true;
43-
doUpdate("/api/" + apiKey + "/forecast10day/q/" + country + "/" + city + ".json");
43+
doUpdate("/api/" + apiKey + "/forecast10day/q/" + country + "/" + city + ".json");
4444
}
4545

4646
void WundergroundClient::doUpdate(String url) {
@@ -52,18 +52,18 @@ void WundergroundClient::doUpdate(String url) {
5252
Serial.println("connection failed");
5353
return;
5454
}
55-
55+
5656
Serial.print("Requesting URL: ");
5757
Serial.println(url);
58-
58+
5959
// This will send the request to the server
6060
client.print(String("GET ") + url + " HTTP/1.1\r\n" +
61-
"Host: api.wunderground.com\r\n" +
61+
"Host: api.wunderground.com\r\n" +
6262
"Connection: close\r\n\r\n");
6363
while(!client.available()) {
64-
delay(1000);
64+
delay(1000);
6565
}
66-
66+
6767
int pos = 0;
6868
boolean isBody = false;
6969
char c;
@@ -117,9 +117,9 @@ void WundergroundClient::value(String value) {
117117
}
118118
if (currentKey == "icon") {
119119
if (isForecast && !isSimpleForecast && currentForecastPeriod < MAX_FORECAST_PERIODS) {
120-
Serial.println(String(currentForecastPeriod) + ": " + value + ":" + currentParent);
120+
Serial.println(String(currentForecastPeriod) + ": " + value + ":" + currentParent);
121121
forecastIcon[currentForecastPeriod] = value;
122-
}
122+
}
123123
if (!isForecast) {
124124
weatherIcon = value;
125125
}
@@ -146,30 +146,31 @@ void WundergroundClient::value(String value) {
146146
currentForecastPeriod = value.toInt();
147147
}
148148
if (currentKey == "title" && currentForecastPeriod < MAX_FORECAST_PERIODS) {
149-
Serial.println(String(currentForecastPeriod) + ": " + value);
149+
Serial.println(String(currentForecastPeriod) + ": " + value);
150150
forecastTitle[currentForecastPeriod] = value;
151151
}
152-
// The detailed forecast period has only one forecast per day with low/high for both
152+
// The detailed forecast period has only one forecast per day with low/high for both
153153
// night and day, starting at index 1.
154154
int dailyForecastPeriod = (currentForecastPeriod - 1) * 2;
155-
if (currentKey == "fahrenheit" && !isMetric && currentForecastPeriod < MAX_FORECAST_PERIODS) {
156-
155+
156+
if (currentKey == "fahrenheit" && !isMetric && dailyForecastPeriod < MAX_FORECAST_PERIODS) {
157+
157158
if (currentParent == "high") {
158159
forecastHighTemp[dailyForecastPeriod] = value;
159160
}
160161
if (currentParent == "low") {
161162
forecastLowTemp[dailyForecastPeriod] = value;
162-
}
163+
}
163164
}
164-
if (currentKey == "celsius" && isMetric && currentForecastPeriod < MAX_FORECAST_PERIODS) {
165-
165+
if (currentKey == "celsius" && isMetric && dailyForecastPeriod < MAX_FORECAST_PERIODS) {
166+
166167
if (currentParent == "high") {
167168
Serial.println(String(currentForecastPeriod)+ ": " + value);
168169
forecastHighTemp[dailyForecastPeriod] = value;
169170
}
170171
if (currentParent == "low") {
171172
forecastLowTemp[dailyForecastPeriod] = value;
172-
}
173+
}
173174
}
174175
}
175176

@@ -260,7 +261,7 @@ String WundergroundClient::getTodayIcon() {
260261
}
261262

262263
String WundergroundClient::getForecastIcon(int period) {
263-
return getMeteoconIcon(forecastIcon[period]);
264+
return getMeteoconIcon(forecastIcon[period]);
264265
}
265266

266267
String WundergroundClient::getForecastTitle(int period) {
@@ -276,48 +277,45 @@ String WundergroundClient::getForecastHighTemp(int period) {
276277
}
277278

278279
String WundergroundClient::getMeteoconIcon(String iconText) {
279-
if (iconText == "chanceflurries") return "F";
280-
if (iconText == "chancerain") return "Q";
281-
if (iconText == "chancesleet") return "W";
282-
if (iconText == "chancesnow") return "V";
283-
if (iconText == "chancetstorms") return "S";
284-
if (iconText == "clear") return "B";
285-
if (iconText == "cloudy") return "Y";
286-
if (iconText == "flurries") return "F";
287-
if (iconText == "fog") return "M";
288-
if (iconText == "hazy") return "E";
289-
if (iconText == "mostlycloudy") return "Y";
290-
if (iconText == "mostlysunny") return "H";
291-
if (iconText == "partlycloudy") return "H";
292-
if (iconText == "partlysunny") return "J";
293-
if (iconText == "sleet") return "W";
294-
if (iconText == "rain") return "R";
295-
if (iconText == "snow") return "W";
296-
if (iconText == "sunny") return "B";
297-
if (iconText == "tstorms") return "0";
298-
299-
if (iconText == "nt_chanceflurries") return "F";
300-
if (iconText == "nt_chancerain") return "7";
301-
if (iconText == "nt_chancesleet") return "#";
302-
if (iconText == "nt_chancesnow") return "#";
303-
if (iconText == "nt_chancetstorms") return "&";
304-
if (iconText == "nt_clear") return "2";
305-
if (iconText == "nt_cloudy") return "Y";
306-
if (iconText == "nt_flurries") return "9";
307-
if (iconText == "nt_fog") return "M";
308-
if (iconText == "nt_hazy") return "E";
309-
if (iconText == "nt_mostlycloudy") return "5";
310-
if (iconText == "nt_mostlysunny") return "3";
311-
if (iconText == "nt_partlycloudy") return "4";
312-
if (iconText == "nt_partlysunny") return "4";
313-
if (iconText == "nt_sleet") return "9";
314-
if (iconText == "nt_rain") return "7";
315-
if (iconText == "nt_snow") return "#";
316-
if (iconText == "nt_sunny") return "4";
317-
if (iconText == "nt_tstorms") return "&";
318-
280+
if (iconText == "chanceflurries") return "F";
281+
if (iconText == "chancerain") return "Q";
282+
if (iconText == "chancesleet") return "W";
283+
if (iconText == "chancesnow") return "V";
284+
if (iconText == "chancetstorms") return "S";
285+
if (iconText == "clear") return "B";
286+
if (iconText == "cloudy") return "Y";
287+
if (iconText == "flurries") return "F";
288+
if (iconText == "fog") return "M";
289+
if (iconText == "hazy") return "E";
290+
if (iconText == "mostlycloudy") return "Y";
291+
if (iconText == "mostlysunny") return "H";
292+
if (iconText == "partlycloudy") return "H";
293+
if (iconText == "partlysunny") return "J";
294+
if (iconText == "sleet") return "W";
295+
if (iconText == "rain") return "R";
296+
if (iconText == "snow") return "W";
297+
if (iconText == "sunny") return "B";
298+
if (iconText == "tstorms") return "0";
299+
300+
if (iconText == "nt_chanceflurries") return "F";
301+
if (iconText == "nt_chancerain") return "7";
302+
if (iconText == "nt_chancesleet") return "#";
303+
if (iconText == "nt_chancesnow") return "#";
304+
if (iconText == "nt_chancetstorms") return "&";
305+
if (iconText == "nt_clear") return "2";
306+
if (iconText == "nt_cloudy") return "Y";
307+
if (iconText == "nt_flurries") return "9";
308+
if (iconText == "nt_fog") return "M";
309+
if (iconText == "nt_hazy") return "E";
310+
if (iconText == "nt_mostlycloudy") return "5";
311+
if (iconText == "nt_mostlysunny") return "3";
312+
if (iconText == "nt_partlycloudy") return "4";
313+
if (iconText == "nt_partlysunny") return "4";
314+
if (iconText == "nt_sleet") return "9";
315+
if (iconText == "nt_rain") return "7";
316+
if (iconText == "nt_snow") return "#";
317+
if (iconText == "nt_sunny") return "4";
318+
if (iconText == "nt_tstorms") return "&";
319+
319320
return ")";
320321
}
321-
322-
323-

WundergroundClient.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ class WundergroundClient: public JsonListener {
5555
String forecastTitle [MAX_FORECAST_PERIODS];
5656
String forecastLowTemp [MAX_FORECAST_PERIODS];
5757
String forecastHighTemp [MAX_FORECAST_PERIODS];
58-
58+
5959
public:
6060
WundergroundClient(boolean isMetric);
6161
void updateConditions(String apiKey, String country, String city);
@@ -87,9 +87,9 @@ class WundergroundClient: public JsonListener {
8787
String getForecastLowTemp(int period);
8888

8989
String getForecastHighTemp(int period);
90-
90+
9191
virtual void whitespace(char c);
92-
92+
9393
virtual void startDocument();
9494

9595
virtual void key(String key);

0 commit comments

Comments
 (0)