Skip to content

Commit

Permalink
add additional weather features
Browse files Browse the repository at this point in the history
Support added for wind direction, barometric pressure, and daily high/low temperatures.
  • Loading branch information
k7bbr authored May 6, 2019
1 parent 9766c7c commit 7206dec
Show file tree
Hide file tree
Showing 3 changed files with 68 additions and 11 deletions.
18 changes: 18 additions & 0 deletions marquee/OpenWeatherMapClient.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -114,13 +114,21 @@ void OpenWeatherMapClient::updateWeather() {
weathers[inx].icon = (const char*)root["list"][inx]["weather"][0]["icon"];
weathers[inx].pressure = (const char*)root["list"][inx]["main"]["pressure"];
weathers[inx].direction = (const char*)root["list"][inx]["wind"]["deg"];
weathers[inx].high = (const char*)root["list"][inx]["main"]["temp_max"];
weathers[inx].low = (const char*)root["list"][inx]["main"]["temp_min"];

if (units == "metric") {
// convert to kph from m/s
float f = (weathers[inx].wind.toFloat() * 3.6);
weathers[inx].wind = String(f);
}

if (units != "metric")
{
float p = (weathers[inx].pressure.toFloat() * 0.0295301); //convert millibars to inches
weathers[inx].pressure = String(p);
}

Serial.println("lat: " + weathers[inx].lat);
Serial.println("lon: " + weathers[inx].lon);
Serial.println("dt: " + weathers[inx].dt);
Expand Down Expand Up @@ -236,6 +244,16 @@ String OpenWeatherMapClient::getPressure(int index)
return weathers[index].pressure;
}

String OpenWeatherMapClient::getHigh(int index)
{
return weathers[index].high;
}

String OpenWeatherMapClient::getLow(int index)
{
return weathers[index].low;
}

String OpenWeatherMapClient::getIcon(int index) {
return weathers[index].icon;
}
Expand Down
4 changes: 4 additions & 0 deletions marquee/OpenWeatherMapClient.h
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,8 @@ class OpenWeatherMapClient {
String error;
String pressure;
String direction;
String high;
String low;
} weather;

