Qrome - updated to include the compile options for Repetier

pull/99/head
David Payne 2019-04-11 16:23:58 -07:00
parent 30da7285a3
commit c7453a2883
8 changed files with 2332 additions and 2324 deletions

View File

@ -27,10 +27,10 @@ SOFTWARE.
#include "OctoPrintClient.h" #include "OctoPrintClient.h"
OctoPrintClient::OctoPrintClient(String ApiKey, String server, int port, String user, String pass, boolean psu) { OctoPrintClient::OctoPrintClient(String ApiKey, String server, int port, String user, String pass, boolean psu) {
updateOctoPrintClient(ApiKey, server, port, user, pass, psu); updatePrintClient(ApiKey, server, port, user, pass, psu);
} }
void OctoPrintClient::updateOctoPrintClient(String ApiKey, String server, int port, String user, String pass, boolean psu) { void OctoPrintClient::updatePrintClient(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;

View File

@ -73,7 +73,7 @@ public:
OctoPrintClient(String ApiKey, String server, int port, String user, String pass, boolean psu); OctoPrintClient(String ApiKey, String server, int port, String user, String pass, boolean psu);
void getPrinterJobResults(); void getPrinterJobResults();
void getPrinterPsuState(); void getPrinterPsuState();
void updateOctoPrintClient(String ApiKey, String server, int port, String user, String pass, boolean psu); void updatePrintClient(String ApiKey, String server, int port, String user, String pass, boolean psu);
String getAveragePrintTime(); String getAveragePrintTime();
String getEstimatedPrintTime(); String getEstimatedPrintTime();

View File

@ -28,10 +28,10 @@ SOFTWARE.
#include "RepetierClient.h" #include "RepetierClient.h"
RepetierClient::RepetierClient(String ApiKey, String server, int port, String user, String pass, boolean psu) { RepetierClient::RepetierClient(String ApiKey, String server, int port, String user, String pass, boolean psu) {
updateOctoPrintClient(ApiKey, server, port, user, pass, psu); updatePrintClient(ApiKey, server, port, user, pass, psu);
} }
void RepetierClient::updateOctoPrintClient(String ApiKey, String server, int port, String user, String pass, boolean psu) { void RepetierClient::updatePrintClient(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;

View File

@ -21,8 +21,8 @@ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE. SOFTWARE.
*/ */
// Additional Contributions: /* 07 April 2019 : Jon Smith : added class for Repetier Server (kg4iae@github)*/
/* 15 Jan 2019 : Owen Carter : Add psucontrol query via POST api call */
#pragma once #pragma once
#include <ESP8266WiFi.h> #include <ESP8266WiFi.h>
@ -73,7 +73,7 @@ public:
RepetierClient(String ApiKey, String server, int port, String user, String pass, boolean psu); RepetierClient(String ApiKey, String server, int port, String user, String pass, boolean psu);
void getPrinterJobResults(); void getPrinterJobResults();
void getPrinterPsuState(); void getPrinterPsuState();
void updateOctoPrintClient(String ApiKey, String server, int port, String user, String pass, boolean psu); void updatePrintClient(String ApiKey, String server, int port, String user, String pass, boolean psu);
String getAveragePrintTime(); String getAveragePrintTime();
String getEstimatedPrintTime(); String getEstimatedPrintTime();

View File

@ -46,6 +46,7 @@ SOFTWARE.
#include <ESP8266HTTPUpdateServer.h> #include <ESP8266HTTPUpdateServer.h>
#include "TimeClient.h" #include "TimeClient.h"
#include "OctoPrintClient.h" #include "OctoPrintClient.h"
#include "RepetierClient.h"
#include "OpenWeatherMapClient.h" #include "OpenWeatherMapClient.h"
#include "WeatherStationFonts.h" #include "WeatherStationFonts.h"
#include "FS.h" #include "FS.h"
@ -57,13 +58,14 @@ SOFTWARE.
// Start Settings // Start Settings
//****************************** //******************************
// OctoPrint Monitoring -- Monitor your 3D printer OctoPrint Server // OctoPrint / Repetier Monitoring -- Monitor your 3D OctoPrint or Repetier Server
String OctoPrintApiKey = ""; // ApiKey from your User Account on OctoPrint #define USE_REPETIER_CLIENT // Uncomment this line to use the Repetier Printer Server -- OctoPrint is used by default and is most common
String OctoPrintHostName = "octopi";// Default 'octopi' -- or hostname if different (optional if your IP changes) String PrinterApiKey = ""; // ApiKey from your User Account on OctoPrint / Repetier
String OctoPrintServer = ""; // IP or Address of your OctoPrint Server (DO NOT include http://) String PrinterHostName = "octopi";// Default 'octopi' -- or hostname if different (optional if your IP changes)
int OctoPrintPort = 80; // the port you are running your OctoPrint server on (usually 80); String PrinterServer = ""; // IP or Address of your OctoPrint / Repetier Server (DO NOT include http://)
String OctoAuthUser = ""; // only used if you have haproxy or basic athentintication turned on (not default) int PrinterPort = 80; // the port you are running your OctoPrint / Repetier server on (usually 80);
String OctoAuthPass = ""; // only used with haproxy or basic auth (only needed if you must authenticate) String PrinterAuthUser = ""; // only used if you have haproxy or basic athentintication turned on (not default)
String PrinterAuthPass = ""; // only used with haproxy or basic auth (only needed if you must authenticate)
// Weather Configuration // Weather Configuration
boolean DISPLAYWEATHER = true; // true = show weather when not printing / false = no weather boolean DISPLAYWEATHER = true; // true = show weather when not printing / false = no weather

View File

@ -30,9 +30,9 @@ SOFTWARE.
#include "Settings.h" #include "Settings.h"
#define VERSION "2.6" #define VERSION "3.0"
#define HOSTNAME "OctMon-" #define HOSTNAME "PrintMon-"
#define CONFIG "/conf.txt" #define CONFIG "/conf.txt"
/* Useful Constants */ /* Useful Constants */
@ -84,8 +84,14 @@ String lastSecond = "xx";
String lastReportStatus = ""; String lastReportStatus = "";
boolean displayOn = true; boolean displayOn = true;
// OctoPrint Client // Printer Client
OctoPrintClient printerClient(OctoPrintApiKey, OctoPrintServer, OctoPrintPort, OctoAuthUser, OctoAuthPass, HAS_PSU); #if defined(USE_REPETIER_CLIENT)
RepetierClient printerClient(PrinterApiKey, PrinterServer, PrinterPort, PrinterAuthUser, PrinterAuthPass, HAS_PSU);
String printerType = "Repetier";
#else
OctoPrintClient printerClient(PrinterApiKey, PrinterServer, PrinterPort, PrinterAuthUser, PrinterAuthPass, HAS_PSU);
String printerType = "OctoPrint";
#endif
int printerCount = 0; int printerCount = 0;
// Weather Client // Weather Client
@ -107,12 +113,12 @@ String WEB_ACTIONS = "<a class='w3-bar-item w3-button' href='/'><i class='fa fa
"<a class='w3-bar-item w3-button' href='https://github.com/Qrome' target='_blank'><i class='fa fa-question-circle'></i> About</a>"; "<a class='w3-bar-item w3-button' href='https://github.com/Qrome' target='_blank'><i class='fa fa-question-circle'></i> About</a>";
String CHANGE_FORM = "<form class='w3-container' action='/updateconfig' method='get'><h2>Station Config:</h2>" String CHANGE_FORM = "<form class='w3-container' action='/updateconfig' method='get'><h2>Station Config:</h2>"
"<p><label>OctoPrint API Key (get from your server)</label><input class='w3-input w3-border w3-margin-bottom' type='text' name='octoPrintApiKey' value='%OCTOKEY%' maxlength='60'></p>" "<p><label>" + printerType + " API Key (get from your server)</label><input class='w3-input w3-border w3-margin-bottom' type='text' name='PrinterApiKey' value='%OCTOKEY%' maxlength='60'></p>"
"<p><label>OctoPrint Host Name (usually octopi)</label><input class='w3-input w3-border w3-margin-bottom' type='text' name='octoPrintHostName' value='%OCTOHOST%' maxlength='60'></p>" "<p><label>" + printerType + " Host Name (usually octopi)</label><input class='w3-input w3-border w3-margin-bottom' type='text' name='PrinterHostName' value='%OCTOHOST%' maxlength='60'></p>"
"<p><label>OctoPrint Address (do not include http://)</label><input class='w3-input w3-border w3-margin-bottom' type='text' name='octoPrintAddress' value='%OCTOADDRESS%' maxlength='60'></p>" "<p><label>" + printerType + " Address (do not include http://)</label><input class='w3-input w3-border w3-margin-bottom' type='text' name='PrinterAddress' value='%OCTOADDRESS%' maxlength='60'></p>"
"<p><label>OctoPrint Port</label><input class='w3-input w3-border w3-margin-bottom' type='text' name='octoPrintPort' value='%OCTOPORT%' maxlength='5' onkeypress='return isNumberKey(event)'></p>" "<p><label>" + printerType + " Port</label><input class='w3-input w3-border w3-margin-bottom' type='text' name='PrinterPort' value='%OCTOPORT%' maxlength='5' onkeypress='return isNumberKey(event)'></p>"
"<p><label>OctoPrint User (only needed if you have haproxy or basic auth turned on)</label><input class='w3-input w3-border w3-margin-bottom' type='text' name='octoUser' value='%OCTOUSER%' maxlength='30'></p>" "<p><label>" + printerType + " User (only needed if you have haproxy or basic auth turned on)</label><input class='w3-input w3-border w3-margin-bottom' type='text' name='octoUser' value='%OCTOUSER%' maxlength='30'></p>"
"<p><label>OctoPrint Password </label><input class='w3-input w3-border w3-margin-bottom' type='password' name='octoPass' value='%OCTOPASS%'></p><hr>" "<p><label>" + printerType + " 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><input name='invDisp' class='w3-check w3-margin-top' type='checkbox' %IS_INVDISP_CHECKED%> Flip display orientation</p>"
@ -326,32 +332,32 @@ void setup() {
display.display(); display.display();
} }
flashLED(5, 500); flashLED(5, 500);
findMDNS(); //go find Octoprint Server by the hostname findMDNS(); //go find Printer Server by the hostname
Serial.println("*** Leaving setup()"); Serial.println("*** Leaving setup()");
} }
void findMDNS() { void findMDNS() {
if (OctoPrintHostName == "" || ENABLE_OTA == false) { if (PrinterHostName == "" || 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
// over tcp, and get the number of available devices // over tcp, and get the number of available devices
int n = MDNS.queryService("http", "tcp"); int n = MDNS.queryService("http", "tcp");
if (n == 0) { if (n == 0) {
Serial.println("no services found - make sure OctoPrint server is turned on"); Serial.println("no services found - make sure Printer server is turned on");
return; return;
} }
Serial.println("*** Looking for " + OctoPrintHostName + " over mDNS"); Serial.println("*** Looking for " + PrinterHostName + " over mDNS");
for (int i = 0; i < n; ++i) { for (int i = 0; i < n; ++i) {
// Going through every available service, // Going through every available service,
// we're searching for the one whose hostname // we're searching for the one whose hostname
// matches what we want, and then get its IP // matches what we want, and then get its IP
Serial.println("Found: " + MDNS.hostname(i)); Serial.println("Found: " + MDNS.hostname(i));
if (MDNS.hostname(i) == OctoPrintHostName) { if (MDNS.hostname(i) == PrinterHostName) {
IPAddress serverIp = MDNS.IP(i); IPAddress serverIp = MDNS.IP(i);
OctoPrintServer = serverIp.toString(); PrinterServer = serverIp.toString();
OctoPrintPort = MDNS.port(i); // save the port PrinterPort = MDNS.port(i); // save the port
Serial.println("*** Found OctoPrint Server " + OctoPrintHostName + " http://" + OctoPrintServer + ":" + OctoPrintPort); Serial.println("*** Found Printer Server " + PrinterHostName + " http://" + PrinterServer + ":" + PrinterPort);
writeSettings(); // update the settings writeSettings(); // update the settings
} }
} }
@ -454,12 +460,12 @@ void handleUpdateConfig() {
if (!authentication()) { if (!authentication()) {
return server.requestAuthentication(); return server.requestAuthentication();
} }
OctoPrintApiKey = server.arg("octoPrintApiKey"); PrinterApiKey = server.arg("PrinterApiKey");
OctoPrintHostName = server.arg("octoPrintHostName"); PrinterHostName = server.arg("PrinterHostName");
OctoPrintServer = server.arg("octoPrintAddress"); PrinterServer = server.arg("PrinterAddress");
OctoPrintPort = server.arg("octoPrintPort").toInt(); PrinterPort = server.arg("PrinterPort").toInt();
OctoAuthUser = server.arg("octoUser"); PrinterAuthUser = server.arg("octoUser");
OctoAuthPass = server.arg("octoPass"); PrinterAuthPass = 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"); INVERT_DISPLAY = server.hasArg("invDisp");
@ -559,12 +565,12 @@ void handleConfigure() {
String form = CHANGE_FORM; String form = CHANGE_FORM;
form.replace("%OCTOKEY%", OctoPrintApiKey); form.replace("%OCTOKEY%", PrinterApiKey);
form.replace("%OCTOHOST%", OctoPrintHostName); form.replace("%OCTOHOST%", PrinterHostName);
form.replace("%OCTOADDRESS%", OctoPrintServer); form.replace("%OCTOADDRESS%", PrinterServer);
form.replace("%OCTOPORT%", String(OctoPrintPort)); form.replace("%OCTOPORT%", String(PrinterPort));
form.replace("%OCTOUSER%", OctoAuthUser); form.replace("%OCTOUSER%", PrinterAuthUser);
form.replace("%OCTOPASS%", OctoAuthPass); form.replace("%OCTOPASS%", PrinterAuthPass);
String isClockChecked = ""; String isClockChecked = "";
if (DISPLAYCLOCK) { if (DISPLAYCLOCK) {
isClockChecked = "checked='checked'"; isClockChecked = "checked='checked'";
@ -719,7 +725,7 @@ void displayPrinterStatus() {
html += "<div class='w3-cell-row' style='width:100%'><h2>Time: " + displayTime + "</h2></div><div class='w3-cell-row'>"; html += "<div class='w3-cell-row' style='width:100%'><h2>Time: " + displayTime + "</h2></div><div class='w3-cell-row'>";
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 += printerType + " Host Name: " + PrinterHostName + "<br>";
if (printerClient.getError() != "") { if (printerClient.getError() != "") {
html += "Status: Offline<br>"; html += "Status: Offline<br>";
html += "Reason: " + printerClient.getError() + "<br>"; html += "Reason: " + printerClient.getError() + "<br>";
@ -905,7 +911,7 @@ void drawClock(OLEDDisplay *display, OLEDDisplayUiState* state, int16_t x, int16
displayTime = timeClient.getHours() + ":" + timeClient.getMinutes() + ":" + timeClient.getSeconds(); displayTime = timeClient.getHours() + ":" + timeClient.getMinutes() + ":" + timeClient.getSeconds();
} }
display->setFont(ArialMT_Plain_16); display->setFont(ArialMT_Plain_16);
display->drawString(64 + x, 0 + y, OctoPrintHostName); display->drawString(64 + x, 0 + y, PrinterHostName);
display->setFont(ArialMT_Plain_24); display->setFont(ArialMT_Plain_24);
display->drawString(64 + x, 17 + y, displayTime); display->drawString(64 + x, 17 + y, displayTime);
} }
@ -1047,12 +1053,12 @@ void writeSettings() {
} else { } else {
Serial.println("Saving settings now..."); Serial.println("Saving settings now...");
f.println("UtcOffset=" + String(UtcOffset)); f.println("UtcOffset=" + String(UtcOffset));
f.println("octoKey=" + OctoPrintApiKey); f.println("printerApiKey=" + PrinterApiKey);
f.println("octoHost=" + OctoPrintHostName); f.println("printerHostName=" + PrinterHostName);
f.println("octoServer=" + OctoPrintServer); f.println("printerServer=" + PrinterServer);
f.println("octoPort=" + String(OctoPrintPort)); f.println("printerPort=" + String(PrinterPort));
f.println("octoUser=" + OctoAuthUser); f.println("printerAuthUser=" + PrinterAuthUser);
f.println("octoPass=" + OctoAuthPass); f.println("printerAuthPass=" + PrinterAuthPass);
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("IS_BASIC_AUTH=" + String(IS_BASIC_AUTH));
@ -1089,34 +1095,34 @@ void readSettings() {
UtcOffset = line.substring(line.lastIndexOf("UtcOffset=") + 10).toFloat(); UtcOffset = line.substring(line.lastIndexOf("UtcOffset=") + 10).toFloat();
Serial.println("UtcOffset=" + String(UtcOffset)); Serial.println("UtcOffset=" + String(UtcOffset));
} }
if (line.indexOf("octoKey=") >= 0) { if (line.indexOf("printerApiKey=") >= 0) {
OctoPrintApiKey = line.substring(line.lastIndexOf("octoKey=") + 8); PrinterApiKey = line.substring(line.lastIndexOf("printerApiKey=") + 14);
OctoPrintApiKey.trim(); PrinterApiKey.trim();
Serial.println("OctoPrintApiKey=" + OctoPrintApiKey); Serial.println("PrinterApiKey=" + PrinterApiKey);
} }
if (line.indexOf("octoHost=") >= 0) { if (line.indexOf("printerHostName=") >= 0) {
OctoPrintHostName = line.substring(line.lastIndexOf("octoHost=") + 9); PrinterHostName = line.substring(line.lastIndexOf("printerHostName=") + 16);
OctoPrintHostName.trim(); PrinterHostName.trim();
Serial.println("OctoPrintHostName=" + OctoPrintHostName); Serial.println("PrinterHostName=" + PrinterHostName);
} }
if (line.indexOf("octoServer=") >= 0) { if (line.indexOf("printerServer=") >= 0) {
OctoPrintServer = line.substring(line.lastIndexOf("octoServer=") + 11); PrinterServer = line.substring(line.lastIndexOf("printerServer=") + 14);
OctoPrintServer.trim(); PrinterServer.trim();
Serial.println("OctoPrintServer=" + OctoPrintServer); Serial.println("PrinterServer=" + PrinterServer);
} }
if (line.indexOf("octoPort=") >= 0) { if (line.indexOf("printerPort=") >= 0) {
OctoPrintPort = line.substring(line.lastIndexOf("octoPort=") + 9).toInt(); PrinterPort = line.substring(line.lastIndexOf("printerPort=") + 12).toInt();
Serial.println("OctoPrintPort=" + String(OctoPrintPort)); Serial.println("PrinterPort=" + String(PrinterPort));
} }
if (line.indexOf("octoUser=") >= 0) { if (line.indexOf("printerAuthUser=") >= 0) {
OctoAuthUser = line.substring(line.lastIndexOf("octoUser=") + 9); PrinterAuthUser = line.substring(line.lastIndexOf("printerAuthUser=") + 16);
OctoAuthUser.trim(); PrinterAuthUser.trim();
Serial.println("OctoAuthUser=" + OctoAuthUser); Serial.println("PrinterAuthUser=" + PrinterAuthUser);
} }
if (line.indexOf("octoPass=") >= 0) { if (line.indexOf("printerAuthPass=") >= 0) {
OctoAuthPass = line.substring(line.lastIndexOf("octoPass=") + 9); PrinterAuthPass = line.substring(line.lastIndexOf("printerAuthPass=") + 16);
OctoAuthPass.trim(); PrinterAuthPass.trim();
Serial.println("OctoAuthPass=" + OctoAuthPass); Serial.println("PrinterAuthPass=" + PrinterAuthPass);
} }
if (line.indexOf("refreshRate=") >= 0) { if (line.indexOf("refreshRate=") >= 0) {
minutesBetweenDataRefresh = line.substring(line.lastIndexOf("refreshRate=") + 12).toInt(); minutesBetweenDataRefresh = line.substring(line.lastIndexOf("refreshRate=") + 12).toInt();
@ -1187,7 +1193,7 @@ void readSettings() {
} }
} }
fr.close(); fr.close();
printerClient.updateOctoPrintClient(OctoPrintApiKey, OctoPrintServer, OctoPrintPort, OctoAuthUser, OctoAuthPass, HAS_PSU); printerClient.updatePrintClient(PrinterApiKey, PrinterServer, PrinterPort, PrinterAuthUser, PrinterAuthPass, HAS_PSU);
weatherClient.updateWeatherApiKey(WeatherApiKey); weatherClient.updateWeatherApiKey(WeatherApiKey);
weatherClient.updateLanguage(WeatherLanguage); weatherClient.updateLanguage(WeatherLanguage);
weatherClient.setMetric(IS_METRIC); weatherClient.setMetric(IS_METRIC);