diff --git a/README.md b/README.md index c751ef5..3e7f920 100644 --- a/README.md +++ b/README.md @@ -39,7 +39,8 @@ SOFTWARE. * Sample rate is every 10 seconds when printing * Fully configurable from the web interface (not required to update Settings.h) * Supports OTA (loading firmware over WiFi connection on same LAN) -* Basic Athentication to protect your settings +* Basic Authentication to protect your settings +* Version 2.2 added the ability to update firmware through web interface from a compiled binary * Video: https://youtu.be/niRv9SCgAPk * Detailed build video by Chris Riley: https://youtu.be/Rm-l1FSuJpI @@ -62,6 +63,11 @@ GND -> GND- https://www.thingiverse.com/thing:2884823 -- for the 0.96" OLED Display https://www.thingiverse.com/thing:2934049 -- for the 1.3" OLED Display +## Upgrading from version 2.2 or Higher +Version 2.2 introduced the ability to upgrade pre-compiled firmware from a binary file. In version 2.3 and on you should find binary files that can be uploaded to your printer monitor via the web interface. From the main menu in the web interface select "Firmware Update" and follow the prompts. +* **printermonitor.ino.d1_mini_SSD1306.bin** - compiled for Wemos D1 Mini for the smaller 0.96" SSD1306 OLED (default) +* **printermonitor.ino.d1_mini_SH1106.bin** - compiled for Wemos D1 Mini for the larger 1.3" SH1106 OLED + ## Compiling and Loading to Wemos D1 Mini It is recommended to use Arduino IDE. You will need to configure Arduino IDE to work with the Wemos board and USB port and installed the required USB drivers etc. * USB CH340G drivers: https://wiki.wemos.cc/downloads diff --git a/printermonitor.ino.d1_mini_SH1106.bin b/printermonitor.ino.d1_mini_SH1106.bin new file mode 100644 index 0000000..f2233b9 Binary files /dev/null and b/printermonitor.ino.d1_mini_SH1106.bin differ diff --git a/printermonitor.ino.d1_mini_SSD1306.bin b/printermonitor.ino.d1_mini_SSD1306.bin new file mode 100644 index 0000000..5067f0f Binary files /dev/null and b/printermonitor.ino.d1_mini_SSD1306.bin differ 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 @@ class OpenWeatherMapClient { 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 @@ class OpenWeatherMapClient { 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 1ec0109..c064400 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]/ @@ -86,6 +88,9 @@ const int SCL_PIN = D5; boolean INVERT_DISPLAY = false; // true = pins at top | false = pins at the bottom //#define DISPLAY_SH1106 // Uncomment this line to use the SH1106 display -- SSD1306 is used by default and is most common +// LED Settings +const int externalLight = LED_BUILTIN; // Set to unused pin, like D1, to disable use of built-in LED (LED_BUILTIN) + boolean ENABLE_OTA = true; // this will allow you to load firmware to the device over WiFi (see OTA for ESP8266) String OTA_Password = ""; // Set an OTA password here -- leave blank if you don't want to be prompted for password //****************************** diff --git a/printermonitor/TimeClient.cpp b/printermonitor/TimeClient.cpp index 84d7f1d..b0753e0 100644 --- a/printermonitor/TimeClient.cpp +++ b/printermonitor/TimeClient.cpp @@ -148,5 +148,5 @@ long TimeClient::getCurrentEpoch() { } long TimeClient::getCurrentEpochWithUtcOffset() { - return round(getCurrentEpoch() + 3600 * myUtcOffset + 86400L) % 86400L; -} + return (long)round(getCurrentEpoch() + 3600 * myUtcOffset + 86400L) % 86400L; +} diff --git a/printermonitor/printermonitor.ino b/printermonitor/printermonitor.ino index fb4bb09..21e201b 100644 --- a/printermonitor/printermonitor.ino +++ b/printermonitor/printermonitor.ino @@ -27,7 +27,7 @@ SOFTWARE. #include "Settings.h" -#define VERSION "2.2" +#define VERSION "2.3" #define HOSTNAME "OctMon-" #define CONFIG "/conf.txt" @@ -35,13 +35,11 @@ SOFTWARE. /* Useful Constants */ #define SECS_PER_MIN (60UL) #define SECS_PER_HOUR (3600UL) -#define SECS_PER_DAY (SECS_PER_HOUR * 24L) /* Useful Macros for getting elapsed time */ #define numberOfSeconds(_time_) (_time_ % SECS_PER_MIN) #define numberOfMinutes(_time_) ((_time_ / SECS_PER_MIN) % SECS_PER_MIN) -#define numberOfHours(_time_) (( _time_% SECS_PER_DAY) / SECS_PER_HOUR) -#define elapsedDays(_time_) ( _time_ / SECS_PER_DAY) +#define numberOfHours(_time_) (_time_ / SECS_PER_HOUR) // Initialize the oled display for I2C_DISPLAY_ADDRESS // SDA_PIN and SCL_PIN @@ -88,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); @@ -131,9 +129,44 @@ String WEATHER_FORM = "
city list" "

" "

Use Metric (Celsius)

" + "

Weather Language

" "
" ""; +String LANG_OPTIONS = "" + "" + "" + "" + "" + "" + "" + "" + "" + "" + "" + "" + "" + "" + "" + "" + "" + "" + "" + "" + "" + "" + "" + "" + "" + "" + "" + "" + "" + "" + "" + "" + ""; + String COLOR_THEMES = "" "" "" @@ -159,9 +192,6 @@ String COLOR_THEMES = "" ""; -// Change the externalLight to the pin you wish to use if other than the Built-in LED -int externalLight = LED_BUILTIN; // LED_BUILTIN is is the built in LED on the Wemos - void setup() { Serial.begin(115200); SPIFFS.begin(); @@ -404,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(); @@ -488,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(); @@ -599,6 +632,7 @@ String getHeader(boolean refresh) { String html = ""; html += "Printer Monitor"; + html += ""; html += ""; if (refresh) { html += ""; @@ -682,14 +716,12 @@ void displayPrinterStatus() { html += "Bed Temperature: " + printerClient.getTempBedActual() + "° C
"; int val = printerClient.getProgressPrintTimeLeft().toInt(); - int days = elapsedDays(val); int hours = numberOfHours(val); int minutes = numberOfMinutes(val); int seconds = numberOfSeconds(val); html += "Est. Print Time Left: " + zeroPad(hours) + ":" + zeroPad(minutes) + ":" + zeroPad(seconds) + "
"; val = printerClient.getProgressPrintTime().toInt(); - days = elapsedDays(val); hours = numberOfHours(val); minutes = numberOfMinutes(val); seconds = numberOfSeconds(val); @@ -787,7 +819,6 @@ void drawScreen2(OLEDDisplay *display, OLEDDisplayUiState* state, int16_t x, int //display->setTextAlignment(TEXT_ALIGN_LEFT); display->setFont(ArialMT_Plain_24); int val = printerClient.getProgressPrintTimeLeft().toInt(); - int days = elapsedDays(val); int hours = numberOfHours(val); int minutes = numberOfMinutes(val); int seconds = numberOfSeconds(val); @@ -804,7 +835,6 @@ void drawScreen3(OLEDDisplay *display, OLEDDisplayUiState* state, int16_t x, int //display->setTextAlignment(TEXT_ALIGN_LEFT); display->setFont(ArialMT_Plain_24); int val = printerClient.getProgressPrintTime().toInt(); - int days = elapsedDays(val); int hours = numberOfHours(val); int minutes = numberOfMinutes(val); int seconds = numberOfSeconds(val); @@ -973,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(); @@ -1077,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);