weather weathers[5];
Expand Down Expand Up @@ -79,6 +81,8 @@ class OpenWeatherMapClient {
String getDirection(int index);
String getDirectionRounded(int index);
String getPressure(int index);
String getHigh(int index);
String getLow(int index);
String getWeatherId(int index);
String getDescription(int index);
String getIcon(int index);
Expand Down
57 changes: 46 additions & 11 deletions marquee/marquee.ino
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,7 @@ boolean SHOW_HUMIDITY = true;
boolean SHOW_WIND = true;
boolean SHOW_WINDDIR = true;
boolean SHOW_PRESSURE = true;
boolean SHOW_HIGHLOW = true;

// OctoPrint Client
OctoPrintClient printerClient(OctoPrintApiKey, OctoPrintServer, OctoPrintPort, OctoAuthUser, OctoAuthPass);
Expand Down Expand Up @@ -124,6 +125,7 @@ static const char CHANGE_FORM1[] PROGMEM = "<form class='w3-container' action='/
"<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='showpressure' class='w3-check w3-margin-top' type='checkbox' %PRESSURE_CHECKED%> Display Barometric Pressure</p>"
"<p><input name='showhighlow' class='w3-check w3-margin-top' type='checkbox' %HIGHLOW_CHECKED%> Display Daily High/Low Temperatures</p>"
"<p><input name='is24hour' class='w3-check w3-margin-top' type='checkbox' %IS_24HOUR_CHECKED%> Use 24 Hour Clock (military time)</p>";

static const char CHANGE_FORM2[] PROGMEM = "<p><input name='isPM' class='w3-check w3-margin-top' type='checkbox' %IS_PM_CHECKED%> Show PM indicator (only 12h format)</p>"
Expand Down Expand Up @@ -382,17 +384,17 @@ void loop() {

if (SHOW_DATE) {
msg += TimeDB.getDayName() + ", ";
msg += TimeDB.getMonthName() + " " + day() + " ";
msg += TimeDB.getMonthName() + " " + day() + " ";
}
if (SHOW_CITY) {
msg += weatherClient.getCity(0) + " ";
msg += weatherClient.getCity(0) + " ";
}
msg += temperature + getTempSymbol() + " ";
msg += temperature + getTempSymbol() + " ";
if (SHOW_CONDITION) {
msg += description + " ";
msg += description + " ";
}
if (SHOW_HUMIDITY) {
msg += "Humidity:" + weatherClient.getHumidityRounded(0) + "% ";
msg += "Humidity:" + weatherClient.getHumidityRounded(0) + "% ";
}
if (SHOW_WIND) {
msg += "Wind:" + weatherClient.getDirectionRounded(0) + " deg/";
Expand All @@ -401,23 +403,29 @@ void loop() {
//line to show barometric pressure
if (SHOW_PRESSURE)
{
msg += "Pressure:" + weatherClient.getPressure(0) + " mb ";
msg += "Pressure:" + weatherClient.getPressure(0) + getPressureSymbol() + " ";
}
msg += marqueeMessage + " ";
//show high/low temperature

if (SHOW_HIGHLOW)
{
msg += "Daily High/Low Temperatures:" + weatherClient.getHigh(0) + "/" + weatherClient.getLow(0) + " " + getTempSymbol() + " ";
}
msg += marqueeMessage + " ";

if (NEWS_ENABLED) {
msg += " " + NEWS_SOURCE + ": " + newsClient.getTitle(newsIndex) + " ";
msg += " " + NEWS_SOURCE + ": " + newsClient.getTitle(newsIndex) + " ";
newsIndex += 1;
if (newsIndex > 9) {
newsIndex = 0;
}
}
if (OCTOPRINT_ENABLED && printerClient.isPrinting()) {
msg += " " + printerClient.getFileName() + " ";
msg += "(" + printerClient.getProgressCompletion() + "%) ";
msg += " " + printerClient.getFileName() + " ";
msg += "(" + printerClient.getProgressCompletion() + "%) ";
}
if (BitcoinCurrencyCode != "NONE" && BitcoinCurrencyCode != "") {
msg += " Bitcoin: " + bitcoinClient.getRate() + " " + bitcoinClient.getCode() + " ";
msg += " Bitcoin: " + bitcoinClient.getRate() + " " + bitcoinClient.getCode() + " ";
}
if (USE_PIHOLE) {
piholeClient.getPiHoleData(PiHoleServer, PiHolePort);
Expand Down Expand Up @@ -576,6 +584,7 @@ void handleLocations() {
SHOW_HUMIDITY = server.hasArg("showhumidity");
SHOW_WIND = server.hasArg("showwind");
SHOW_PRESSURE = server.hasArg("showpressure");
SHOW_HIGHLOW = server.hasArg("showhighlow");
IS_METRIC = server.hasArg("metric");
marqueeMessage = decodeHtmlString(server.arg("marqueeMsg"));
timeDisplayTurnsOn = decodeHtmlString(server.arg("startTime"));
Expand Down Expand Up @@ -839,6 +848,14 @@ void handleConfigure() {
isPressureChecked = "checked='checked'";
}
form.replace("%PRESSURE_CHECKED%", isPressureChecked);

String isHighlowChecked = "";
if (SHOW_HIGHLOW) {
isHighlowChecked = "checked='checked'";
}
form.replace("%HIGHLOW_CHECKED%", isHighlowChecked);


String is24hourChecked = "";
if (IS_24HOUR) {
is24hourChecked = "checked='checked'";
Expand Down Expand Up @@ -1100,6 +1117,7 @@ void displayWeatherData() {
html += "<div class='w3-cell w3-container' style='width:100%'><p>";
html += weatherClient.getCondition(0) + " (" + weatherClient.getDescription(0) + ")<br>";
html += temperature + " " + getTempSymbol() + "<br>";
html += weatherClient.getHigh(0) + "/" + weatherClient.getLow(0) + " " + getTempSymbol() + "<br>";
html += time + "<br>";
html += "<a href='https://www.google.com/maps/@" + weatherClient.getLat(0) + "," + weatherClient.getLon(0) + ",10000m/data=!3m1!1e3' target='_BLANK'><i class='fas fa-map-marker' style='color:red'></i> Map It!</a><br>";
html += "</p></div></div><hr>";
Expand Down Expand Up @@ -1212,6 +1230,16 @@ String getSpeedSymbol() {
return rtnValue;
}

String getPressureSymbol()
{
String rtnValue = "";
if (IS_METRIC)
{
rtnValue = "mb";
}
return rtnValue;
}

// converts the dBm to a range between 0 and 100%
int8_t getWifiQuality() {
int32_t dbm = WiFi.RSSI();
Expand Down Expand Up @@ -1335,6 +1363,7 @@ String writeCityIds() {
f.println("SHOW_HUMIDITY=" + String(SHOW_HUMIDITY));
f.println("SHOW_WIND=" + String(SHOW_WIND));
f.println("SHOW_PRESSURE=" + String(SHOW_PRESSURE));
f.println("SHOW_HIGHLOW=" + String(SHOW_HIGHLOW));
f.println("SHOW_DATE=" + String(SHOW_DATE));
f.println("USE_PIHOLE=" + String(USE_PIHOLE));
f.println("PiHoleServer=" + PiHoleServer);
Expand Down Expand Up @@ -1514,6 +1543,12 @@ void readCityIds() {
SHOW_PRESSURE = line.substring(line.lastIndexOf("SHOW_PRESSURE=") + 14).toInt();
Serial.println("SHOW_PRESSURE=" + String(SHOW_PRESSURE));
}

if (line.indexOf("SHOW_HIGHLOW=") >= 0) {
SHOW_HIGHLOW = line.substring(line.lastIndexOf("SHOW_HIGHLOW=") + 13).toInt();
Serial.println("SHOW_HIGHLOW=" + String(SHOW_HIGHLOW));
}

if (line.indexOf("SHOW_DATE=") >= 0) {
SHOW_DATE = line.substring(line.lastIndexOf("SHOW_DATE=") + 10).toInt();
Serial.println("SHOW_DATE=" + String(SHOW_DATE));
Expand Down

0 comments on commit 7206dec

Please sign in to comment.