diff --git a/printermonitor/OpenWeatherMapClient.cpp b/printermonitor/OpenWeatherMapClient.cpp index 856775e..e3c7874 100644 --- a/printermonitor/OpenWeatherMapClient.cpp +++ b/printermonitor/OpenWeatherMapClient.cpp @@ -23,8 +23,9 @@ SOFTWARE. #include "OpenWeatherMapClient.h" -OpenWeatherMapClient::OpenWeatherMapClient(String ApiKey, int CityIDs[], int cityCount, boolean isMetric) { +OpenWeatherMapClient::OpenWeatherMapClient(String ApiKey, int CityIDs[], int cityCount, boolean isMetric, String language) { updateCityIdList(CityIDs, cityCount); + updateLanguage(language); myApiKey = ApiKey; setMetric(isMetric); } @@ -33,9 +34,16 @@ void OpenWeatherMapClient::updateWeatherApiKey(String ApiKey) { myApiKey = ApiKey; } +void OpenWeatherMapClient::updateLanguage(String language) { + lang = language; + if (lang == "") { + lang = "en"; + } +} + void OpenWeatherMapClient::updateWeather() { WiFiClient weatherClient; - String apiGetData = "GET /data/2.5/group?id=" + myCityIDs + "&units=" + units + "&cnt=1&APPID=" + myApiKey + " HTTP/1.1"; + String apiGetData = "GET /data/2.5/group?id=" + myCityIDs + "&units=" + units + "&cnt=1&APPID=" + myApiKey + "&lang=" + lang + " HTTP/1.1"; Serial.println("Getting Weather Data"); Serial.println(apiGetData); diff --git a/printermonitor/OpenWeatherMapClient.h b/printermonitor/OpenWeatherMapClient.h index c85d31b..7555447 100644 --- a/printermonitor/OpenWeatherMapClient.h +++ b/printermonitor/OpenWeatherMapClient.h @@ -31,6 +31,7 @@ private: String myCityIDs = ""; String myApiKey = ""; String units = ""; + String lang = ""; const char* servername = "api.openweathermap.org"; // remote server we will connect to String result; @@ -57,10 +58,11 @@ private: String roundValue(String value); public: - OpenWeatherMapClient(String ApiKey, int CityIDs[], int cityCount, boolean isMetric); + OpenWeatherMapClient(String ApiKey, int CityIDs[], int cityCount, boolean isMetric, String language); void updateWeather(); void updateWeatherApiKey(String ApiKey); void updateCityIdList(int CityIDs[], int cityCount); + void updateLanguage(String language); void setMetric(boolean isMetric); String getWeatherResults(); diff --git a/printermonitor/Settings.h b/printermonitor/Settings.h index 4f510fe..5da1794 100644 --- a/printermonitor/Settings.h +++ b/printermonitor/Settings.h @@ -68,6 +68,8 @@ String WeatherApiKey = ""; // Your API Key from http://openweathermap.org/ // Default City Location (use http://openweathermap.org/find to find city ID) int CityIDs[] = { 5304391 }; //Only USE ONE for weather marquee boolean IS_METRIC = false; // false = Imperial and true = Metric +// Languages: ar, bg, ca, cz, de, el, en, fa, fi, fr, gl, hr, hu, it, ja, kr, la, lt, mk, nl, pl, pt, ro, ru, se, sk, sl, es, tr, ua, vi, zh_cn, zh_tw +String WeatherLanguage = "en"; //Default (en) English 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]/ diff --git a/printermonitor/printermonitor.ino b/printermonitor/printermonitor.ino index c91c082..21e201b 100644 --- a/printermonitor/printermonitor.ino +++ b/printermonitor/printermonitor.ino @@ -86,7 +86,7 @@ OctoPrintClient printerClient(OctoPrintApiKey, OctoPrintServer, OctoPrintPort, O int printerCount = 0; // Weather Client -OpenWeatherMapClient weatherClient(WeatherApiKey, CityIDs, 1, IS_METRIC); +OpenWeatherMapClient weatherClient(WeatherApiKey, CityIDs, 1, IS_METRIC, WeatherLanguage); //declairing prototypes void configModeCallback (WiFiManager *myWiFiManager); @@ -129,9 +129,44 @@ String WEATHER_FORM = "
city list" "

" "

Use Metric (Celsius)

" + "

Weather Language

" "
" ""; +String LANG_OPTIONS = "" + "" + "" + "" + "" + "" + "" + "" + "" + "" + "" + "" + "" + "" + "" + "" + "" + "" + "" + "" + "" + "" + "" + "" + "" + "" + "" + "" + "" + "" + "" + "" + ""; + String COLOR_THEMES = "" "" "" @@ -399,6 +434,7 @@ void handleUpdateWeather() { WeatherApiKey = server.arg("openWeatherMapApiKey"); CityIDs[0] = server.arg("city1").toInt(); IS_METRIC = server.hasArg("metric"); + WeatherLanguage = server.arg("language"); writeSettings(); isClockOn = false; // this will force a check for the display checkDisplay(); @@ -483,7 +519,9 @@ void handleWeatherConfigure() { checked = "checked='checked'"; } form.replace("%METRIC%", checked); - + String options = LANG_OPTIONS; + options.replace(">"+String(WeatherLanguage)+"<", " selected>"+String(WeatherLanguage)+"<"); + form.replace("%LANGUAGEOPTIONS%", options); server.sendContent(form); html = getFooter(); @@ -594,6 +632,7 @@ String getHeader(boolean refresh) { String html = ""; html += "Printer Monitor"; + html += ""; html += ""; if (refresh) { html += ""; @@ -964,6 +1003,7 @@ void writeSettings() { f.println("weatherKey=" + WeatherApiKey); f.println("CityID=" + String(CityIDs[0])); f.println("isMetric=" + String(IS_METRIC)); + f.println("language=" + String(WeatherLanguage)); } f.close(); readSettings(); @@ -1068,10 +1108,16 @@ void readSettings() { IS_METRIC = line.substring(line.lastIndexOf("isMetric=") + 9).toInt(); Serial.println("IS_METRIC=" + String(IS_METRIC)); } + if (line.indexOf("language=") >= 0) { + WeatherLanguage = line.substring(line.lastIndexOf("language=") + 9); + WeatherLanguage.trim(); + Serial.println("WeatherLanguage=" + WeatherLanguage); + } } fr.close(); printerClient.updateOctoPrintClient(OctoPrintApiKey, OctoPrintServer, OctoPrintPort, OctoAuthUser, OctoAuthPass); weatherClient.updateWeatherApiKey(WeatherApiKey); + weatherClient.updateLanguage(WeatherLanguage); weatherClient.setMetric(IS_METRIC); weatherClient.updateCityIdList(CityIDs, 1); timeClient.setUtcOffset(UtcOffset); @@ -1160,4 +1206,4 @@ void enableDisplay(boolean enable) { Serial.println("Display was turned OFF: " + timeClient.getFormattedTime()); displayOffEpoch = lastEpoch; } -} +}