From 7206dec37ad669283817fff525a74110b621cf12 Mon Sep 17 00:00:00 2001
From: Brandon
Date: Sun, 5 May 2019 19:57:49 -0600
Subject: [PATCH] add additional weather features
Support added for wind direction, barometric pressure, and daily high/low temperatures.
---
marquee/OpenWeatherMapClient.cpp | 18 ++++++++++
marquee/OpenWeatherMapClient.h | 4 +++
marquee/marquee.ino | 57 ++++++++++++++++++++++++++------
3 files changed, 68 insertions(+), 11 deletions(-)
diff --git a/marquee/OpenWeatherMapClient.cpp b/marquee/OpenWeatherMapClient.cpp
index 9a9608b..8d4e05b 100644
--- a/marquee/OpenWeatherMapClient.cpp
+++ b/marquee/OpenWeatherMapClient.cpp
@@ -114,6 +114,8 @@ 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
@@ -121,6 +123,12 @@ void OpenWeatherMapClient::updateWeather() {
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);
@@ -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;
}
diff --git a/marquee/OpenWeatherMapClient.h b/marquee/OpenWeatherMapClient.h
index 2b34a97..636acd0 100644
--- a/marquee/OpenWeatherMapClient.h
+++ b/marquee/OpenWeatherMapClient.h
@@ -51,6 +51,8 @@ class OpenWeatherMapClient {
String error;
String pressure;
String direction;
+ String high;
+ String low;
} weather;
weather weathers[5];
@@ -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);
diff --git a/marquee/marquee.ino b/marquee/marquee.ino
index ec4828f..6f615d3 100644
--- a/marquee/marquee.ino
+++ b/marquee/marquee.ino
@@ -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);
@@ -124,6 +125,7 @@ static const char CHANGE_FORM1[] PROGMEM = "
"
" Display Wind
"
" Display Barometric Pressure
"
+ " Display Daily High/Low Temperatures
"
" Use 24 Hour Clock (military time)
";
static const char CHANGE_FORM2[] PROGMEM = " Show PM indicator (only 12h format)
"
@@ -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/";
@@ -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);
@@ -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"));
@@ -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'";
@@ -1100,6 +1117,7 @@ void displayWeatherData() {
html += "";
html += weatherClient.getCondition(0) + " (" + weatherClient.getDescription(0) + ")
";
html += temperature + " " + getTempSymbol() + "
";
+ html += weatherClient.getHigh(0) + "/" + weatherClient.getLow(0) + " " + getTempSymbol() + "
";
html += time + "
";
html += " Map It!
";
html += "
";
@@ -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();
@@ -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);
@@ -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));