Bringing klipper up (can use ip or hostname, preffer ip)
parent
290fea0311
commit
13c04d65e8
|
|
@ -11,8 +11,8 @@ KlipperClient::KlipperClient(GlobalDataController *globalDataController, DebugCo
|
|||
|
||||
void KlipperClient::updatePrintClient() {
|
||||
this->globalDataController->getPrinterHostName().toCharArray(this->myServer, 100);
|
||||
myApiKey = this->globalDataController->getPrinterApiKey();
|
||||
myPort = this->globalDataController->getPrinterPort();
|
||||
this->globalDataController->getPrinterServer().toCharArray(this->myServerIp, 30);
|
||||
this->myPort = this->globalDataController->getPrinterPort();
|
||||
encodedAuth = "";
|
||||
if (this->globalDataController->getPrinterAuthUser() != "") {
|
||||
String userpass = this->globalDataController->getPrinterAuthUser() + ":" + this->globalDataController->getPrinterAuthPass();
|
||||
|
|
@ -25,11 +25,8 @@ void KlipperClient::updatePrintClient() {
|
|||
boolean KlipperClient::validate() {
|
||||
boolean rtnValue = false;
|
||||
printerData.error = "";
|
||||
if (String(myServer) == "") {
|
||||
printerData.error += "Server address is required; ";
|
||||
}
|
||||
if (myApiKey == "") {
|
||||
printerData.error += "ApiKey is required; ";
|
||||
if ((String(this->myServer) == "") && (String(this->myServerIp) == "")) {
|
||||
printerData.error += "Server address or host name is required; ";
|
||||
}
|
||||
if (printerData.error == "") {
|
||||
rtnValue = true;
|
||||
|
|
@ -40,14 +37,17 @@ boolean KlipperClient::validate() {
|
|||
WiFiClient KlipperClient::getSubmitRequest(String apiGetData) {
|
||||
WiFiClient printClient;
|
||||
printClient.setTimeout(5000);
|
||||
const char *targetServer = this->myServerIp;
|
||||
if (String(this->myServerIp) == "") {
|
||||
targetServer = this->myServer;
|
||||
}
|
||||
|
||||
this->debugController->printLn("Getting Klipper Data via GET");
|
||||
this->debugController->printLn(apiGetData);
|
||||
result = "";
|
||||
if (printClient.connect(myServer, myPort)) { //starts client connection, checks for connection
|
||||
if (printClient.connect(targetServer, myPort)) { //starts client connection, checks for connection
|
||||
printClient.println(apiGetData);
|
||||
printClient.println("Host: " + String(myServer) + ":" + String(myPort));
|
||||
printClient.println("X-Api-Key: " + myApiKey);
|
||||
printClient.println("Host: " + String(targetServer) + ":" + String(myPort));
|
||||
if (encodedAuth != "") {
|
||||
printClient.print("Authorization: ");
|
||||
printClient.println("Basic " + encodedAuth);
|
||||
|
|
@ -55,18 +55,18 @@ WiFiClient KlipperClient::getSubmitRequest(String apiGetData) {
|
|||
printClient.println("User-Agent: ArduinoWiFi/1.1");
|
||||
printClient.println("Connection: close");
|
||||
if (printClient.println() == 0) {
|
||||
this->debugController->printLn("Connection to " + String(myServer) + ":" + String(myPort) + " failed.");
|
||||
this->debugController->printLn("Connection to " + String(targetServer) + ":" + String(myPort) + " failed.");
|
||||
this->debugController->printLn("");
|
||||
resetPrintData();
|
||||
printerData.error = "Connection to " + String(myServer) + ":" + String(myPort) + " failed.";
|
||||
printerData.error = "Connection to " + String(targetServer) + ":" + String(myPort) + " failed.";
|
||||
return printClient;
|
||||
}
|
||||
}
|
||||
else {
|
||||
this->debugController->printLn("Connection to Klipper failed: " + String(myServer) + ":" + String(myPort)); //error message if no client connect
|
||||
this->debugController->printLn("Connection to Klipper failed: " + String(targetServer) + ":" + String(myPort)); //error message if no client connect
|
||||
this->debugController->printLn("");
|
||||
resetPrintData();
|
||||
printerData.error = "Connection to Klipper failed: " + String(myServer) + ":" + String(myPort);
|
||||
printerData.error = "Connection to Klipper failed: " + String(targetServer) + ":" + String(myPort);
|
||||
return printClient;
|
||||
}
|
||||
|
||||
|
|
@ -85,7 +85,7 @@ WiFiClient KlipperClient::getSubmitRequest(String apiGetData) {
|
|||
char endOfHeaders[] = "\r\n\r\n";
|
||||
if (!printClient.find(endOfHeaders)) {
|
||||
this->debugController->printLn("Invalid response");
|
||||
printerData.error = "Invalid response from " + String(myServer) + ":" + String(myPort);
|
||||
printerData.error = "Invalid response from " + String(targetServer) + ":" + String(myPort);
|
||||
printerData.state = "";
|
||||
}
|
||||
|
||||
|
|
@ -95,18 +95,21 @@ WiFiClient KlipperClient::getSubmitRequest(String apiGetData) {
|
|||
WiFiClient KlipperClient::getPostRequest(String apiPostData, String apiPostBody) {
|
||||
WiFiClient printClient;
|
||||
printClient.setTimeout(5000);
|
||||
const char *targetServer = this->myServerIp;
|
||||
if (String(this->myServerIp) == "") {
|
||||
targetServer = this->myServer;
|
||||
}
|
||||
|
||||
this->debugController->printLn("Getting Klipper Data via POST");
|
||||
this->debugController->printLn(apiPostData + " | " + apiPostBody);
|
||||
result = "";
|
||||
if (printClient.connect(myServer, myPort)) { //starts client connection, checks for connection
|
||||
if (printClient.connect(targetServer, myPort)) { //starts client connection, checks for connection
|
||||
printClient.println(apiPostData);
|
||||
printClient.println("Host: " + String(myServer) + ":" + String(myPort));
|
||||
printClient.println("Host: " + String(targetServer) + ":" + String(myPort));
|
||||
printClient.println("Connection: close");
|
||||
printClient.println("X-Api-Key: " + myApiKey);
|
||||
if (encodedAuth != "") {
|
||||
printClient.print("Authorization: ");
|
||||
printClient.println("Basic " + encodedAuth);
|
||||
printClient.print("Authorization: ");
|
||||
printClient.println("Basic " + encodedAuth);
|
||||
}
|
||||
printClient.println("User-Agent: ArduinoWiFi/1.1");
|
||||
printClient.println("Content-Type: application/json");
|
||||
|
|
@ -115,18 +118,18 @@ WiFiClient KlipperClient::getPostRequest(String apiPostData, String apiPostBody)
|
|||
printClient.println();
|
||||
printClient.println(apiPostBody);
|
||||
if (printClient.println() == 0) {
|
||||
this->debugController->printLn("Connection to " + String(myServer) + ":" + String(myPort) + " failed.");
|
||||
this->debugController->printLn("");
|
||||
resetPrintData();
|
||||
printerData.error = "Connection to " + String(myServer) + ":" + String(myPort) + " failed.";
|
||||
return printClient;
|
||||
this->debugController->printLn("Connection to " + String(targetServer) + ":" + String(myPort) + " failed.");
|
||||
this->debugController->printLn("");
|
||||
resetPrintData();
|
||||
printerData.error = "Connection to " + String(targetServer) + ":" + String(myPort) + " failed.";
|
||||
return printClient;
|
||||
}
|
||||
}
|
||||
else {
|
||||
this->debugController->printLn("Connection to Klipper failed: " + String(myServer) + ":" + String(myPort)); //error message if no client connect
|
||||
this->debugController->printLn("Connection to Klipper failed: " + String(targetServer) + ":" + String(myPort)); //error message if no client connect
|
||||
this->debugController->printLn("");
|
||||
resetPrintData();
|
||||
printerData.error = "Connection to Klipper failed: " + String(myServer) + ":" + String(myPort);
|
||||
printerData.error = "Connection to Klipper failed: " + String(targetServer) + ":" + String(myPort);
|
||||
return printClient;
|
||||
}
|
||||
|
||||
|
|
@ -145,7 +148,7 @@ WiFiClient KlipperClient::getPostRequest(String apiPostData, String apiPostBody)
|
|||
char endOfHeaders[] = "\r\n\r\n";
|
||||
if (!printClient.find(endOfHeaders)) {
|
||||
this->debugController->printLn("Invalid response");
|
||||
printerData.error = "Invalid response from " + String(myServer) + ":" + String(myPort);
|
||||
printerData.error = "Invalid response from " + String(targetServer) + ":" + String(myPort);
|
||||
printerData.state = "";
|
||||
}
|
||||
|
||||
|
|
@ -156,6 +159,11 @@ void KlipperClient::getPrinterJobResults() {
|
|||
if (!validate()) {
|
||||
return;
|
||||
}
|
||||
const char *targetServer = this->myServerIp;
|
||||
if (String(this->myServerIp) == "") {
|
||||
targetServer = this->myServer;
|
||||
}
|
||||
|
||||
//**** get the Printer Job status
|
||||
String apiGetData = "GET /printer/objects/query?heater_bed&extruder&webhooks&virtual_sdcard&print_stats&toolhead&display_status";
|
||||
WiFiClient printClient = getSubmitRequest(apiGetData);
|
||||
|
|
@ -168,8 +176,8 @@ void KlipperClient::getPrinterJobResults() {
|
|||
// Parse JSON object
|
||||
DeserializationError error = deserializeJson(jsonBuffer, printClient);
|
||||
if (error) {
|
||||
this->debugController->printLn("Klipper Data Parsing failed: " + String(myServer) + ":" + String(myPort));
|
||||
printerData.error = "Klipper Data Parsing failed: " + String(myServer) + ":" + String(myPort);
|
||||
this->debugController->printLn("Klipper Data Parsing failed: " + String(targetServer) + ":" + String(myPort));
|
||||
printerData.error = "Klipper Data Parsing failed: " + String(targetServer) + ":" + String(myPort);
|
||||
printerData.state = "";
|
||||
printerData.isPrinting = false;
|
||||
printerData.toolTemp = "";
|
||||
|
|
|
|||
|
|
@ -9,8 +9,8 @@
|
|||
class KlipperClient : public BasePrinterClient {
|
||||
private:
|
||||
char myServer[100];
|
||||
char myServerIp[30];
|
||||
int myPort = 7125;
|
||||
String myApiKey = "";
|
||||
String encodedAuth = "";
|
||||
boolean pollPsu;
|
||||
const String printerType = "Klipper";
|
||||
|
|
|
|||
|
|
@ -7,6 +7,7 @@ public:
|
|||
virtual void preSetup();
|
||||
virtual void postSetup();
|
||||
virtual void handleUpdate();
|
||||
virtual void flipDisplayUpdate();
|
||||
virtual void showBootScreen();
|
||||
virtual void showApAccessScreen(String apSsid, String apIp);
|
||||
virtual void showWebserverSplashScreen(bool isEnabled);
|
||||
|
|
|
|||
|
|
@ -20,6 +20,10 @@ void NextionDisplay::handleUpdate() {
|
|||
|
||||
}
|
||||
|
||||
void NextionDisplay::flipDisplayUpdate() {
|
||||
|
||||
}
|
||||
|
||||
void NextionDisplay::showBootScreen() {
|
||||
String command("version.txt=");
|
||||
command += "\"for " + this->globalDataController->getPrinterClient()->getPrinterType() + " V" + this->globalDataController->getVersion() + "\"";
|
||||
|
|
|
|||
|
|
@ -18,6 +18,7 @@ public:
|
|||
void preSetup();
|
||||
void postSetup();
|
||||
void handleUpdate();
|
||||
void flipDisplayUpdate();
|
||||
void showBootScreen();
|
||||
void showApAccessScreen(String apSsid, String apIp);
|
||||
void showWebserverSplashScreen(bool isEnabled);
|
||||
|
|
|
|||
|
|
@ -46,6 +46,14 @@ void OledDisplay::handleUpdate() {
|
|||
this->ui->update();
|
||||
}
|
||||
|
||||
void OledDisplay::flipDisplayUpdate() {
|
||||
this->ui->init();
|
||||
if (this->globalDataController->isDisplayInverted()) {
|
||||
this->oledDisplay->flipScreenVertically(); // connections at top of OLED display
|
||||
}
|
||||
this->ui->update();
|
||||
}
|
||||
|
||||
void OledDisplay::showBootScreen() {
|
||||
this->oledDisplay->setTextAlignment(TEXT_ALIGN_CENTER);
|
||||
this->oledDisplay->setContrast(255); // default is 255
|
||||
|
|
|
|||
|
|
@ -27,6 +27,7 @@ public:
|
|||
void preSetup();
|
||||
void postSetup();
|
||||
void handleUpdate();
|
||||
void flipDisplayUpdate();
|
||||
void showBootScreen();
|
||||
void showApAccessScreen(String apSsid, String apIp);
|
||||
void showWebserverSplashScreen(bool isEnabled);
|
||||
|
|
|
|||
|
|
@ -208,7 +208,7 @@ void GlobalDataController::setDisplayClient(BaseDisplayClient *baseDisplayClient
|
|||
this->baseDisplayClient = baseDisplayClient;
|
||||
}
|
||||
|
||||
BaseDisplayClient *GlobalDataController::setDisplayClient() {
|
||||
BaseDisplayClient *GlobalDataController::getDisplayClient() {
|
||||
return this->baseDisplayClient;
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -64,7 +64,7 @@ public:
|
|||
TimeClient *getTimeClient();
|
||||
OpenWeatherMapClient *getWeatherClient();
|
||||
BasePrinterClient *getPrinterClient();
|
||||
BaseDisplayClient *setDisplayClient();
|
||||
BaseDisplayClient *getDisplayClient();
|
||||
String getLastReportStatus();
|
||||
String getVersion();
|
||||
|
||||
|
|
|
|||
|
|
@ -323,13 +323,10 @@ void WebServer::handleUpdateConfig() {
|
|||
|
||||
this->globalDataController->getPrinterClient()->getPrinterJobResults();
|
||||
this->globalDataController->getPrinterClient()->getPrinterPsuState();
|
||||
/*if (INVERT_DISPLAY != flipOld) {
|
||||
ui.init();
|
||||
if(INVERT_DISPLAY)
|
||||
display.flipScreenVertically();
|
||||
ui.update();
|
||||
if (this->globalDataController->isDisplayInverted() != flipOld) {
|
||||
this->globalDataController->getDisplayClient()->flipDisplayUpdate();
|
||||
}
|
||||
checkDisplay();*/
|
||||
this->globalDataController->getDisplayClient()->handleUpdate();
|
||||
this->globalDataController->getTimeClient()->resetLastEpoch();
|
||||
this->redirectHome();
|
||||
}
|
||||
|
|
@ -415,11 +412,10 @@ void WebServer::handleConfigure() {
|
|||
this->server->sendContent(html);
|
||||
}
|
||||
else if (printerClient->getPrinterType() == "Klipper") {
|
||||
// TODO: INVALID JAVASCRIPT HERE
|
||||
/*html = "<script>function testKlipper(){var e=document.getElementById(\"KlipperTest\"),r=document.getElementById(\"PrinterAddress\").value,"
|
||||
"t=document.getElementById(\"PrinterPort\").value;if(\"\"==r||\"\"==t)return e.innerHTML=\"* Address and Port are required\","
|
||||
"void(e.style.background=\"\");var n=\"http://\"+r+\":\"+t;n+=\"/printer/info";
|
||||
this->server->sendContent(html); */
|
||||
html = "<script>function testKlipper(){var e=document.getElementById(\"KlipperTest\"),t=document.getElementById(\"PrinterAddress\").value,"
|
||||
"n=document.getElementById(\"PrinterPort\").value;if(e.innerHTML=\"\",\"\"==t||\"\"==n)return e.innerHTML=\"* Address and Port are required\","
|
||||
"void(e.style.background=\"\");var r=\"http://\"+t+\":\"+n;r+=\"/printer/info\",window.open(r,\"_blank\").focus()}</script>";
|
||||
this->server->sendContent(html);
|
||||
}
|
||||
else {
|
||||
html = "<script>function testOctoPrint(){var e=document.getElementById(\"OctoPrintTest\"),t=document.getElementById(\"PrinterAddress\").value,"
|
||||
|
|
@ -429,38 +425,37 @@ void WebServer::handleConfigure() {
|
|||
}
|
||||
|
||||
|
||||
String form = "<form class='w3-container' action='/updateconfig' method='get'><h2>Station Config:</h2>"
|
||||
"<p><label>" + printerClient->getPrinterType() + " API Key (get from your server)</label>"
|
||||
"<input class='w3-input w3-border w3-margin-bottom' type='text' name='PrinterApiKey' id='PrinterApiKey' value='%OCTOKEY%' maxlength='60'></p>";
|
||||
String form = "<form class='w3-container' action='/updateconfig' method='get'><h2>Station Config:</h2>";
|
||||
|
||||
|
||||
if (printerClient->getPrinterType() != "Klipper") {
|
||||
form += "<p><label>" + printerClient->getPrinterType() + " API Key (get from your server)</label>"
|
||||
"<input class='w3-input w3-border w3-margin-bottom' type='text' name='PrinterApiKey' id='PrinterApiKey' value='%PRINTERAPIKEY%' maxlength='60'></p>";
|
||||
}
|
||||
if ((printerClient->getPrinterType() == "OctoPrint") || (printerClient->getPrinterType() == "Klipper")) {
|
||||
form += "<p><label>" + printerClient->getPrinterType() + " Host Name</label><input class='w3-input w3-border w3-margin-bottom' type='text' name='PrinterHostName' value='%OCTOHOST%' maxlength='60'></p>";
|
||||
form += "<p><label>" + printerClient->getPrinterType() + " Host Name</label><input class='w3-input w3-border w3-margin-bottom' type='text' name='PrinterHostName' value='%PRINTERHOST%' maxlength='60'></p>";
|
||||
}
|
||||
form += "<p><label>" + printerClient->getPrinterType() + " Address (do not include http://)</label>"
|
||||
"<input class='w3-input w3-border w3-margin-bottom' type='text' name='PrinterAddress' id='PrinterAddress' value='%OCTOADDRESS%' maxlength='60'></p>"
|
||||
"<input class='w3-input w3-border w3-margin-bottom' type='text' name='PrinterAddress' id='PrinterAddress' value='%PRINTERADDRESS%' maxlength='60'></p>"
|
||||
"<p><label>" + printerClient->getPrinterType() + " Port</label>"
|
||||
"<input class='w3-input w3-border w3-margin-bottom' type='text' name='PrinterPort' id='PrinterPort' value='%OCTOPORT%' maxlength='5' onkeypress='return isNumberKey(event)'></p>";
|
||||
if (printerClient->getPrinterType() == "Repetier") {
|
||||
form += "<input type='button' value='Test Connection' onclick='testRepetier()'>"
|
||||
"<input type='hidden' id='selectedPrinter' value='" + printerClient->getPrinterName() + "'><p id='RepetierTest'></p>"
|
||||
"<script>testRepetier();</script>";
|
||||
}
|
||||
else if (printerClient->getPrinterType() == "Klipper") {
|
||||
form += "<input type='button' value='Test Connection' onclick='testKlipper()'>"
|
||||
"<input type='hidden' id='selectedPrinter' value='" + printerClient->getPrinterName() + "'><p id='KlipperTest'></p>"
|
||||
"<script>testKlipper();</script>";
|
||||
"<input class='w3-input w3-border w3-margin-bottom' type='text' name='PrinterPort' id='PrinterPort' value='%PRINTERPORT%' maxlength='5' onkeypress='return isNumberKey(event)'></p>";
|
||||
if ((printerClient->getPrinterType() == "Repetier") || (printerClient->getPrinterType() == "Klipper")) {
|
||||
form += "<input type='button' value='Test Connection' onclick='test" + printerClient->getPrinterName() + "()'>"
|
||||
"<input type='hidden' id='selectedPrinter' value='" + printerClient->getPrinterName() + "'><p id='" + printerClient->getPrinterName() + "Test'></p>"
|
||||
"<script>test" + printerClient->getPrinterName() + "();</script>";
|
||||
}
|
||||
else {
|
||||
form += "<input type='button' value='Test Connection and API JSON Response' onclick='testOctoPrint()'><p id='OctoPrintTest'></p>";
|
||||
}
|
||||
form += "<p><label>" + printerClient->getPrinterType() + " 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>" + printerClient->getPrinterType() + " Password </label><input class='w3-input w3-border w3-margin-bottom' type='password' name='octoPass' value='%OCTOPASS%'></p>";
|
||||
form += "<p><label>" + printerClient->getPrinterType() + " 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='%PRINTERUSER%' maxlength='30'></p>"
|
||||
"<p><label>" + printerClient->getPrinterType() + " Password </label><input class='w3-input w3-border w3-margin-bottom' type='password' name='octoPass' value='%PRINTERPASS%'></p>";
|
||||
|
||||
form.replace("%OCTOKEY%", this->globalDataController->getPrinterApiKey());
|
||||
form.replace("%OCTOHOST%", this->globalDataController->getPrinterHostName());
|
||||
form.replace("%OCTOADDRESS%", this->globalDataController->getPrinterServer());
|
||||
form.replace("%OCTOPORT%", String(this->globalDataController->getPrinterPort()));
|
||||
form.replace("%OCTOUSER%", this->globalDataController->getPrinterAuthUser());
|
||||
form.replace("%OCTOPASS%", this->globalDataController->getPrinterAuthPass());
|
||||
form.replace("%PRINTERAPIKEY%", this->globalDataController->getPrinterApiKey());
|
||||
form.replace("%PRINTERHOST%", this->globalDataController->getPrinterHostName());
|
||||
form.replace("%PRINTERADDRESS%", this->globalDataController->getPrinterServer());
|
||||
form.replace("%PRINTERPORT%", String(this->globalDataController->getPrinterPort()));
|
||||
form.replace("%PRINTERUSER%", this->globalDataController->getPrinterAuthUser());
|
||||
form.replace("%PRINTERPASS%", this->globalDataController->getPrinterAuthPass());
|
||||
this->server->sendContent(form);
|
||||
|
||||
form = FPSTR(CLOCK_FORM);
|
||||
|
|
|
|||
Loading…
Reference in New Issue