Skip to content

Commit

Permalink
Merge pull request #46 from Qrome/2.3
Browse files Browse the repository at this point in the history
2.3
  • Loading branch information
Qrome authored Aug 23, 2018
2 parents 9d80da6 + 2edfc94 commit d8c2e8a
Show file tree
Hide file tree
Showing 7 changed files with 182 additions and 38 deletions.
117 changes: 108 additions & 9 deletions marquee/GeoNamesClient.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,15 +24,19 @@ SOFTWARE.
#include "GeoNamesClient.h"

GeoNamesClient::GeoNamesClient(String UserName, String lat, String lon) {
updateClient(UserName, lat, lon);
}

void GeoNamesClient::updateClient(String UserName, String lat, String lon) {
myLat = lat;
myLon = lon;
myUserName = UserName;
}

float GeoNamesClient::getTimeOffset() {
datetime = "";
WiFiClient client;
String apiGetData = "GET /timezoneJSON?lat=" + myLat + "&lng=" + myLon + "&username=" + myUserName + " HTTP/1.1";

Serial.println("Getting TimeZone Data for " + myLat + "," + myLon);
Serial.println(apiGetData);
String result = "";
Expand Down Expand Up @@ -76,22 +80,117 @@ float GeoNamesClient::getTimeOffset() {
JsonObject& root = json_buf.parseObject(jsonArray);
String offset = (const char*)root["dstOffset"];
// Sample time: "2018-03-19 21:22"
String timeDate = (const char*)root["time"];
hours = timeDate.substring(11, 13).toInt();
minutes = timeDate.substring(14, 16).toInt();
datetime = (const char*)root["time"];
Serial.println("rawOffset for " + String((const char*)root["timezoneId"]) + " is: " + offset);
Serial.println("Geo Time: " + String(hours) + ":" + String(minutes));
Serial.println("Geo Date & Time: " + getMonthName() + " " + getDay(false) + ", " + getHours() + ":" + getMinutes());
Serial.println();
return offset.toFloat();
}

int GeoNamesClient::getHours() {
return hours;
String GeoNamesClient::getHours() {
String rtnValue = "";
if (datetime.length() >= 13) {
rtnValue = datetime.substring(11, 13);
}
return rtnValue;
}

String GeoNamesClient::getMinutes() {
String rtnValue = "";
if (datetime.length() >= 16) {
rtnValue = datetime.substring(14, 16);
}
return rtnValue;
}

String GeoNamesClient::getYear() {
String rtnValue = "";
if (datetime.length() > 4) {
rtnValue = datetime.substring(0, 4);
}
return rtnValue;
}

int GeoNamesClient::getMinutes() {
return minutes;
String GeoNamesClient::getMonth00() {
String rtnValue = "";
if (datetime.length() > 7) {
rtnValue = datetime.substring(5, 7);
}
return rtnValue;
}

String GeoNamesClient::getMonth(boolean zeroPad) {
String rtnValue = getMonth00();
if (zeroPad) {
return rtnValue;
}
int month = rtnValue.toInt();
return String(month);
}

String GeoNamesClient::getMonthName() {
String rtnValue = "";
int month = getMonth00().toInt();
switch (month) {
case 1:
rtnValue = "Jan";
break;
case 2:
rtnValue = "Feb";
break;
case 3:
rtnValue = "Mar";
break;
case 4:
rtnValue = "Apr";
break;
case 5:
rtnValue = "May";
break;
case 6:
rtnValue = "June";
break;
case 7:
rtnValue = "July";
break;
case 8:
rtnValue = "Aug";
break;
case 9:
rtnValue = "Sep";
break;
case 10:
rtnValue = "Oct";
break;
case 11:
rtnValue = "Nov";
break;
case 12:
rtnValue = "Dec";
break;
default:
rtnValue = "";
}
return rtnValue;
}

String GeoNamesClient::getDay(boolean zeroPad) {
String rtnValue = getDay00();
if (zeroPad) {
return rtnValue;
}
int day = rtnValue.toInt();
return String(day);
}

String GeoNamesClient::getDay00() {
String rtnValue = "";
if (datetime.length() > 10) {
rtnValue = datetime.substring(8, 10);
}
return rtnValue;
}




14 changes: 11 additions & 3 deletions marquee/GeoNamesClient.h
Original file line number Diff line number Diff line change
Expand Up @@ -34,13 +34,21 @@ class GeoNamesClient {

int hours = 0;
int minutes = 0;
String datetime = "";

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

public:
GeoNamesClient(String UserName, String lat, String lon);
void updateClient(String UserName, String lat, String lon);
float getTimeOffset();
int getHours();
int getMinutes();
String getHours();
String getMinutes();
String getYear();
String getMonth00();
String getMonth(boolean zeroPad);
String getMonthName();
String getDay00();
String getDay(boolean zeroPad);
};


14 changes: 14 additions & 0 deletions marquee/NewsApiClient.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -165,5 +165,19 @@ String NewsApiClient::cleanText(String text) {
text.replace("ô", "o");
text.replace("", "...");
text.replace("", "-");
text.replace("Â", "A");
text.replace("À", "A");
text.replace("æ", "ae");
text.replace("Æ", "AE");
text.replace("É", "E");
text.replace("È", "E");
text.replace("Ë", "E");
text.replace("Ô", "O");
text.replace("Ö", "O");
text.replace("œ", "oe");
text.replace("Œ", "OE");
text.replace("Ù", "U");
text.replace("Û", "U");
text.replace("Ü", "U");
return text;
}
11 changes: 4 additions & 7 deletions marquee/OpenWeatherMapClient.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,8 @@ void OpenWeatherMapClient::updateWeather() {

Serial.println("Getting Weather Data");
Serial.println(apiGetData);
result = "";
weathers[0].cached = false;
weathers[0].error = "";
if (weatherClient.connect(servername, 80)) { //starts client connection, checks for connection
weatherClient.println(apiGetData);
weatherClient.println("Host: " + String(servername));
Expand All @@ -50,6 +51,7 @@ void OpenWeatherMapClient::updateWeather() {
else {
Serial.println("connection for weather data failed"); //error message if no client connect
Serial.println();
weathers[0].error = "Connection for weather data failed";
return;
}

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

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

weathers[0].cached = false;
weathers[0].error = "";
// Parse JSON object
JsonObject& root = jsonBuffer.parseObject(weatherClient);
if (!root.success()) {
Expand Down Expand Up @@ -155,10 +156,6 @@ void OpenWeatherMapClient::setMetric(boolean isMetric) {
}
}

String OpenWeatherMapClient::getWeatherResults() {
return result;
}

String OpenWeatherMapClient::getLat(int index) {
return weathers[index].lat;
}
Expand Down
3 changes: 0 additions & 3 deletions marquee/OpenWeatherMapClient.h
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,6 @@ class OpenWeatherMapClient {
String units = "";

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

typedef struct {
String lat;
Expand Down Expand Up @@ -63,8 +62,6 @@ class OpenWeatherMapClient {
void updateCityIdList(int CityIDs[], int cityCount);
void setMetric(boolean isMetric);

String getWeatherResults();

String getLat(int index);
String getLon(int index);
String getDt(int index);
Expand Down
4 changes: 2 additions & 2 deletions marquee/TimeClient.h
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ class TimeClient {
float myUtcOffset = 0;
long localEpoc = 0;
long localMillisAtUpdate;
const char* ntpServerName = "www.google.com";
const char* ntpServerName = "time.google.com";
const int httpPort = 80;
byte packetBuffer[ NTP_PACKET_SIZE]; //buffer to hold incoming and outgoing packets

Expand All @@ -59,4 +59,4 @@ class TimeClient {
long getCurrentEpochWithUtcOffset();

};


Loading

0 comments on commit d8c2e8a

Please sign in to comment.