|
|
|
@ -1,4 +1,4 @@
|
|
|
|
/** The MIT License (MIT)
|
|
|
|
/** The MIT License (MIT)
|
|
|
|
|
|
|
|
|
|
|
|
Copyright (c) 2018 David Payne
|
|
|
|
Copyright (c) 2018 David Payne
|
|
|
|
|
|
|
|
|
|
|
|
@ -27,7 +27,7 @@ SOFTWARE.
|
|
|
|
|
|
|
|
|
|
|
|
#include "Settings.h"
|
|
|
|
#include "Settings.h"
|
|
|
|
|
|
|
|
|
|
|
|
#define VERSION "2.1"
|
|
|
|
#define VERSION "2.2"
|
|
|
|
|
|
|
|
|
|
|
|
#define HOSTNAME "OctMon-"
|
|
|
|
#define HOSTNAME "OctMon-"
|
|
|
|
#define CONFIG "/conf.txt"
|
|
|
|
#define CONFIG "/conf.txt"
|
|
|
|
@ -112,9 +112,11 @@ String CHANGE_FORM = "<form class='w3-container' action='/updateconfig' method=
|
|
|
|
"<p><label>OctoPrint Password </label><input class='w3-input w3-border w3-margin-bottom' type='password' name='octoPass' value='%OCTOPASS%'></p><hr>"
|
|
|
|
"<p><label>OctoPrint Password </label><input class='w3-input w3-border w3-margin-bottom' type='password' name='octoPass' value='%OCTOPASS%'></p><hr>"
|
|
|
|
"<p><input name='isClockEnabled' class='w3-check w3-margin-top' type='checkbox' %IS_CLOCK_CHECKED%> Display Clock when printer is off</p>"
|
|
|
|
"<p><input name='isClockEnabled' class='w3-check w3-margin-top' type='checkbox' %IS_CLOCK_CHECKED%> Display Clock when printer is off</p>"
|
|
|
|
"<p><input name='is24hour' class='w3-check w3-margin-top' type='checkbox' %IS_24HOUR_CHECKED%> Use 24 Hour Clock (military time)</p>"
|
|
|
|
"<p><input name='is24hour' class='w3-check w3-margin-top' type='checkbox' %IS_24HOUR_CHECKED%> Use 24 Hour Clock (military time)</p>"
|
|
|
|
|
|
|
|
"<p><input name='invDisp' class='w3-check w3-margin-top' type='checkbox' %IS_INVDISP_CHECKED%> Flip display orientation</p>"
|
|
|
|
"<p>Clock Sync / Weather Refresh (minutes) <select class='w3-option w3-padding' name='refresh'>%OPTIONS%</select></p>"
|
|
|
|
"<p>Clock Sync / Weather Refresh (minutes) <select class='w3-option w3-padding' name='refresh'>%OPTIONS%</select></p>"
|
|
|
|
"<p>Theme Color <select class='w3-option w3-padding' name='theme'>%THEME_OPTIONS%</select></p>"
|
|
|
|
"<p>Theme Color <select class='w3-option w3-padding' name='theme'>%THEME_OPTIONS%</select></p>"
|
|
|
|
"<p><label>UTC Time Offset</label><input class='w3-input w3-border w3-margin-bottom' type='text' name='utcoffset' value='%UTCOFFSET%' maxlength='12'></p><hr>"
|
|
|
|
"<p><label>UTC Time Offset</label><input class='w3-input w3-border w3-margin-bottom' type='text' name='utcoffset' value='%UTCOFFSET%' maxlength='12'></p><hr>"
|
|
|
|
|
|
|
|
"<p><input name='isBasicAuth' class='w3-check w3-margin-top' type='checkbox' %IS_BASICAUTH_CHECKED%> Use Security Credentials for Configuration Changes</p>"
|
|
|
|
"<p><label>User ID (for this interface)</label><input class='w3-input w3-border w3-margin-bottom' type='text' name='userid' value='%USERID%' maxlength='20'></p>"
|
|
|
|
"<p><label>User ID (for this interface)</label><input class='w3-input w3-border w3-margin-bottom' type='text' name='userid' value='%USERID%' maxlength='20'></p>"
|
|
|
|
"<p><label>Password </label><input class='w3-input w3-border w3-margin-bottom' type='password' name='stationpassword' value='%STATIONPASSWORD%'></p>"
|
|
|
|
"<p><label>Password </label><input class='w3-input w3-border w3-margin-bottom' type='password' name='stationpassword' value='%STATIONPASSWORD%'></p>"
|
|
|
|
"<button class='w3-button w3-block w3-grey w3-section w3-padding' type='submit'>Save</button></form>";
|
|
|
|
"<button class='w3-button w3-block w3-grey w3-section w3-padding' type='submit'>Save</button></form>";
|
|
|
|
@ -285,13 +287,13 @@ void setup() {
|
|
|
|
display.drawString(64, 20, "Enable in Settings.h");
|
|
|
|
display.drawString(64, 20, "Enable in Settings.h");
|
|
|
|
display.display();
|
|
|
|
display.display();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
flashLED(5, 500);
|
|
|
|
flashLED(5, 500);
|
|
|
|
findMDNS(); //go find Octoprint Server by the hostname
|
|
|
|
findMDNS(); //go find Octoprint Server by the hostname
|
|
|
|
|
|
|
|
Serial.println("*** Leaving setup()");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void findMDNS() {
|
|
|
|
void findMDNS() {
|
|
|
|
if (OctoPrintHostName == "") {
|
|
|
|
if (OctoPrintHostName == "" || ENABLE_OTA == false) {
|
|
|
|
return; // nothing to do here
|
|
|
|
return; // nothing to do here
|
|
|
|
}
|
|
|
|
}
|
|
|
|
// We now query our network for 'web servers' service
|
|
|
|
// We now query our network for 'web servers' service
|
|
|
|
@ -373,8 +375,15 @@ void getUpdateTime() {
|
|
|
|
digitalWrite(externalLight, HIGH); // turn off the LED
|
|
|
|
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() {
|
|
|
|
void handleSystemReset() {
|
|
|
|
if (!server.authenticate(www_username, www_password)) {
|
|
|
|
if (!authentication()) {
|
|
|
|
return server.requestAuthentication();
|
|
|
|
return server.requestAuthentication();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
Serial.println("Reset System Configuration");
|
|
|
|
Serial.println("Reset System Configuration");
|
|
|
|
@ -385,7 +394,7 @@ void handleSystemReset() {
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void handleUpdateWeather() {
|
|
|
|
void handleUpdateWeather() {
|
|
|
|
if (!server.authenticate(www_username, www_password)) {
|
|
|
|
if (!authentication()) {
|
|
|
|
return server.requestAuthentication();
|
|
|
|
return server.requestAuthentication();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
DISPLAYWEATHER = server.hasArg("isWeatherEnabled");
|
|
|
|
DISPLAYWEATHER = server.hasArg("isWeatherEnabled");
|
|
|
|
@ -400,7 +409,8 @@ void handleUpdateWeather() {
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void handleUpdateConfig() {
|
|
|
|
void handleUpdateConfig() {
|
|
|
|
if (!server.authenticate(www_username, www_password)) {
|
|
|
|
boolean flipOld = INVERT_DISPLAY;
|
|
|
|
|
|
|
|
if (!authentication()) {
|
|
|
|
return server.requestAuthentication();
|
|
|
|
return server.requestAuthentication();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
OctoPrintApiKey = server.arg("octoPrintApiKey");
|
|
|
|
OctoPrintApiKey = server.arg("octoPrintApiKey");
|
|
|
|
@ -411,6 +421,7 @@ void handleUpdateConfig() {
|
|
|
|
OctoAuthPass = server.arg("octoPass");
|
|
|
|
OctoAuthPass = server.arg("octoPass");
|
|
|
|
DISPLAYCLOCK = server.hasArg("isClockEnabled");
|
|
|
|
DISPLAYCLOCK = server.hasArg("isClockEnabled");
|
|
|
|
IS_24HOUR = server.hasArg("is24hour");
|
|
|
|
IS_24HOUR = server.hasArg("is24hour");
|
|
|
|
|
|
|
|
INVERT_DISPLAY = server.hasArg("invDisp");
|
|
|
|
minutesBetweenDataRefresh = server.arg("refresh").toInt();
|
|
|
|
minutesBetweenDataRefresh = server.arg("refresh").toInt();
|
|
|
|
themeColor = server.arg("theme");
|
|
|
|
themeColor = server.arg("theme");
|
|
|
|
UtcOffset = server.arg("utcoffset").toFloat();
|
|
|
|
UtcOffset = server.arg("utcoffset").toFloat();
|
|
|
|
@ -421,13 +432,19 @@ void handleUpdateConfig() {
|
|
|
|
writeSettings();
|
|
|
|
writeSettings();
|
|
|
|
findMDNS();
|
|
|
|
findMDNS();
|
|
|
|
printerClient.getPrinterJobResults();
|
|
|
|
printerClient.getPrinterJobResults();
|
|
|
|
|
|
|
|
if (INVERT_DISPLAY != flipOld) {
|
|
|
|
|
|
|
|
ui.init();
|
|
|
|
|
|
|
|
if(INVERT_DISPLAY)
|
|
|
|
|
|
|
|
display.flipScreenVertically();
|
|
|
|
|
|
|
|
ui.update();
|
|
|
|
|
|
|
|
}
|
|
|
|
checkDisplay();
|
|
|
|
checkDisplay();
|
|
|
|
lastEpoch = 0;
|
|
|
|
lastEpoch = 0;
|
|
|
|
redirectHome();
|
|
|
|
redirectHome();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void handleWifiReset() {
|
|
|
|
void handleWifiReset() {
|
|
|
|
if (!server.authenticate(www_username, www_password)) {
|
|
|
|
if (!authentication()) {
|
|
|
|
return server.requestAuthentication();
|
|
|
|
return server.requestAuthentication();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
//WiFiManager
|
|
|
|
//WiFiManager
|
|
|
|
@ -439,7 +456,7 @@ void handleWifiReset() {
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void handleWeatherConfigure() {
|
|
|
|
void handleWeatherConfigure() {
|
|
|
|
if (!server.authenticate(www_username, www_password)) {
|
|
|
|
if (!authentication()) {
|
|
|
|
return server.requestAuthentication();
|
|
|
|
return server.requestAuthentication();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
digitalWrite(externalLight, LOW);
|
|
|
|
digitalWrite(externalLight, LOW);
|
|
|
|
@ -479,7 +496,7 @@ void handleWeatherConfigure() {
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void handleConfigure() {
|
|
|
|
void handleConfigure() {
|
|
|
|
if (!server.authenticate(www_username, www_password)) {
|
|
|
|
if (!authentication()) {
|
|
|
|
return server.requestAuthentication();
|
|
|
|
return server.requestAuthentication();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
digitalWrite(externalLight, LOW);
|
|
|
|
digitalWrite(externalLight, LOW);
|
|
|
|
@ -512,6 +529,11 @@ void handleConfigure() {
|
|
|
|
is24hourChecked = "checked='checked'";
|
|
|
|
is24hourChecked = "checked='checked'";
|
|
|
|
}
|
|
|
|
}
|
|
|
|
form.replace("%IS_24HOUR_CHECKED%", is24hourChecked);
|
|
|
|
form.replace("%IS_24HOUR_CHECKED%", is24hourChecked);
|
|
|
|
|
|
|
|
String isInvDisp = "";
|
|
|
|
|
|
|
|
if (INVERT_DISPLAY) {
|
|
|
|
|
|
|
|
isInvDisp = "checked='checked'";
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
form.replace("%IS_INVDISP_CHECKED%", isInvDisp);
|
|
|
|
String options = "<option>10</option><option>15</option><option>20</option><option>30</option><option>60</option>";
|
|
|
|
String options = "<option>10</option><option>15</option><option>20</option><option>30</option><option>60</option>";
|
|
|
|
options.replace(">"+String(minutesBetweenDataRefresh)+"<", " selected>"+String(minutesBetweenDataRefresh)+"<");
|
|
|
|
options.replace(">"+String(minutesBetweenDataRefresh)+"<", " selected>"+String(minutesBetweenDataRefresh)+"<");
|
|
|
|
form.replace("%OPTIONS%", options);
|
|
|
|
form.replace("%OPTIONS%", options);
|
|
|
|
@ -519,6 +541,11 @@ void handleConfigure() {
|
|
|
|
themeOptions.replace(">"+String(themeColor)+"<", " selected>"+String(themeColor)+"<");
|
|
|
|
themeOptions.replace(">"+String(themeColor)+"<", " selected>"+String(themeColor)+"<");
|
|
|
|
form.replace("%THEME_OPTIONS%", themeOptions);
|
|
|
|
form.replace("%THEME_OPTIONS%", themeOptions);
|
|
|
|
form.replace("%UTCOFFSET%", String(UtcOffset));
|
|
|
|
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("%USERID%", String(www_username));
|
|
|
|
form.replace("%STATIONPASSWORD%", String(www_password));
|
|
|
|
form.replace("%STATIONPASSWORD%", String(www_password));
|
|
|
|
|
|
|
|
|
|
|
|
@ -933,10 +960,12 @@ void writeSettings() {
|
|
|
|
f.println("octoPass=" + OctoAuthPass);
|
|
|
|
f.println("octoPass=" + OctoAuthPass);
|
|
|
|
f.println("refreshRate=" + String(minutesBetweenDataRefresh));
|
|
|
|
f.println("refreshRate=" + String(minutesBetweenDataRefresh));
|
|
|
|
f.println("themeColor=" + themeColor);
|
|
|
|
f.println("themeColor=" + themeColor);
|
|
|
|
|
|
|
|
f.println("IS_BASIC_AUTH=" + String(IS_BASIC_AUTH));
|
|
|
|
f.println("www_username=" + String(www_username));
|
|
|
|
f.println("www_username=" + String(www_username));
|
|
|
|
f.println("www_password=" + String(www_password));
|
|
|
|
f.println("www_password=" + String(www_password));
|
|
|
|
f.println("DISPLAYCLOCK=" + String(DISPLAYCLOCK));
|
|
|
|
f.println("DISPLAYCLOCK=" + String(DISPLAYCLOCK));
|
|
|
|
f.println("is24hour=" + String(IS_24HOUR));
|
|
|
|
f.println("is24hour=" + String(IS_24HOUR));
|
|
|
|
|
|
|
|
f.println("invertDisp=" + String(INVERT_DISPLAY));
|
|
|
|
f.println("isWeather=" + String(DISPLAYWEATHER));
|
|
|
|
f.println("isWeather=" + String(DISPLAYWEATHER));
|
|
|
|
f.println("weatherKey=" + WeatherApiKey);
|
|
|
|
f.println("weatherKey=" + WeatherApiKey);
|
|
|
|
f.println("CityID=" + String(CityIDs[0]));
|
|
|
|
f.println("CityID=" + String(CityIDs[0]));
|
|
|
|
@ -1000,6 +1029,10 @@ void readSettings() {
|
|
|
|
themeColor.trim();
|
|
|
|
themeColor.trim();
|
|
|
|
Serial.println("themeColor=" + themeColor);
|
|
|
|
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) {
|
|
|
|
if (line.indexOf("www_username=") >= 0) {
|
|
|
|
String temp = line.substring(line.lastIndexOf("www_username=") + 13);
|
|
|
|
String temp = line.substring(line.lastIndexOf("www_username=") + 13);
|
|
|
|
temp.trim();
|
|
|
|
temp.trim();
|
|
|
|
@ -1020,6 +1053,10 @@ void readSettings() {
|
|
|
|
IS_24HOUR = line.substring(line.lastIndexOf("is24hour=") + 9).toInt();
|
|
|
|
IS_24HOUR = line.substring(line.lastIndexOf("is24hour=") + 9).toInt();
|
|
|
|
Serial.println("IS_24HOUR=" + String(IS_24HOUR));
|
|
|
|
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) {
|
|
|
|
if (line.indexOf("isWeather=") >= 0) {
|
|
|
|
DISPLAYWEATHER = line.substring(line.lastIndexOf("isWeather=") + 10).toInt();
|
|
|
|
DISPLAYWEATHER = line.substring(line.lastIndexOf("isWeather=") + 10).toInt();
|
|
|
|
Serial.println("DISPLAYWEATHER=" + String(DISPLAYWEATHER));
|
|
|
|
Serial.println("DISPLAYWEATHER=" + String(DISPLAYWEATHER));
|
|
|
|
|