diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..dff1ca8 --- /dev/null +++ b/.gitignore @@ -0,0 +1,2 @@ + +printermonitor/my_Settings.h diff --git a/README.md b/README.md index 803273b..c751ef5 100644 --- a/README.md +++ b/README.md @@ -109,7 +109,8 @@ Please do not feel obligated, but donations and tips are warmly welcomed. I hav ## Contributors David Payne -Daniel Eichhorn -- Author of the TimeClient class and OLEDDisplayUi . +Daniel Eichhorn -- Author of the TimeClient class and OLEDDisplayUi +Florian Schütte -- added flip display to web interface Contributing to this software is warmly welcomed. You can do this basically by forking from master, committing modifications and then making a pulling requests to be reviewed (follow the links above diff --git a/printermonitor/Settings.h b/printermonitor/Settings.h index 5cd795c..5bf439c 100644 --- a/printermonitor/Settings.h +++ b/printermonitor/Settings.h @@ -70,6 +70,7 @@ boolean IS_METRIC = false; // false = Imperial and true = Metric 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; // true = require athentication to change configuration settings / false = no auth char* www_username = "admin"; // User account for the Web Interface char* www_password = "password"; // Password for the Web Interface float UtcOffset = -7; // Hour offset from GMT for your timezone @@ -81,8 +82,8 @@ boolean DISPLAYCLOCK = true; // true = Show Clock when not printing / false = const int I2C_DISPLAY_ADDRESS = 0x3c; // I2C Address of your Display (usually 0x3c or 0x3d) const int SDA_PIN = D2; const int SCL_PIN = D5; -const 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 +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 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/printermonitor.ino b/printermonitor/printermonitor.ino index 9914324..1f662f9 100644 --- a/printermonitor/printermonitor.ino +++ b/printermonitor/printermonitor.ino @@ -1,4 +1,4 @@ - /** The MIT License (MIT) +/** The MIT License (MIT) Copyright (c) 2018 David Payne @@ -27,7 +27,7 @@ SOFTWARE. #include "Settings.h" -#define VERSION "2.1" +#define VERSION "2.2" #define HOSTNAME "OctMon-" #define CONFIG "/conf.txt" @@ -112,9 +112,11 @@ String CHANGE_FORM = "
Display Clock when printer is off

" "

Use 24 Hour Clock (military time)

" + "

Flip display orientation

" "

Clock Sync / Weather Refresh (minutes)

" "

Theme Color

" "


" + "

Use Security Credentials for Configuration Changes

" "

" "

