Skip to content

Commit d8c2e8a

Browse files
authored
Merge pull request #46 from Qrome/2.3
2.3
2 parents 9d80da6 + 2edfc94 commit d8c2e8a

File tree

7 files changed

+182
-38
lines changed

7 files changed

+182
-38
lines changed

marquee/GeoNamesClient.cpp

Lines changed: 108 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -24,15 +24,19 @@ SOFTWARE.
2424
#include "GeoNamesClient.h"
2525

2626
GeoNamesClient::GeoNamesClient(String UserName, String lat, String lon) {
27+
updateClient(UserName, lat, lon);
28+
}
29+
30+
void GeoNamesClient::updateClient(String UserName, String lat, String lon) {
2731
myLat = lat;
2832
myLon = lon;
2933
myUserName = UserName;
3034
}
3135

3236
float GeoNamesClient::getTimeOffset() {
37+
datetime = "";
3338
WiFiClient client;
3439
String apiGetData = "GET /timezoneJSON?lat=" + myLat + "&lng=" + myLon + "&username=" + myUserName + " HTTP/1.1";
35-
3640
Serial.println("Getting TimeZone Data for " + myLat + "," + myLon);
3741
Serial.println(apiGetData);
3842
String result = "";
@@ -76,22 +80,117 @@ float GeoNamesClient::getTimeOffset() {
7680
JsonObject& root = json_buf.parseObject(jsonArray);
7781
String offset = (const char*)root["dstOffset"];
7882
// Sample time: "2018-03-19 21:22"
79-
String timeDate = (const char*)root["time"];
80-
hours = timeDate.substring(11, 13).toInt();
81-
minutes = timeDate.substring(14, 16).toInt();
83+
datetime = (const char*)root["time"];
8284
Serial.println("rawOffset for " + String((const char*)root["timezoneId"]) + " is: " + offset);
83-
Serial.println("Geo Time: " + String(hours) + ":" + String(minutes));
85+
Serial.println("Geo Date & Time: " + getMonthName() + " " + getDay(false) + ", " + getHours() + ":" + getMinutes());
8486
Serial.println();
8587
return offset.toFloat();
8688
}
8789

88-
int GeoNamesClient::getHours() {
89-
return hours;
90+
String GeoNamesClient::getHours() {
91+
String rtnValue = "";
92+
if (datetime.length() >= 13) {
93+
rtnValue = datetime.substring(11, 13);
94+
}
95+
return rtnValue;
96+
}
97+
98+
String GeoNamesClient::getMinutes() {
99+
String rtnValue = "";
100+
if (datetime.length() >= 16) {
101+
rtnValue = datetime.substring(14, 16);
102+
}
103+
return rtnValue;
104+
}
105+
106+
String GeoNamesClient::getYear() {
107+
String rtnValue = "";
108+
if (datetime.length() > 4) {
109+
rtnValue = datetime.substring(0, 4);
110+
}
111+
return rtnValue;
90112
}
91113

92-
int GeoNamesClient::getMinutes() {
93-
return minutes;
114+
String GeoNamesClient::getMonth00() {
115+
String rtnValue = "";
116+
if (datetime.length() > 7) {
117+
rtnValue = datetime.substring(5, 7);
118+
}
119+
return rtnValue;
120+
}
121+
122+
String GeoNamesClient::getMonth(boolean zeroPad) {
123+
String rtnValue = getMonth00();
124+
if (zeroPad) {
125+
return rtnValue;
126+
}
127+
int month = rtnValue.toInt();
128+
return String(month);
129+
}
130+
131+
String GeoNamesClient::getMonthName() {
132+
String rtnValue = "";
133+
int month = getMonth00().toInt();
134+
switch (month) {
135+
case 1:
136+
rtnValue = "Jan";
137+
break;
138+
case 2:
139+
rtnValue = "Feb";
140+
break;
141+
case 3:
142+
rtnValue = "Mar";
143+
break;
144+
case 4:
145+
rtnValue = "Apr";
146+
break;
147+
case 5:
148+
rtnValue = "May";
149+
break;
150+
case 6:
151+
rtnValue = "June";
152+
break;
153+
case 7:
154+
rtnValue = "July";
155+
break;
156+
case 8:
157+
rtnValue = "Aug";
158+
break;
159+
case 9:
160+
rtnValue = "Sep";
161+
break;
162+
case 10:
163+
rtnValue = "Oct";
164+
break;
165+
case 11:
166+
rtnValue = "Nov";
167+
break;
168+
case 12:
169+
rtnValue = "Dec";
170+
break;
171+
default:
172+
rtnValue = "";
173+
}
174+
return rtnValue;
175+
}
176+
177+
String GeoNamesClient::getDay(boolean zeroPad) {
178+
String rtnValue = getDay00();
179+
if (zeroPad) {
180+
return rtnValue;
181+
}
182+
int day = rtnValue.toInt();
183+
return String(day);
184+
}
185+
186+
String GeoNamesClient::getDay00() {
187+
String rtnValue = "";
188+
if (datetime.length() > 10) {
189+
rtnValue = datetime.substring(8, 10);
190+
}
191+
return rtnValue;
94192
}
95193

96194

97195

196+

marquee/GeoNamesClient.h

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -34,13 +34,21 @@ class GeoNamesClient {
3434

3535
int hours = 0;
3636
int minutes = 0;
37+
String datetime = "";
3738

3839
const char* servername = "api.geonames.org"; // remote server we will connect to
3940

4041
public:
4142
GeoNamesClient(String UserName, String lat, String lon);
43+
void updateClient(String UserName, String lat, String lon);
4244
float getTimeOffset();
43-
int getHours();
44-
int getMinutes();
45+
String getHours();
46+
String getMinutes();
47+
String getYear();
48+
String getMonth00();
49+
String getMonth(boolean zeroPad);
50+
String getMonthName();
51+
String getDay00();
52+
String getDay(boolean zeroPad);
4553
};
46-
54+

marquee/NewsApiClient.cpp

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -165,5 +165,19 @@ String NewsApiClient::cleanText(String text) {
165165
text.replace("ô", "o");
166166
text.replace("", "...");
167167
text.replace("", "-");
168+
text.replace("Â", "A");
169+
text.replace("À", "A");
170+
text.replace("æ", "ae");
171+
text.replace("Æ", "AE");
172+
text.replace("É", "E");
173+
text.replace("È", "E");
174+
text.replace("Ë", "E");
175+
text.replace("Ô", "O");
176+
text.replace("Ö", "O");
177+
text.replace("œ", "oe");
178+
text.replace("Œ", "OE");
179+
text.replace("Ù", "U");
180+
text.replace("Û", "U");
181+
text.replace("Ü", "U");
168182
return text;
169183
}

marquee/OpenWeatherMapClient.cpp

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,8 @@ void OpenWeatherMapClient::updateWeather() {
3939

4040
Serial.println("Getting Weather Data");
4141
Serial.println(apiGetData);
42-
result = "";
42+
weathers[0].cached = false;
43+
weathers[0].error = "";
4344
if (weatherClient.connect(servername, 80)) { //starts client connection, checks for connection
4445
weatherClient.println(apiGetData);
4546
weatherClient.println("Host: " + String(servername));
@@ -50,6 +51,7 @@ void OpenWeatherMapClient::updateWeather() {
5051
else {
5152
Serial.println("connection for weather data failed"); //error message if no client connect
5253
Serial.println();
54+
weathers[0].error = "Connection for weather data failed";
5355
return;
5456
}
5557

@@ -64,6 +66,7 @@ void OpenWeatherMapClient::updateWeather() {
6466
if (strcmp(status, "HTTP/1.1 200 OK") != 0) {
6567
Serial.print(F("Unexpected response: "));
6668
Serial.println(status);
69+
weathers[0].error = "Weather Data Error: " + String(status);
6770
return;
6871
}
6972

@@ -77,8 +80,6 @@ void OpenWeatherMapClient::updateWeather() {
7780
const size_t bufferSize = 710;
7881
DynamicJsonBuffer jsonBuffer(bufferSize);
7982

80-
weathers[0].cached = false;
81-
weathers[0].error = "";
8283
// Parse JSON object
8384
JsonObject& root = jsonBuffer.parseObject(weatherClient);
8485
if (!root.success()) {
@@ -155,10 +156,6 @@ void OpenWeatherMapClient::setMetric(boolean isMetric) {
155156
}
156157
}
157158

158-
String OpenWeatherMapClient::getWeatherResults() {
159-
return result;
160-
}
161-
162159
String OpenWeatherMapClient::getLat(int index) {
163160
return weathers[index].lat;
164161
}

marquee/OpenWeatherMapClient.h

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,6 @@ class OpenWeatherMapClient {
3333
String units = "";
3434

3535
const char* servername = "api.openweathermap.org"; // remote server we will connect to
36-
String result;
3736

3837
typedef struct {
3938
String lat;
@@ -63,8 +62,6 @@ class OpenWeatherMapClient {
6362
void updateCityIdList(int CityIDs[], int cityCount);
6463
void setMetric(boolean isMetric);
6564

66-
String getWeatherResults();
67-
6865
String getLat(int index);
6966
String getLon(int index);
7067
String getDt(int index);

marquee/TimeClient.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ class TimeClient {
3939
float myUtcOffset = 0;
4040
long localEpoc = 0;
4141
long localMillisAtUpdate;
42-
const char* ntpServerName = "www.google.com";
42+
const char* ntpServerName = "time.google.com";
4343
const int httpPort = 80;
4444
byte packetBuffer[ NTP_PACKET_SIZE]; //buffer to hold incoming and outgoing packets
4545

@@ -59,4 +59,4 @@ class TimeClient {
5959
long getCurrentEpochWithUtcOffset();
6060

6161
};
62-
62+

0 commit comments

Comments
 (0)