Skip to content

Commit

Permalink
Merge pull request #55 from Qrome/2.4
Browse files Browse the repository at this point in the history
2.4
  • Loading branch information
Qrome authored Oct 30, 2018
2 parents d8c2e8a + 4e6dcb3 commit 43909ec
Show file tree
Hide file tree
Showing 9 changed files with 76 additions and 16 deletions.
12 changes: 8 additions & 4 deletions marquee/GeoNamesClient.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,14 +23,15 @@ SOFTWARE.

#include "GeoNamesClient.h"

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

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

float GeoNamesClient::getTimeOffset() {
Expand Down Expand Up @@ -79,6 +80,9 @@ float GeoNamesClient::getTimeOffset() {
DynamicJsonBuffer json_buf;
JsonObject& root = json_buf.parseObject(jsonArray);
String offset = (const char*)root["dstOffset"];
if (!isDst) {
offset = (const char*)root["gmtOffset"];
}
// Sample time: "2018-03-19 21:22"
datetime = (const char*)root["time"];
Serial.println("rawOffset for " + String((const char*)root["timezoneId"]) + " is: " + offset);
Expand Down Expand Up @@ -193,4 +197,4 @@ String GeoNamesClient::getDay00() {





5 changes: 3 additions & 2 deletions marquee/GeoNamesClient.h
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ class GeoNamesClient {
String myLat = "";
String myLon = "";
String myUserName = "";
boolean isDst = true; // Daylight Savings Time

int hours = 0;
int minutes = 0;
Expand All @@ -39,8 +40,8 @@ class GeoNamesClient {
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);
GeoNamesClient(String UserName, String lat, String lon, boolean useDst);
void updateClient(String UserName, String lat, String lon, boolean useDst);
float getTimeOffset();
String getHours();
String getMinutes();
Expand Down
8 changes: 6 additions & 2 deletions marquee/NewsApiClient.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -173,11 +173,15 @@ String NewsApiClient::cleanText(String text) {
text.replace("È", "E");
text.replace("Ë", "E");
text.replace("Ô", "O");
text.replace("Ö", "O");
text.replace("Ö", "Oe");
text.replace("ö", "oe");
text.replace("œ", "oe");
text.replace("Œ", "OE");
text.replace("Ù", "U");
text.replace("Û", "U");
text.replace("Ü", "U");
text.replace("Ü", "Ue");
text.replace("ü", "ue");
text.replace("Ä", "Ae");
text.replace("ä", "ae");
return text;
}
35 changes: 35 additions & 0 deletions marquee/OpenWeatherMapClient.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -228,6 +228,41 @@ String OpenWeatherMapClient::getError() {
return weathers[0].error;
}

String OpenWeatherMapClient::getWeekDay(int index, float offset) {
String rtnValue = "";
long epoc = weathers[index].dt.toInt();
long day = 0;
if (epoc != 0) {
day = (((epoc + (3600 * (int)offset)) / 86400) + 4) % 7;
switch (day) {
case 0:
rtnValue = "Sunday";
break;
case 1:
rtnValue = "Monday";
break;
case 2:
rtnValue = "Tuesday";
break;
case 3:
rtnValue = "Wednesday";
break;
case 4:
rtnValue = "Thursday";
break;
case 5:
rtnValue = "Friday";
break;
case 6:
rtnValue = "Saturday";
break;
default:
break;
}
}
return rtnValue;
}

String OpenWeatherMapClient::getWeatherIcon(int index)
{
int id = getWeatherId(index).toInt();
Expand Down
1 change: 1 addition & 0 deletions marquee/OpenWeatherMapClient.h
Original file line number Diff line number Diff line change
Expand Up @@ -81,5 +81,6 @@ class OpenWeatherMapClient {
String getMyCityIDs();
String getWeatherIcon(int index);
String getError();
String getWeekDay(int index, float offset);
};

1 change: 1 addition & 0 deletions marquee/Settings.h
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@ int CityIDs[] = { 5304391 }; //Only USE ONE for weather marquee
String marqueeMessage = "";
boolean IS_METRIC = false; // false = Imperial and true = Metric
boolean IS_24HOUR = false; // 23:00 millitary 24 hour clock
boolean IS_DST = true; // Does your TimeZone use Daylight Savings Time (DST)?
const int WEBSERVER_PORT = 80; // The port you can access this device on over HTTP
const boolean WEBSERVER_ENABLED = true; // Device will provide a web interface via http://[ip]:[port]/
boolean IS_BASIC_AUTH = true; // Use Basic Authorization for Configuration security on Web Interface
Expand Down
2 changes: 2 additions & 0 deletions marquee/TimeClient.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -150,3 +150,5 @@ long TimeClient::getCurrentEpoch() {
long TimeClient::getCurrentEpochWithUtcOffset() {
return round(getCurrentEpoch() + 3600 * myUtcOffset + 86400L) % 86400L;
}


1 change: 0 additions & 1 deletion marquee/TimeClient.h
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,5 @@ class TimeClient {
String getAmPmFormattedTime();
long getCurrentEpoch();
long getCurrentEpochWithUtcOffset();

};

27 changes: 20 additions & 7 deletions marquee/marquee.ino
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ SOFTWARE.

#include "Settings.h"

#define VERSION "2.3"
#define VERSION "2.4"

#define HOSTNAME "CLOCK-"
#define CONFIG "/conf.txt"
Expand Down Expand Up @@ -69,7 +69,7 @@ boolean displayOn = true;
boolean timeOffsetFetched = false;

// GeoNames
GeoNamesClient geoNames(GEONAMES_USER, "", "");
GeoNamesClient geoNames(GEONAMES_USER, "", "", IS_DST);

// News Client
NewsApiClient newsClient(NEWS_API_KEY, NEWS_SOURCE);
Expand Down Expand Up @@ -107,7 +107,8 @@ String CHANGE_FORM1 = "<form class='w3-container' action='/locations' method='ge
"<p><input name='showcondition' class='w3-check w3-margin-top' type='checkbox' %CONDITION_CHECKED%> Display Weather Condition</p>"
"<p><input name='showhumidity' class='w3-check w3-margin-top' type='checkbox' %HUMIDITY_CHECKED%> Display Humidity</p>"
"<p><input name='showwind' class='w3-check w3-margin-top' type='checkbox' %WIND_CHECKED%> Display Wind</p>"
"<p><input name='is24hour' class='w3-check w3-margin-top' type='checkbox' %IS_24HOUR_CHECKED%> Use 24 Hour Clock (military time)</p>";
"<p><input name='is24hour' class='w3-check w3-margin-top' type='checkbox' %IS_24HOUR_CHECKED%> Use 24 Hour Clock (military time)</p>"
"<p><input name='isDST' class='w3-check w3-margin-top' type='checkbox' %IS_DST_CHECKED%> Use DST (Daylight Savings Time)</p>";

String CHANGE_FORM2 = "<p><input name='displayadvice' class='w3-check w3-margin-top' type='checkbox' %ADVICECHECKED%> Display Advice</p>"
"<p><label>Marquee Message (up to 60 chars)</label><input class='w3-input w3-border w3-margin-bottom' type='text' name='marqueeMsg' value='%MSG%' maxlength='60'></p>"
Expand Down Expand Up @@ -308,7 +309,7 @@ void loop() {

if (timeClient.getHours() == "00" && timeClient.getMinutes() == "00" && timeClient.getSeconds() == "00") {
// Exactly Midnight -- fetch a new geoNames for updating the Date and time offset
geoNames.updateClient(GEONAMES_USER, weatherClient.getLat(0), weatherClient.getLon(0));
geoNames.updateClient(GEONAMES_USER, weatherClient.getLat(0), weatherClient.getLon(0), IS_DST);
UtcOffset = geoNames.getTimeOffset();
}

Expand Down Expand Up @@ -343,6 +344,7 @@ void loop() {
msg += " ";

if (SHOW_DATE) {
msg += weatherClient.getWeekDay(0, UtcOffset) + ", ";
msg += geoNames.getMonthName() + " " + geoNames.getDay(false) + " ";
}
if (SHOW_CITY) {
Expand Down Expand Up @@ -489,6 +491,7 @@ void handleLocations() {
CityIDs[0] = server.arg("city1").toInt();
ADVICE_ENABLED = server.hasArg("displayadvice");
IS_24HOUR = server.hasArg("is24hour");
IS_DST = server.hasArg("isDST");
SHOW_DATE = server.hasArg("showdate");
SHOW_CITY = server.hasArg("showcity");
SHOW_CONDITION = server.hasArg("showcondition");
Expand Down Expand Up @@ -744,6 +747,11 @@ void handleConfigure() {
is24hourChecked = "checked='checked'";
}
form.replace("%IS_24HOUR_CHECKED%", is24hourChecked);
String isDstChecked = "";
if (IS_DST) {
isDstChecked = "checked='checked'";
}
form.replace("%IS_DST_CHECKED%", isDstChecked);
String checked = "";
if (IS_METRIC) {
checked = "checked='checked'";
Expand Down Expand Up @@ -849,7 +857,7 @@ void getWeatherData() //client function to send/receive GET request data.
// we need to get offsets
centerPrint("....");
timeOffsetFetched = true;
geoNames.updateClient(GEONAMES_USER, weatherClient.getLat(0), weatherClient.getLon(0));
geoNames.updateClient(GEONAMES_USER, weatherClient.getLat(0), weatherClient.getLon(0), IS_DST);
UtcOffset = geoNames.getTimeOffset();
timeClient.setUtcOffset(UtcOffset);
}
Expand Down Expand Up @@ -979,7 +987,7 @@ void displayWeatherData() {
}

timeClient.setUtcOffset(getTimeOffset());
String time = geoNames.getMonthName() + " " + geoNames.getDay(false) + ", " + timeClient.getAmPmFormattedTime();
String time = weatherClient.getWeekDay(0, UtcOffset) + ", " + geoNames.getMonthName() + " " + geoNames.getDay(false) + ", " + timeClient.getAmPmFormattedTime();

Serial.println(weatherClient.getCity(0));
Serial.println(weatherClient.getCondition(0));
Expand Down Expand Up @@ -1071,7 +1079,7 @@ float getTimeOffset() {
// we need to get offsets
timeOffsetFetched = true;

geoNames.updateClient(GEONAMES_USER, weatherClient.getLat(0), weatherClient.getLon(0));
geoNames.updateClient(GEONAMES_USER, weatherClient.getLat(0), weatherClient.getLon(0), IS_DST);
UtcOffset = geoNames.getTimeOffset();

return UtcOffset;
Expand Down Expand Up @@ -1218,6 +1226,7 @@ String writeCityIds() {
f.println("newsApiKey=" + NEWS_API_KEY);
f.println("isAdvice=" + String(ADVICE_ENABLED));
f.println("is24hour=" + String(IS_24HOUR));
f.println("isDST=" + String(IS_DST));
f.println("wideclockformat=" + Wide_Clock_Style);
f.println("isMetric=" + String(IS_METRIC));
f.println("refreshRate=" + String(minutesBetweenDataRefresh));
Expand Down Expand Up @@ -1283,6 +1292,10 @@ void readCityIds() {
IS_24HOUR = line.substring(line.lastIndexOf("is24hour=") + 9).toInt();
Serial.println("IS_24HOUR=" + String(IS_24HOUR));
}
if (line.indexOf("isDST=") >= 0) {
IS_DST = line.substring(line.lastIndexOf("isDST=") + 6).toInt();
Serial.println("IS_DST=" + String(IS_DST));
}
if (line.indexOf("wideclockformat=") >= 0) {
Wide_Clock_Style = line.substring(line.lastIndexOf("wideclockformat=") + 16);
Wide_Clock_Style.trim();
Expand Down

0 comments on commit 43909ec

Please sign in to comment.