" "
"; @@ -285,13 +287,13 @@ void setup() { display.drawString(64, 20, "Enable in Settings.h"); display.display(); } - flashLED(5, 500); findMDNS(); //go find Octoprint Server by the hostname + Serial.println("*** Leaving setup()"); } void findMDNS() { - if (OctoPrintHostName == "") { + if (OctoPrintHostName == "" || ENABLE_OTA == false) { return; // nothing to do here } // We now query our network for 'web servers' service @@ -373,8 +375,15 @@ void getUpdateTime() { digitalWrite(externalLight, HIGH); // turn off the LED } +boolean authentication() { + if (IS_BASIC_AUTH && (strlen(www_username) >= 1 && strlen(www_password) >= 1)) { + return server.authenticate(www_username, www_password); + } + return true; // Authentication not required +} + void handleSystemReset() { - if (!server.authenticate(www_username, www_password)) { + if (!authentication()) { return server.requestAuthentication(); } Serial.println("Reset System Configuration"); @@ -385,7 +394,7 @@ void handleSystemReset() { } void handleUpdateWeather() { - if (!server.authenticate(www_username, www_password)) { + if (!authentication()) { return server.requestAuthentication(); } DISPLAYWEATHER = server.hasArg("isWeatherEnabled"); @@ -400,7 +409,8 @@ void handleUpdateWeather() { } void handleUpdateConfig() { - if (!server.authenticate(www_username, www_password)) { + boolean flipOld = INVERT_DISPLAY; + if (!authentication()) { return server.requestAuthentication(); } OctoPrintApiKey = server.arg("octoPrintApiKey"); @@ -411,6 +421,7 @@ void handleUpdateConfig() { OctoAuthPass = server.arg("octoPass"); DISPLAYCLOCK = server.hasArg("isClockEnabled"); IS_24HOUR = server.hasArg("is24hour"); + INVERT_DISPLAY = server.hasArg("invDisp"); minutesBetweenDataRefresh = server.arg("refresh").toInt(); themeColor = server.arg("theme"); UtcOffset = server.arg("utcoffset").toFloat(); @@ -421,13 +432,19 @@ void handleUpdateConfig() { writeSettings(); findMDNS(); printerClient.getPrinterJobResults(); + if (INVERT_DISPLAY != flipOld) { + ui.init(); + if(INVERT_DISPLAY) + display.flipScreenVertically(); + ui.update(); + } checkDisplay(); lastEpoch = 0; redirectHome(); } void handleWifiReset() { - if (!server.authenticate(www_username, www_password)) { + if (!authentication()) { return server.requestAuthentication(); } //WiFiManager @@ -439,7 +456,7 @@ void handleWifiReset() { } void handleWeatherConfigure() { - if (!server.authenticate(www_username, www_password)) { + if (!authentication()) { return server.requestAuthentication(); } digitalWrite(externalLight, LOW); @@ -479,7 +496,7 @@ void handleWeatherConfigure() { } void handleConfigure() { - if (!server.authenticate(www_username, www_password)) { + if (!authentication()) { return server.requestAuthentication(); } digitalWrite(externalLight, LOW); @@ -512,6 +529,11 @@ void handleConfigure() { is24hourChecked = "checked='checked'"; } form.replace("%IS_24HOUR_CHECKED%", is24hourChecked); + String isInvDisp = ""; + if (INVERT_DISPLAY) { + isInvDisp = "checked='checked'"; + } + form.replace("%IS_INVDISP_CHECKED%", isInvDisp); String options = ""; options.replace(">"+String(minutesBetweenDataRefresh)+"<", " selected>"+String(minutesBetweenDataRefresh)+"<"); form.replace("%OPTIONS%", options); @@ -519,6 +541,11 @@ void handleConfigure() { themeOptions.replace(">"+String(themeColor)+"<", " selected>"+String(themeColor)+"<"); form.replace("%THEME_OPTIONS%", themeOptions); form.replace("%UTCOFFSET%", String(UtcOffset)); + String isUseSecurityChecked = ""; + if (IS_BASIC_AUTH) { + isUseSecurityChecked = "checked='checked'"; + } + form.replace("%IS_BASICAUTH_CHECKED%", isUseSecurityChecked); form.replace("%USERID%", String(www_username)); form.replace("%STATIONPASSWORD%", String(www_password)); @@ -933,10 +960,12 @@ void writeSettings() { f.println("octoPass=" + OctoAuthPass); f.println("refreshRate=" + String(minutesBetweenDataRefresh)); f.println("themeColor=" + themeColor); + f.println("IS_BASIC_AUTH=" + String(IS_BASIC_AUTH)); f.println("www_username=" + String(www_username)); f.println("www_password=" + String(www_password)); f.println("DISPLAYCLOCK=" + String(DISPLAYCLOCK)); f.println("is24hour=" + String(IS_24HOUR)); + f.println("invertDisp=" + String(INVERT_DISPLAY)); f.println("isWeather=" + String(DISPLAYWEATHER)); f.println("weatherKey=" + WeatherApiKey); f.println("CityID=" + String(CityIDs[0])); @@ -1000,6 +1029,10 @@ void readSettings() { themeColor.trim(); Serial.println("themeColor=" + themeColor); } + if (line.indexOf("IS_BASIC_AUTH=") >= 0) { + IS_BASIC_AUTH = line.substring(line.lastIndexOf("IS_BASIC_AUTH=") + 14).toInt(); + Serial.println("IS_BASIC_AUTH=" + String(IS_BASIC_AUTH)); + } if (line.indexOf("www_username=") >= 0) { String temp = line.substring(line.lastIndexOf("www_username=") + 13); temp.trim(); @@ -1020,6 +1053,10 @@ void readSettings() { IS_24HOUR = line.substring(line.lastIndexOf("is24hour=") + 9).toInt(); Serial.println("IS_24HOUR=" + String(IS_24HOUR)); } + if(line.indexOf("invertDisp=") >= 0) { + INVERT_DISPLAY = line.substring(line.lastIndexOf("invertDisp=") + 11).toInt(); + Serial.println("INVERT_DISPLAY=" + String(INVERT_DISPLAY)); + } if (line.indexOf("isWeather=") >= 0) { DISPLAYWEATHER = line.substring(line.lastIndexOf("isWeather=") + 10).toInt(); Serial.println("DISPLAYWEATHER=" + String(DISPLAYWEATHER));