Merge pull request #70 from Qrome/2.4

2.4
pull/74/head V2.4
Qrome 2019-01-18 10:39:02 -07:00 committed by GitHub
commit 221c6f9609
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
9 changed files with 1853 additions and 1693 deletions

View File

@ -41,6 +41,7 @@ SOFTWARE.
* Supports OTA (loading firmware over WiFi connection on same LAN) * Supports OTA (loading firmware over WiFi connection on same LAN)
* Basic Authentication 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 * Version 2.2 added the ability to update firmware through web interface from a compiled binary
* Can query the Octoprint [PSU Control plugin](https://plugins.octoprint.org/plugins/psucontrol/) to enter clock or blank mode when PSU is off
* Video: https://youtu.be/niRv9SCgAPk * Video: https://youtu.be/niRv9SCgAPk
* Detailed build video by Chris Riley: https://youtu.be/Rm-l1FSuJpI * Detailed build video by Chris Riley: https://youtu.be/Rm-l1FSuJpI
@ -114,9 +115,10 @@ Please do not feel obligated, but donations and tips are warmly welcomed. I hav
[![paypal](https://www.paypalobjects.com/en_US/i/btn/btn_donateCC_LG.gif)](https://www.paypal.com/cgi-bin/webscr?cmd=_s-xclick&hosted_button_id=6VPMTLASLSKWE) [![paypal](https://www.paypalobjects.com/en_US/i/btn/btn_donateCC_LG.gif)](https://www.paypal.com/cgi-bin/webscr?cmd=_s-xclick&hosted_button_id=6VPMTLASLSKWE)
## Contributors ## Contributors
David Payne David Payne -- Principal developer and architect
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 Florian Schütte -- added flip display to web interface
Owen Carter -- Added psu control setting (v2.4)
Contributing to this software is warmly welcomed. You can do this basically by 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 forking from master, committing modifications and then making a pulling requests to be reviewed (follow the links above

Binary file not shown.

Binary file not shown.

View File

@ -21,13 +21,16 @@ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE. SOFTWARE.
*/ */
// Additional Contributions:
/* 15 Jan 2019 : Owen Carter : Add psucontrol query via POST api call */
#include "OctoPrintClient.h" #include "OctoPrintClient.h"
OctoPrintClient::OctoPrintClient(String ApiKey, String server, int port, String user, String pass) { OctoPrintClient::OctoPrintClient(String ApiKey, String server, int port, String user, String pass, boolean psu) {
updateOctoPrintClient(ApiKey, server, port, user, pass); updateOctoPrintClient(ApiKey, server, port, user, pass, psu);
} }
void OctoPrintClient::updateOctoPrintClient(String ApiKey, String server, int port, String user, String pass) { void OctoPrintClient::updateOctoPrintClient(String ApiKey, String server, int port, String user, String pass, boolean psu) {
server.toCharArray(myServer, 100); server.toCharArray(myServer, 100);
myApiKey = ApiKey; myApiKey = ApiKey;
myPort = port; myPort = port;
@ -37,6 +40,7 @@ void OctoPrintClient::updateOctoPrintClient(String ApiKey, String server, int po
base64 b64; base64 b64;
encodedAuth = b64.encode(userpass, true); encodedAuth = b64.encode(userpass, true);
} }
pollPsu = psu;
} }
boolean OctoPrintClient::validate() { boolean OctoPrintClient::validate() {
@ -58,7 +62,7 @@ WiFiClient OctoPrintClient::getSubmitRequest(String apiGetData) {
WiFiClient printClient; WiFiClient printClient;
printClient.setTimeout(5000); printClient.setTimeout(5000);
Serial.println("Getting Octoprint Data"); Serial.println("Getting Octoprint Data via GET");
Serial.println(apiGetData); Serial.println(apiGetData);
result = ""; result = "";
if (printClient.connect(myServer, myPort)) { //starts client connection, checks for connection if (printClient.connect(myServer, myPort)) { //starts client connection, checks for connection
@ -109,18 +113,76 @@ WiFiClient OctoPrintClient::getSubmitRequest(String apiGetData) {
return printClient; return printClient;
} }
WiFiClient OctoPrintClient::getPostRequest(String apiPostData, String apiPostBody) {
WiFiClient printClient;
printClient.setTimeout(5000);
Serial.println("Getting Octoprint Data via POST");
Serial.println(apiPostData + " | " + apiPostBody);
result = "";
if (printClient.connect(myServer, myPort)) { //starts client connection, checks for connection
printClient.println(apiPostData);
printClient.println("Host: " + String(myServer) + ":" + String(myPort));
printClient.println("Connection: close");
printClient.println("X-Api-Key: " + myApiKey);
if (encodedAuth != "") {
printClient.print("Authorization: ");
printClient.println("Basic " + encodedAuth);
}
printClient.println("User-Agent: ArduinoWiFi/1.1");
printClient.println("Content-Type: application/json");
printClient.print("Content-Length: ");
printClient.println(apiPostBody.length());
printClient.println();
printClient.println(apiPostBody);
if (printClient.println() == 0) {
Serial.println("Connection to " + String(myServer) + ":" + String(myPort) + " failed.");
Serial.println();
resetPrintData();
printerData.error = "Connection to " + String(myServer) + ":" + String(myPort) + " failed.";
return printClient;
}
}
else {
Serial.println("Connection to OctoPrint failed: " + String(myServer) + ":" + String(myPort)); //error message if no client connect
Serial.println();
resetPrintData();
printerData.error = "Connection to OctoPrint failed: " + String(myServer) + ":" + String(myPort);
return printClient;
}
// Check HTTP status
char status[32] = {0};
printClient.readBytesUntil('\r', status, sizeof(status));
if (strcmp(status, "HTTP/1.1 200 OK") != 0 && strcmp(status, "HTTP/1.1 409 CONFLICT") != 0) {
Serial.print(F("Unexpected response: "));
Serial.println(status);
printerData.state = "";
printerData.error = "Response: " + String(status);
return printClient;
}
// Skip HTTP headers
char endOfHeaders[] = "\r\n\r\n";
if (!printClient.find(endOfHeaders)) {
Serial.println(F("Invalid response"));
printerData.error = "Invalid response from " + String(myServer) + ":" + String(myPort);
printerData.state = "";
}
return printClient;
}
void OctoPrintClient::getPrinterJobResults() { void OctoPrintClient::getPrinterJobResults() {
if (!validate()) { if (!validate()) {
return; return;
} }
//**** get the Printer Job status
String apiGetData = "GET /api/job HTTP/1.1"; String apiGetData = "GET /api/job HTTP/1.1";
WiFiClient printClient = getSubmitRequest(apiGetData); WiFiClient printClient = getSubmitRequest(apiGetData);
if (printerData.error != "") { if (printerData.error != "") {
return; return;
} }
const size_t bufferSize = JSON_OBJECT_SIZE(1) + JSON_OBJECT_SIZE(2) + JSON_OBJECT_SIZE(3) + 2*JSON_OBJECT_SIZE(5) + JSON_OBJECT_SIZE(6) + 710; const size_t bufferSize = JSON_OBJECT_SIZE(1) + JSON_OBJECT_SIZE(2) + JSON_OBJECT_SIZE(3) + 2*JSON_OBJECT_SIZE(5) + JSON_OBJECT_SIZE(6) + 710;
DynamicJsonBuffer jsonBuffer(bufferSize); DynamicJsonBuffer jsonBuffer(bufferSize);
@ -148,7 +210,7 @@ void OctoPrintClient::getPrinterJobResults() {
if (isOperational()) { if (isOperational()) {
Serial.println("Status: " + printerData.state); Serial.println("Status: " + printerData.state);
} else { } else {
Serial.println("Printer Not Opperational"); Serial.println("Printer Not Operational");
} }
//**** get the Printer Temps and Stat //**** get the Printer Temps and Stat
@ -183,8 +245,42 @@ void OctoPrintClient::getPrinterJobResults() {
if (isPrinting()) { if (isPrinting()) {
Serial.println("Status: " + printerData.state + " " + printerData.fileName + "(" + printerData.progressCompletion + "%)"); Serial.println("Status: " + printerData.state + " " + printerData.fileName + "(" + printerData.progressCompletion + "%)");
} }
}
void OctoPrintClient::getPrinterPsuState() {
//**** get the PSU state (if enabled and printer operational)
if (pollPsu && isOperational()) {
if (!validate()) {
printerData.isPSUoff = false; // we do not know PSU state, so assume on.
return;
}
String apiPostData = "POST /api/plugin/psucontrol HTTP/1.1";
String apiPostBody = "{\"command\":\"getPSUState\"}";
WiFiClient printClient = getPostRequest(apiPostData,apiPostBody);
if (printerData.error != "") {
printerData.isPSUoff = false; // we do not know PSU state, so assume on.
return;
}
const size_t bufferSize3 = JSON_OBJECT_SIZE(2) + 300;
DynamicJsonBuffer jsonBuffer3(bufferSize3);
// Parse JSON object
JsonObject& root3 = jsonBuffer3.parseObject(printClient);
if (!root3.success()) {
printerData.isPSUoff = false; // we do not know PSU state, so assume on
return;
}
String psu = (const char*)root3["isPSUOn"];
if (psu == "true") {
printerData.isPSUoff = false; // PSU checked and is on
} else {
printerData.isPSUoff = true; // PSU checked and is off, set flag
}
printClient.stop(); //stop client printClient.stop(); //stop client
} else {
printerData.isPSUoff = false; // we are not checking PSU state, so assume on
}
} }
// Reset all PrinterData // Reset all PrinterData
@ -205,6 +301,7 @@ void OctoPrintClient::resetPrintData() {
printerData.bedTemp = ""; printerData.bedTemp = "";
printerData.bedTargetTemp = ""; printerData.bedTargetTemp = "";
printerData.isPrinting = false; printerData.isPrinting = false;
printerData.isPSUoff = false;
printerData.error = ""; printerData.error = "";
} }
@ -256,6 +353,10 @@ boolean OctoPrintClient::isPrinting() {
return printerData.isPrinting; return printerData.isPrinting;
} }
boolean OctoPrintClient::isPSUoff() {
return printerData.isPSUoff;
}
boolean OctoPrintClient::isOperational() { boolean OctoPrintClient::isOperational() {
boolean operational = false; boolean operational = false;
if (printerData.state == "Operational" || isPrinting()) { if (printerData.state == "Operational" || isPrinting()) {

View File

@ -21,6 +21,9 @@ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE. SOFTWARE.
*/ */
// Additional Contributions:
/* 15 Jan 2019 : Owen Carter : Add psucontrol query via POST api call */
#pragma once #pragma once
#include <ESP8266WiFi.h> #include <ESP8266WiFi.h>
#include <ArduinoJson.h> #include <ArduinoJson.h>
@ -33,10 +36,12 @@ private:
int myPort = 80; int myPort = 80;
String myApiKey = ""; String myApiKey = "";
String encodedAuth = ""; String encodedAuth = "";
boolean pollPsu;
void resetPrintData(); void resetPrintData();
boolean validate(); boolean validate();
WiFiClient getSubmitRequest(String apiGetData); WiFiClient getSubmitRequest(String apiGetData);
WiFiClient getPostRequest(String apiPostData, String apiPostBody);
String result; String result;
@ -57,6 +62,7 @@ private:
String bedTemp; String bedTemp;
String bedTargetTemp; String bedTargetTemp;
boolean isPrinting; boolean isPrinting;
boolean isPSUoff;
String error; String error;
} PrinterStruct; } PrinterStruct;
@ -64,9 +70,10 @@ private:
public: public:
OctoPrintClient(String ApiKey, String server, int port, String user, String pass); OctoPrintClient(String ApiKey, String server, int port, String user, String pass, boolean psu);
void getPrinterJobResults(); void getPrinterJobResults();
void updateOctoPrintClient(String ApiKey, String server, int port, String user, String pass); void getPrinterPsuState();
void updateOctoPrintClient(String ApiKey, String server, int port, String user, String pass, boolean psu);
String getAveragePrintTime(); String getAveragePrintTime();
String getEstimatedPrintTime(); String getEstimatedPrintTime();
@ -80,6 +87,7 @@ public:
String getState(); String getState();
boolean isPrinting(); boolean isPrinting();
boolean isOperational(); boolean isOperational();
boolean isPSUoff();
String getTempBedActual(); String getTempBedActual();
String getTempBedTarget(); String getTempBedTarget();
String getTempToolActual(); String getTempToolActual();
@ -88,4 +96,3 @@ public:
String getValueRounded(String value); String getValueRounded(String value);
String getError(); String getError();
}; };

View File

@ -21,6 +21,9 @@ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE. SOFTWARE.
*/ */
// Additional Contributions:
/* 15 Jan 2019 : Owen Carter : Add psucontrol setting */
/****************************************************************************** /******************************************************************************
* Printer Monitor is designed for the Wemos D1 ESP8266 * Printer Monitor is designed for the Wemos D1 ESP8266
* Wemos D1 Mini: https://amzn.to/2qLyKJd * Wemos D1 Mini: https://amzn.to/2qLyKJd
@ -71,11 +74,14 @@ 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 // 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 String WeatherLanguage = "en"; //Default (en) English
// Webserver
const int WEBSERVER_PORT = 80; // The port you can access this device on over HTTP 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]/ 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 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_username = "admin"; // User account for the Web Interface
char* www_password = "password"; // Password for the Web Interface char* www_password = "password"; // Password for the Web Interface
// Date and Time
float UtcOffset = -7; // Hour offset from GMT for your timezone float UtcOffset = -7; // Hour offset from GMT for your timezone
boolean IS_24HOUR = false; // 23:00 millitary 24 hour clock boolean IS_24HOUR = false; // 23:00 millitary 24 hour clock
int minutesBetweenDataRefresh = 15; int minutesBetweenDataRefresh = 15;
@ -91,8 +97,13 @@ boolean INVERT_DISPLAY = false; // true = pins at top | false = pins at the bott
// LED Settings // LED Settings
const int externalLight = LED_BUILTIN; // Set to unused pin, like D1, to disable use of built-in LED (LED_BUILTIN) const int externalLight = LED_BUILTIN; // Set to unused pin, like D1, to disable use of built-in LED (LED_BUILTIN)
// PSU Control
boolean HAS_PSU = false; // Set to true if https://github.com/kantlivelong/OctoPrint-PSUControl/ in use
// OTA Updates
boolean ENABLE_OTA = true; // this will allow you to load firmware to the device over WiFi (see OTA for ESP8266) 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 String OTA_Password = ""; // Set an OTA password here -- leave blank if you don't want to be prompted for password
//****************************** //******************************
// End Settings // End Settings
//****************************** //******************************

View File

@ -21,13 +21,16 @@ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE. SOFTWARE.
*/ */
// Additional Contributions:
/* 15 Jan 2019 : Owen Carter : Add psucontrol option and processing */
/********************************************** /**********************************************
* Edit Settings.h for personalization * Edit Settings.h for personalization
***********************************************/ ***********************************************/
#include "Settings.h" #include "Settings.h"
#define VERSION "2.3" #define VERSION "2.4"
#define HOSTNAME "OctMon-" #define HOSTNAME "OctMon-"
#define CONFIG "/conf.txt" #define CONFIG "/conf.txt"
@ -82,7 +85,7 @@ String lastReportStatus = "";
boolean displayOn = true; boolean displayOn = true;
// OctoPrint Client // OctoPrint Client
OctoPrintClient printerClient(OctoPrintApiKey, OctoPrintServer, OctoPrintPort, OctoAuthUser, OctoAuthPass); OctoPrintClient printerClient(OctoPrintApiKey, OctoPrintServer, OctoPrintPort, OctoAuthUser, OctoAuthPass, HAS_PSU);
int printerCount = 0; int printerCount = 0;
// Weather Client // Weather Client
@ -113,8 +116,10 @@ String CHANGE_FORM = "<form class='w3-container' action='/updateconfig' method=
"<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><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><input name='hasPSU' class='w3-check w3-margin-top' type='checkbox' %HAS_PSU_CHECKED%> Use OctoPrint PSU control plugin for clock/blank</p>"
"<p>Theme Color <select class='w3-option w3-padding' name='theme'>%THEME_OPTIONS%</select></p>" "<p>Clock Sync / Weather Refresh (minutes) <select class='w3-option w3-padding' name='refresh'>%OPTIONS%</select></p>";
String THEME_FORM = "<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><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>"
@ -205,7 +210,7 @@ void setup() {
readSettings(); readSettings();
// initialize dispaly // initialize display
display.init(); display.init();
if (INVERT_DISPLAY) { if (INVERT_DISPLAY) {
display.flipScreenVertically(); // connections at top of OLED display display.flipScreenVertically(); // connections at top of OLED display
@ -367,6 +372,7 @@ void loop() {
digitalWrite(externalLight, LOW); digitalWrite(externalLight, LOW);
lastMinute = timeClient.getMinutes(); // reset the check value lastMinute = timeClient.getMinutes(); // reset the check value
printerClient.getPrinterJobResults(); printerClient.getPrinterJobResults();
printerClient.getPrinterPsuState();
digitalWrite(externalLight, HIGH); digitalWrite(externalLight, HIGH);
} else if (printerClient.isPrinting()) { } else if (printerClient.isPrinting()) {
if (lastSecond != timeClient.getSeconds() && timeClient.getSeconds().endsWith("0")) { if (lastSecond != timeClient.getSeconds() && timeClient.getSeconds().endsWith("0")) {
@ -374,6 +380,7 @@ void loop() {
// every 10 seconds while printing get an update // every 10 seconds while printing get an update
digitalWrite(externalLight, LOW); digitalWrite(externalLight, LOW);
printerClient.getPrinterJobResults(); printerClient.getPrinterJobResults();
printerClient.getPrinterPsuState();
digitalWrite(externalLight, HIGH); digitalWrite(externalLight, HIGH);
} }
} }
@ -456,6 +463,7 @@ void handleUpdateConfig() {
DISPLAYCLOCK = server.hasArg("isClockEnabled"); DISPLAYCLOCK = server.hasArg("isClockEnabled");
IS_24HOUR = server.hasArg("is24hour"); IS_24HOUR = server.hasArg("is24hour");
INVERT_DISPLAY = server.hasArg("invDisp"); INVERT_DISPLAY = server.hasArg("invDisp");
HAS_PSU = server.hasArg("hasPSU");
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();
@ -466,6 +474,7 @@ void handleUpdateConfig() {
writeSettings(); writeSettings();
findMDNS(); findMDNS();
printerClient.getPrinterJobResults(); printerClient.getPrinterJobResults();
printerClient.getPrinterPsuState();
if (INVERT_DISPLAY != flipOld) { if (INVERT_DISPLAY != flipOld) {
ui.init(); ui.init();
if(INVERT_DISPLAY) if(INVERT_DISPLAY)
@ -570,9 +579,20 @@ void handleConfigure() {
isInvDisp = "checked='checked'"; isInvDisp = "checked='checked'";
} }
form.replace("%IS_INVDISP_CHECKED%", isInvDisp); form.replace("%IS_INVDISP_CHECKED%", isInvDisp);
String hasPSUchecked = "";
if (HAS_PSU) {
hasPSUchecked = "checked='checked'";
}
form.replace("%HAS_PSU_CHECKED%", hasPSUchecked);
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);
server.sendContent(form);
form = THEME_FORM;
String themeOptions = COLOR_THEMES; String themeOptions = COLOR_THEMES;
themeOptions.replace(">"+String(themeColor)+"<", " selected>"+String(themeColor)+"<"); themeOptions.replace(">"+String(themeColor)+"<", " selected>"+String(themeColor)+"<");
form.replace("%THEME_OPTIONS%", themeOptions); form.replace("%THEME_OPTIONS%", themeOptions);
@ -695,9 +715,15 @@ void displayPrinterStatus() {
html += "<div class='w3-cell w3-container' style='width:100%'><p>"; html += "<div class='w3-cell w3-container' style='width:100%'><p>";
html += "Host Name: " + OctoPrintHostName + "<br>"; html += "Host Name: " + OctoPrintHostName + "<br>";
if (printerClient.getError() != "") { if (printerClient.getError() != "") {
html += "Error: " + printerClient.getError() + "<br>"; html += "Status: Offline<br>";
html += "Reason: " + printerClient.getError() + "<br>";
} else {
html += "Status: " + printerClient.getState();
if (printerClient.isPSUoff() && HAS_PSU) {
html += ", PSU off";
}
html += "<br>";
} }
html += "Status: " + printerClient.getState() + "<br>";
if (printerClient.isPrinting()) { if (printerClient.isPrinting()) {
html += "File: " + printerClient.getFileName() + "<br>"; html += "File: " + printerClient.getFileName() + "<br>";
@ -941,9 +967,17 @@ void drawClockHeaderOverlay(OLEDDisplay *display, OLEDDisplayUiState* state) {
if (!IS_24HOUR) { if (!IS_24HOUR) {
display->drawString(0, 48, timeClient.getAmPm()); display->drawString(0, 48, timeClient.getAmPm());
display->setTextAlignment(TEXT_ALIGN_CENTER); display->setTextAlignment(TEXT_ALIGN_CENTER);
display->drawString(64, 48, "offline"); if (printerClient.isPSUoff()) {
display->drawString(64, 47, "psu off");
} else { } else {
display->drawString(0,48, "offline"); display->drawString(64, 47, "offline");
}
} else {
if (printerClient.isPSUoff()) {
display->drawString(0, 47, "psu off");
} else {
display->drawString(0, 47, "offline");
}
} }
display->setTextAlignment(TEXT_ALIGN_LEFT); display->setTextAlignment(TEXT_ALIGN_LEFT);
display->drawRect(0, 43, 128, 2); display->drawRect(0, 43, 128, 2);
@ -1004,6 +1038,7 @@ void writeSettings() {
f.println("CityID=" + String(CityIDs[0])); f.println("CityID=" + String(CityIDs[0]));
f.println("isMetric=" + String(IS_METRIC)); f.println("isMetric=" + String(IS_METRIC));
f.println("language=" + String(WeatherLanguage)); f.println("language=" + String(WeatherLanguage));
f.println("hasPSU=" + String(HAS_PSU));
} }
f.close(); f.close();
readSettings(); readSettings();
@ -1091,6 +1126,10 @@ void readSettings() {
INVERT_DISPLAY = line.substring(line.lastIndexOf("invertDisp=") + 11).toInt(); INVERT_DISPLAY = line.substring(line.lastIndexOf("invertDisp=") + 11).toInt();
Serial.println("INVERT_DISPLAY=" + String(INVERT_DISPLAY)); Serial.println("INVERT_DISPLAY=" + String(INVERT_DISPLAY));
} }
if (line.indexOf("hasPSU=") >= 0) {
HAS_PSU = line.substring(line.lastIndexOf("hasPSU=") + 7).toInt();
Serial.println("HAS_PSU=" + String(HAS_PSU));
}
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));
@ -1115,7 +1154,7 @@ void readSettings() {
} }
} }
fr.close(); fr.close();
printerClient.updateOctoPrintClient(OctoPrintApiKey, OctoPrintServer, OctoPrintPort, OctoAuthUser, OctoAuthPass); printerClient.updateOctoPrintClient(OctoPrintApiKey, OctoPrintServer, OctoPrintPort, OctoAuthUser, OctoAuthPass, HAS_PSU);
weatherClient.updateWeatherApiKey(WeatherApiKey); weatherClient.updateWeatherApiKey(WeatherApiKey);
weatherClient.updateLanguage(WeatherLanguage); weatherClient.updateLanguage(WeatherLanguage);
weatherClient.setMetric(IS_METRIC); weatherClient.setMetric(IS_METRIC);
@ -1167,7 +1206,7 @@ void checkDisplay() {
return; return;
} }
} else if (DISPLAYCLOCK) { } else if (DISPLAYCLOCK) {
if (!printerClient.isOperational() && !isClockOn) { if ((!printerClient.isOperational() || printerClient.isPSUoff()) && !isClockOn) {
Serial.println("Clock Mode is turned on."); Serial.println("Clock Mode is turned on.");
if (!DISPLAYWEATHER) { if (!DISPLAYWEATHER) {
ui.disableAutoTransition(); ui.disableAutoTransition();
@ -1181,7 +1220,7 @@ void checkDisplay() {
} }
ui.setOverlays(clockOverlay, numberOfOverlays); ui.setOverlays(clockOverlay, numberOfOverlays);
isClockOn = true; isClockOn = true;
} else if (printerClient.isOperational() && isClockOn) { } else if (printerClient.isOperational() && !printerClient.isPSUoff() && isClockOn) {
Serial.println("Printer Monitor is active."); Serial.println("Printer Monitor is active.");
ui.setFrames(frames, numberOfFrames); ui.setFrames(frames, numberOfFrames);
ui.setOverlays(overlays, numberOfOverlays); ui.setOverlays(overlays, numberOfOverlays);