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

@ -1,295 +1,396 @@
/** The MIT License (MIT) /** The MIT License (MIT)
Copyright (c) 2018 David Payne Copyright (c) 2018 David Payne
Permission is hereby granted, free of charge, to any person obtaining a copy Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions: furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software. copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE. SOFTWARE.
*/ */
#include "OctoPrintClient.h" // Additional Contributions:
/* 15 Jan 2019 : Owen Carter : Add psucontrol query via POST api call */
OctoPrintClient::OctoPrintClient(String ApiKey, String server, int port, String user, String pass) {
updateOctoPrintClient(ApiKey, server, port, user, pass); #include "OctoPrintClient.h"
}
OctoPrintClient::OctoPrintClient(String ApiKey, String server, int port, String user, String pass, boolean psu) {
void OctoPrintClient::updateOctoPrintClient(String ApiKey, String server, int port, String user, String pass) { updateOctoPrintClient(ApiKey, server, port, user, pass, psu);
server.toCharArray(myServer, 100); }
myApiKey = ApiKey;
myPort = port; void OctoPrintClient::updateOctoPrintClient(String ApiKey, String server, int port, String user, String pass, boolean psu) {
encodedAuth = ""; server.toCharArray(myServer, 100);
if (user != "") { myApiKey = ApiKey;
String userpass = user + ":" + pass; myPort = port;
base64 b64; encodedAuth = "";
encodedAuth = b64.encode(userpass, true); if (user != "") {
} String userpass = user + ":" + pass;
} base64 b64;
encodedAuth = b64.encode(userpass, true);
boolean OctoPrintClient::validate() { }
boolean rtnValue = false; pollPsu = psu;
printerData.error = ""; }
if (String(myServer) == "") {
printerData.error += "Server address is required; "; boolean OctoPrintClient::validate() {
} boolean rtnValue = false;
if (myApiKey == "") { printerData.error = "";
printerData.error += "ApiKey is required; "; if (String(myServer) == "") {
} printerData.error += "Server address is required; ";
if (printerData.error == "") { }
rtnValue = true; if (myApiKey == "") {
} printerData.error += "ApiKey is required; ";
return rtnValue; }
} if (printerData.error == "") {
rtnValue = true;
WiFiClient OctoPrintClient::getSubmitRequest(String apiGetData) { }
WiFiClient printClient; return rtnValue;
printClient.setTimeout(5000); }
Serial.println("Getting Octoprint Data"); WiFiClient OctoPrintClient::getSubmitRequest(String apiGetData) {
Serial.println(apiGetData); WiFiClient printClient;
result = ""; printClient.setTimeout(5000);
if (printClient.connect(myServer, myPort)) { //starts client connection, checks for connection
printClient.println(apiGetData); Serial.println("Getting Octoprint Data via GET");
printClient.println("Host: " + String(myServer) + ":" + String(myPort)); Serial.println(apiGetData);
printClient.println("X-Api-Key: " + myApiKey); result = "";
if (encodedAuth != "") { if (printClient.connect(myServer, myPort)) { //starts client connection, checks for connection
printClient.print("Authorization: "); printClient.println(apiGetData);
printClient.println("Basic " + encodedAuth); printClient.println("Host: " + String(myServer) + ":" + String(myPort));
} printClient.println("X-Api-Key: " + myApiKey);
printClient.println("User-Agent: ArduinoWiFi/1.1"); if (encodedAuth != "") {
printClient.println("Connection: close"); printClient.print("Authorization: ");
if (printClient.println() == 0) { printClient.println("Basic " + encodedAuth);
Serial.println("Connection to " + String(myServer) + ":" + String(myPort) + " failed."); }
Serial.println(); printClient.println("User-Agent: ArduinoWiFi/1.1");
resetPrintData(); printClient.println("Connection: close");
printerData.error = "Connection to " + String(myServer) + ":" + String(myPort) + " failed."; if (printClient.println() == 0) {
return printClient; Serial.println("Connection to " + String(myServer) + ":" + String(myPort) + " failed.");
} Serial.println();
} resetPrintData();
else { printerData.error = "Connection to " + String(myServer) + ":" + String(myPort) + " failed.";
Serial.println("Connection to OctoPrint failed: " + String(myServer) + ":" + String(myPort)); //error message if no client connect return printClient;
Serial.println(); }
resetPrintData(); }
printerData.error = "Connection to OctoPrint failed: " + String(myServer) + ":" + String(myPort); else {
return printClient; Serial.println("Connection to OctoPrint failed: " + String(myServer) + ":" + String(myPort)); //error message if no client connect
} Serial.println();
resetPrintData();
// Check HTTP status printerData.error = "Connection to OctoPrint failed: " + String(myServer) + ":" + String(myPort);
char status[32] = {0}; return printClient;
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: ")); // Check HTTP status
Serial.println(status); char status[32] = {0};
printerData.state = ""; printClient.readBytesUntil('\r', status, sizeof(status));
printerData.error = "Response: " + String(status); if (strcmp(status, "HTTP/1.1 200 OK") != 0 && strcmp(status, "HTTP/1.1 409 CONFLICT") != 0) {
return printClient; Serial.print(F("Unexpected response: "));
} Serial.println(status);
printerData.state = "";
// Skip HTTP headers printerData.error = "Response: " + String(status);
char endOfHeaders[] = "\r\n\r\n"; return printClient;
if (!printClient.find(endOfHeaders)) { }
Serial.println(F("Invalid response"));
printerData.error = "Invalid response from " + String(myServer) + ":" + String(myPort); // Skip HTTP headers
printerData.state = ""; char endOfHeaders[] = "\r\n\r\n";
} if (!printClient.find(endOfHeaders)) {
Serial.println(F("Invalid response"));
return printClient; printerData.error = "Invalid response from " + String(myServer) + ":" + String(myPort);
} printerData.state = "";
}
void OctoPrintClient::getPrinterJobResults() {
if (!validate()) { return printClient;
return; }
}
String apiGetData = "GET /api/job HTTP/1.1"; WiFiClient OctoPrintClient::getPostRequest(String apiPostData, String apiPostBody) {
WiFiClient printClient;
WiFiClient printClient = getSubmitRequest(apiGetData); printClient.setTimeout(5000);
if (printerData.error != "") { Serial.println("Getting Octoprint Data via POST");
return; Serial.println(apiPostData + " | " + apiPostBody);
} result = "";
if (printClient.connect(myServer, myPort)) { //starts client connection, checks for connection
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; printClient.println(apiPostData);
DynamicJsonBuffer jsonBuffer(bufferSize); printClient.println("Host: " + String(myServer) + ":" + String(myPort));
printClient.println("Connection: close");
// Parse JSON object printClient.println("X-Api-Key: " + myApiKey);
JsonObject& root = jsonBuffer.parseObject(printClient); if (encodedAuth != "") {
if (!root.success()) { printClient.print("Authorization: ");
Serial.println("OctoPrint Data Parsing failed: " + String(myServer) + ":" + String(myPort)); printClient.println("Basic " + encodedAuth);
printerData.error = "OctoPrint Data Parsing failed: " + String(myServer) + ":" + String(myPort); }
printerData.state = ""; printClient.println("User-Agent: ArduinoWiFi/1.1");
return; printClient.println("Content-Type: application/json");
} printClient.print("Content-Length: ");
printClient.println(apiPostBody.length());
printerData.averagePrintTime = (const char*)root["job"]["averagePrintTime"]; printClient.println();
printerData.estimatedPrintTime = (const char*)root["job"]["estimatedPrintTime"]; printClient.println(apiPostBody);
printerData.fileName = (const char*)root["job"]["file"]["name"]; if (printClient.println() == 0) {
printerData.fileSize = (const char*)root["job"]["file"]["size"]; Serial.println("Connection to " + String(myServer) + ":" + String(myPort) + " failed.");
printerData.lastPrintTime = (const char*)root["job"]["lastPrintTime"]; Serial.println();
printerData.progressCompletion = (const char*)root["progress"]["completion"]; resetPrintData();
printerData.progressFilepos = (const char*)root["progress"]["filepos"]; printerData.error = "Connection to " + String(myServer) + ":" + String(myPort) + " failed.";
printerData.progressPrintTime = (const char*)root["progress"]["printTime"]; return printClient;
printerData.progressPrintTimeLeft = (const char*)root["progress"]["printTimeLeft"]; }
printerData.filamentLength = (const char*)root["job"]["filament"]["tool0"]["length"]; }
printerData.state = (const char*)root["state"]; else {
Serial.println("Connection to OctoPrint failed: " + String(myServer) + ":" + String(myPort)); //error message if no client connect
if (isOperational()) { Serial.println();
Serial.println("Status: " + printerData.state); resetPrintData();
} else { printerData.error = "Connection to OctoPrint failed: " + String(myServer) + ":" + String(myPort);
Serial.println("Printer Not Opperational"); return printClient;
} }
//**** get the Printer Temps and Stat // Check HTTP status
apiGetData = "GET /api/printer?exclude=sd,history HTTP/1.1"; char status[32] = {0};
printClient = getSubmitRequest(apiGetData); printClient.readBytesUntil('\r', status, sizeof(status));
if (printerData.error != "") { if (strcmp(status, "HTTP/1.1 200 OK") != 0 && strcmp(status, "HTTP/1.1 409 CONFLICT") != 0) {
return; Serial.print(F("Unexpected response: "));
} Serial.println(status);
const size_t bufferSize2 = 3*JSON_OBJECT_SIZE(2) + 2*JSON_OBJECT_SIZE(3) + JSON_OBJECT_SIZE(9) + 300; printerData.state = "";
DynamicJsonBuffer jsonBuffer2(bufferSize2); printerData.error = "Response: " + String(status);
return printClient;
// Parse JSON object }
JsonObject& root2 = jsonBuffer2.parseObject(printClient);
if (!root2.success()) { // Skip HTTP headers
printerData.isPrinting = false; char endOfHeaders[] = "\r\n\r\n";
printerData.toolTemp = ""; if (!printClient.find(endOfHeaders)) {
printerData.toolTargetTemp = ""; Serial.println(F("Invalid response"));
printerData.bedTemp = ""; printerData.error = "Invalid response from " + String(myServer) + ":" + String(myPort);
printerData.bedTargetTemp = (const char*)root2["temperature"]["bed"]["target"]; printerData.state = "";
return; }
}
return printClient;
String printing = (const char*)root2["state"]["flags"]["printing"]; }
if (printing == "true") {
printerData.isPrinting = true; void OctoPrintClient::getPrinterJobResults() {
} if (!validate()) {
printerData.toolTemp = (const char*)root2["temperature"]["tool0"]["actual"]; return;
printerData.toolTargetTemp = (const char*)root2["temperature"]["tool0"]["target"]; }
printerData.bedTemp = (const char*)root2["temperature"]["bed"]["actual"]; //**** get the Printer Job status
printerData.bedTargetTemp = (const char*)root2["temperature"]["bed"]["target"]; String apiGetData = "GET /api/job HTTP/1.1";
WiFiClient printClient = getSubmitRequest(apiGetData);
if (isPrinting()) { if (printerData.error != "") {
Serial.println("Status: " + printerData.state + " " + printerData.fileName + "(" + printerData.progressCompletion + "%)"); 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;
printClient.stop(); //stop client DynamicJsonBuffer jsonBuffer(bufferSize);
}
// Parse JSON object
// Reset all PrinterData JsonObject& root = jsonBuffer.parseObject(printClient);
void OctoPrintClient::resetPrintData() { if (!root.success()) {
printerData.averagePrintTime = ""; Serial.println("OctoPrint Data Parsing failed: " + String(myServer) + ":" + String(myPort));
printerData.estimatedPrintTime = ""; printerData.error = "OctoPrint Data Parsing failed: " + String(myServer) + ":" + String(myPort);
printerData.fileName = ""; printerData.state = "";
printerData.fileSize = ""; return;
printerData.lastPrintTime = ""; }
printerData.progressCompletion = "";
printerData.progressFilepos = ""; printerData.averagePrintTime = (const char*)root["job"]["averagePrintTime"];
printerData.progressPrintTime = ""; printerData.estimatedPrintTime = (const char*)root["job"]["estimatedPrintTime"];
printerData.progressPrintTimeLeft = ""; printerData.fileName = (const char*)root["job"]["file"]["name"];
printerData.state = ""; printerData.fileSize = (const char*)root["job"]["file"]["size"];
printerData.toolTemp = ""; printerData.lastPrintTime = (const char*)root["job"]["lastPrintTime"];
printerData.toolTargetTemp = ""; printerData.progressCompletion = (const char*)root["progress"]["completion"];
printerData.filamentLength = ""; printerData.progressFilepos = (const char*)root["progress"]["filepos"];
printerData.bedTemp = ""; printerData.progressPrintTime = (const char*)root["progress"]["printTime"];
printerData.bedTargetTemp = ""; printerData.progressPrintTimeLeft = (const char*)root["progress"]["printTimeLeft"];
printerData.isPrinting = false; printerData.filamentLength = (const char*)root["job"]["filament"]["tool0"]["length"];
printerData.error = ""; printerData.state = (const char*)root["state"];
}
if (isOperational()) {
String OctoPrintClient::getAveragePrintTime(){ Serial.println("Status: " + printerData.state);
return printerData.averagePrintTime; } else {
} Serial.println("Printer Not Operational");
}
String OctoPrintClient::getEstimatedPrintTime() {
return printerData.estimatedPrintTime; //**** get the Printer Temps and Stat
} apiGetData = "GET /api/printer?exclude=sd,history HTTP/1.1";
printClient = getSubmitRequest(apiGetData);
String OctoPrintClient::getFileName() { if (printerData.error != "") {
return printerData.fileName; return;
} }
const size_t bufferSize2 = 3*JSON_OBJECT_SIZE(2) + 2*JSON_OBJECT_SIZE(3) + JSON_OBJECT_SIZE(9) + 300;
String OctoPrintClient::getFileSize() { DynamicJsonBuffer jsonBuffer2(bufferSize2);
return printerData.fileSize;
} // Parse JSON object
JsonObject& root2 = jsonBuffer2.parseObject(printClient);
String OctoPrintClient::getLastPrintTime(){ if (!root2.success()) {
return printerData.lastPrintTime; printerData.isPrinting = false;
} printerData.toolTemp = "";
printerData.toolTargetTemp = "";
String OctoPrintClient::getProgressCompletion() { printerData.bedTemp = "";
return String(printerData.progressCompletion.toInt()); printerData.bedTargetTemp = (const char*)root2["temperature"]["bed"]["target"];
} return;
}
String OctoPrintClient::getProgressFilepos() {
return printerData.progressFilepos; String printing = (const char*)root2["state"]["flags"]["printing"];
} if (printing == "true") {
printerData.isPrinting = true;
String OctoPrintClient::getProgressPrintTime() { }
return printerData.progressPrintTime; printerData.toolTemp = (const char*)root2["temperature"]["tool0"]["actual"];
} printerData.toolTargetTemp = (const char*)root2["temperature"]["tool0"]["target"];
printerData.bedTemp = (const char*)root2["temperature"]["bed"]["actual"];
String OctoPrintClient::getProgressPrintTimeLeft() { printerData.bedTargetTemp = (const char*)root2["temperature"]["bed"]["target"];
String rtnValue = printerData.progressPrintTimeLeft;
if (getProgressCompletion() == "100") { if (isPrinting()) {
rtnValue = "0"; // Print is done so this should be 0 this is a fix for OctoPrint Serial.println("Status: " + printerData.state + " " + printerData.fileName + "(" + printerData.progressCompletion + "%)");
} }
return rtnValue; }
}
void OctoPrintClient::getPrinterPsuState() {
String OctoPrintClient::getState() { //**** get the PSU state (if enabled and printer operational)
return printerData.state; if (pollPsu && isOperational()) {
} if (!validate()) {
printerData.isPSUoff = false; // we do not know PSU state, so assume on.
boolean OctoPrintClient::isPrinting() { return;
return printerData.isPrinting; }
} String apiPostData = "POST /api/plugin/psucontrol HTTP/1.1";
String apiPostBody = "{\"command\":\"getPSUState\"}";
boolean OctoPrintClient::isOperational() { WiFiClient printClient = getPostRequest(apiPostData,apiPostBody);
boolean operational = false; if (printerData.error != "") {
if (printerData.state == "Operational" || isPrinting()) { printerData.isPSUoff = false; // we do not know PSU state, so assume on.
operational = true; return;
} }
return operational; const size_t bufferSize3 = JSON_OBJECT_SIZE(2) + 300;
} DynamicJsonBuffer jsonBuffer3(bufferSize3);
String OctoPrintClient::getTempBedActual() { // Parse JSON object
return printerData.bedTemp; JsonObject& root3 = jsonBuffer3.parseObject(printClient);
} if (!root3.success()) {
printerData.isPSUoff = false; // we do not know PSU state, so assume on
String OctoPrintClient::getTempBedTarget() { return;
return printerData.bedTargetTemp; }
}
String psu = (const char*)root3["isPSUOn"];
String OctoPrintClient::getTempToolActual() { if (psu == "true") {
return printerData.toolTemp; printerData.isPSUoff = false; // PSU checked and is on
} } else {
printerData.isPSUoff = true; // PSU checked and is off, set flag
String OctoPrintClient::getTempToolTarget() { }
return printerData.toolTargetTemp; printClient.stop(); //stop client
} } else {
printerData.isPSUoff = false; // we are not checking PSU state, so assume on
String OctoPrintClient::getFilamentLength() { }
return printerData.filamentLength; }
}
// Reset all PrinterData
String OctoPrintClient::getError() { void OctoPrintClient::resetPrintData() {
return printerData.error; printerData.averagePrintTime = "";
} printerData.estimatedPrintTime = "";
printerData.fileName = "";
String OctoPrintClient::getValueRounded(String value) { printerData.fileSize = "";
float f = value.toFloat(); printerData.lastPrintTime = "";
int rounded = (int)(f+0.5f); printerData.progressCompletion = "";
return String(rounded); printerData.progressFilepos = "";
printerData.progressPrintTime = "";
printerData.progressPrintTimeLeft = "";
printerData.state = "";
printerData.toolTemp = "";
printerData.toolTargetTemp = "";
printerData.filamentLength = "";
printerData.bedTemp = "";
printerData.bedTargetTemp = "";
printerData.isPrinting = false;
printerData.isPSUoff = false;
printerData.error = "";
}
String OctoPrintClient::getAveragePrintTime(){
return printerData.averagePrintTime;
}
String OctoPrintClient::getEstimatedPrintTime() {
return printerData.estimatedPrintTime;
}
String OctoPrintClient::getFileName() {
return printerData.fileName;
}
String OctoPrintClient::getFileSize() {
return printerData.fileSize;
}
String OctoPrintClient::getLastPrintTime(){
return printerData.lastPrintTime;
}
String OctoPrintClient::getProgressCompletion() {
return String(printerData.progressCompletion.toInt());
}
String OctoPrintClient::getProgressFilepos() {
return printerData.progressFilepos;
}
String OctoPrintClient::getProgressPrintTime() {
return printerData.progressPrintTime;
}
String OctoPrintClient::getProgressPrintTimeLeft() {
String rtnValue = printerData.progressPrintTimeLeft;
if (getProgressCompletion() == "100") {
rtnValue = "0"; // Print is done so this should be 0 this is a fix for OctoPrint
}
return rtnValue;
}
String OctoPrintClient::getState() {
return printerData.state;
}
boolean OctoPrintClient::isPrinting() {
return printerData.isPrinting;
}
boolean OctoPrintClient::isPSUoff() {
return printerData.isPSUoff;
}
boolean OctoPrintClient::isOperational() {
boolean operational = false;
if (printerData.state == "Operational" || isPrinting()) {
operational = true;
}
return operational;
}
String OctoPrintClient::getTempBedActual() {
return printerData.bedTemp;
}
String OctoPrintClient::getTempBedTarget() {
return printerData.bedTargetTemp;
}
String OctoPrintClient::getTempToolActual() {
return printerData.toolTemp;
}
String OctoPrintClient::getTempToolTarget() {
return printerData.toolTargetTemp;
}
String OctoPrintClient::getFilamentLength() {
return printerData.filamentLength;
}
String OctoPrintClient::getError() {
return printerData.error;
}
String OctoPrintClient::getValueRounded(String value) {
float f = value.toFloat();
int rounded = (int)(f+0.5f);
return String(rounded);
} }

View File

@ -1,91 +1,98 @@
/** The MIT License (MIT) /** The MIT License (MIT)
Copyright (c) 2018 David Payne
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
*/
#pragma once
#include <ESP8266WiFi.h>
#include <ArduinoJson.h>
#include <base64.h>
class OctoPrintClient {
private:
char myServer[100];
int myPort = 80;
String myApiKey = "";
String encodedAuth = "";
void resetPrintData();
boolean validate();
WiFiClient getSubmitRequest(String apiGetData);
String result;
typedef struct {
String averagePrintTime;
String estimatedPrintTime;
String fileName;
String fileSize;
String lastPrintTime;
String progressCompletion;
String progressFilepos;
String progressPrintTime;
String progressPrintTimeLeft;
String state;
String toolTemp;
String toolTargetTemp;
String filamentLength;
String bedTemp;
String bedTargetTemp;
boolean isPrinting;
String error;
} PrinterStruct;
PrinterStruct printerData;
public:
OctoPrintClient(String ApiKey, String server, int port, String user, String pass);
void getPrinterJobResults();
void updateOctoPrintClient(String ApiKey, String server, int port, String user, String pass);
String getAveragePrintTime();
String getEstimatedPrintTime();
String getFileName();
String getFileSize();
String getLastPrintTime();
String getProgressCompletion();
String getProgressFilepos();
String getProgressPrintTime();
String getProgressPrintTimeLeft();
String getState();
boolean isPrinting();
boolean isOperational();
String getTempBedActual();
String getTempBedTarget();
String getTempToolActual();
String getTempToolTarget();
String getFilamentLength();
String getValueRounded(String value);
String getError();
};
Copyright (c) 2018 David Payne
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
*/
// Additional Contributions:
/* 15 Jan 2019 : Owen Carter : Add psucontrol query via POST api call */
#pragma once
#include <ESP8266WiFi.h>
#include <ArduinoJson.h>
#include <base64.h>
class OctoPrintClient {
private:
char myServer[100];
int myPort = 80;
String myApiKey = "";
String encodedAuth = "";
boolean pollPsu;
void resetPrintData();
boolean validate();
WiFiClient getSubmitRequest(String apiGetData);
WiFiClient getPostRequest(String apiPostData, String apiPostBody);
String result;
typedef struct {
String averagePrintTime;
String estimatedPrintTime;
String fileName;
String fileSize;
String lastPrintTime;
String progressCompletion;
String progressFilepos;
String progressPrintTime;
String progressPrintTimeLeft;
String state;
String toolTemp;
String toolTargetTemp;
String filamentLength;
String bedTemp;
String bedTargetTemp;
boolean isPrinting;
boolean isPSUoff;
String error;
} PrinterStruct;
PrinterStruct printerData;
public:
OctoPrintClient(String ApiKey, String server, int port, String user, String pass, boolean psu);
void getPrinterJobResults();
void getPrinterPsuState();
void updateOctoPrintClient(String ApiKey, String server, int port, String user, String pass, boolean psu);
String getAveragePrintTime();
String getEstimatedPrintTime();
String getFileName();
String getFileSize();
String getLastPrintTime();
String getProgressCompletion();
String getProgressFilepos();
String getProgressPrintTime();
String getProgressPrintTimeLeft();
String getState();
boolean isPrinting();
boolean isOperational();
boolean isPSUoff();
String getTempBedActual();
String getTempBedTarget();
String getTempToolActual();
String getTempToolTarget();
String getFilamentLength();
String getValueRounded(String value);
String getError();
};

View File

@ -1,100 +1,111 @@
/** The MIT License (MIT) /** The MIT License (MIT)
Copyright (c) 2018 David Payne Copyright (c) 2018 David Payne
Permission is hereby granted, free of charge, to any person obtaining a copy Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions: furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software. copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE. SOFTWARE.
*/ */
/****************************************************************************** // Additional Contributions:
* Printer Monitor is designed for the Wemos D1 ESP8266 /* 15 Jan 2019 : Owen Carter : Add psucontrol setting */
* Wemos D1 Mini: https://amzn.to/2qLyKJd
* 0.96" OLED I2C 128x64 Display (12864) SSD1306 /******************************************************************************
* OLED Display: https://amzn.to/2JDEAUF * Printer Monitor is designed for the Wemos D1 ESP8266
******************************************************************************/ * Wemos D1 Mini: https://amzn.to/2qLyKJd
/****************************************************************************** * 0.96" OLED I2C 128x64 Display (12864) SSD1306
* NOTE: The settings here are the default settings for the first loading. * OLED Display: https://amzn.to/2JDEAUF
* After loading you will manage changes to the settings via the Web Interface. ******************************************************************************/
* If you want to change settings again in the settings.h, you will need to /******************************************************************************
* erase the file system on the Wemos or use the Reset Settings option in * NOTE: The settings here are the default settings for the first loading.
* the Web Interface. * After loading you will manage changes to the settings via the Web Interface.
******************************************************************************/ * If you want to change settings again in the settings.h, you will need to
* erase the file system on the Wemos or use the Reset Settings option in
#include <ESP8266WiFi.h> * the Web Interface.
#include <ESP8266WebServer.h> ******************************************************************************/
#include <WiFiManager.h>
#include <ESP8266mDNS.h> #include <ESP8266WiFi.h>
#include <ArduinoOTA.h> #include <ESP8266WebServer.h>
#include <ESP8266HTTPUpdateServer.h> #include <WiFiManager.h>
#include "TimeClient.h" #include <ESP8266mDNS.h>
#include "OctoPrintClient.h" #include <ArduinoOTA.h>
#include "OpenWeatherMapClient.h" #include <ESP8266HTTPUpdateServer.h>
#include "WeatherStationFonts.h" #include "TimeClient.h"
#include "FS.h" #include "OctoPrintClient.h"
#include "SH1106Wire.h" #include "OpenWeatherMapClient.h"
#include "SSD1306Wire.h" #include "WeatherStationFonts.h"
#include "OLEDDisplayUi.h" #include "FS.h"
#include "SH1106Wire.h"
//****************************** #include "SSD1306Wire.h"
// Start Settings #include "OLEDDisplayUi.h"
//******************************
//******************************
// OctoPrint Monitoring -- Monitor your 3D printer OctoPrint Server // Start Settings
String OctoPrintApiKey = ""; // ApiKey from your User Account on OctoPrint //******************************
String OctoPrintHostName = "octopi";// Default 'octopi' -- or hostname if different (optional if your IP changes)
String OctoPrintServer = ""; // IP or Address of your OctoPrint Server (DO NOT include http://) // OctoPrint Monitoring -- Monitor your 3D printer OctoPrint Server
int OctoPrintPort = 80; // the port you are running your OctoPrint server on (usually 80); String OctoPrintApiKey = ""; // ApiKey from your User Account on OctoPrint
String OctoAuthUser = ""; // only used if you have haproxy or basic athentintication turned on (not default) String OctoPrintHostName = "octopi";// Default 'octopi' -- or hostname if different (optional if your IP changes)
String OctoAuthPass = ""; // only used with haproxy or basic auth (only needed if you must authenticate) String OctoPrintServer = ""; // IP or Address of your OctoPrint Server (DO NOT include http://)
int OctoPrintPort = 80; // the port you are running your OctoPrint server on (usually 80);
// Weather Configuration String OctoAuthUser = ""; // only used if you have haproxy or basic athentintication turned on (not default)
boolean DISPLAYWEATHER = true; // true = show weather when not printing / false = no weather String OctoAuthPass = ""; // only used with haproxy or basic auth (only needed if you must authenticate)
String WeatherApiKey = ""; // Your API Key from http://openweathermap.org/
// Default City Location (use http://openweathermap.org/find to find city ID) // Weather Configuration
int CityIDs[] = { 5304391 }; //Only USE ONE for weather marquee boolean DISPLAYWEATHER = true; // true = show weather when not printing / false = no weather
boolean IS_METRIC = false; // false = Imperial and true = Metric String WeatherApiKey = ""; // Your API Key from http://openweathermap.org/
// 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 // Default City Location (use http://openweathermap.org/find to find city ID)
String WeatherLanguage = "en"; //Default (en) English int CityIDs[] = { 5304391 }; //Only USE ONE for weather marquee
boolean IS_METRIC = false; // false = Imperial and true = Metric
const int WEBSERVER_PORT = 80; // The port you can access this device on over HTTP // 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
const boolean WEBSERVER_ENABLED = true; // Device will provide a web interface via http://[ip]:[port]/ String WeatherLanguage = "en"; //Default (en) English
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 // Webserver
char* www_password = "password"; // Password for the Web Interface const int WEBSERVER_PORT = 80; // The port you can access this device on over HTTP
float UtcOffset = -7; // Hour offset from GMT for your timezone const boolean WEBSERVER_ENABLED = true; // Device will provide a web interface via http://[ip]:[port]/
boolean IS_24HOUR = false; // 23:00 millitary 24 hour clock boolean IS_BASIC_AUTH = true; // true = require athentication to change configuration settings / false = no auth
int minutesBetweenDataRefresh = 15; char* www_username = "admin"; // User account for the Web Interface
boolean DISPLAYCLOCK = true; // true = Show Clock when not printing / false = turn off display when not printing char* www_password = "password"; // Password for the Web Interface
// Display Settings // Date and Time
const int I2C_DISPLAY_ADDRESS = 0x3c; // I2C Address of your Display (usually 0x3c or 0x3d) float UtcOffset = -7; // Hour offset from GMT for your timezone
const int SDA_PIN = D2; boolean IS_24HOUR = false; // 23:00 millitary 24 hour clock
const int SCL_PIN = D5; int minutesBetweenDataRefresh = 15;
boolean INVERT_DISPLAY = false; // true = pins at top | false = pins at the bottom boolean DISPLAYCLOCK = true; // true = Show Clock when not printing / false = turn off display when not printing
//#define DISPLAY_SH1106 // Uncomment this line to use the SH1106 display -- SSD1306 is used by default and is most common
// Display Settings
// LED Settings const int I2C_DISPLAY_ADDRESS = 0x3c; // I2C Address of your Display (usually 0x3c or 0x3d)
const int externalLight = LED_BUILTIN; // Set to unused pin, like D1, to disable use of built-in LED (LED_BUILTIN) const int SDA_PIN = D2;
const int SCL_PIN = D5;
boolean ENABLE_OTA = true; // this will allow you to load firmware to the device over WiFi (see OTA for ESP8266) boolean INVERT_DISPLAY = false; // true = pins at top | false = pins at the bottom
String OTA_Password = ""; // Set an OTA password here -- leave blank if you don't want to be prompted for password //#define DISPLAY_SH1106 // Uncomment this line to use the SH1106 display -- SSD1306 is used by default and is most common
//******************************
// End Settings // LED Settings
//****************************** const int externalLight = LED_BUILTIN; // Set to unused pin, like D1, to disable use of built-in LED (LED_BUILTIN)
String themeColor = "light-green"; // this can be changed later in the web interface. // 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)
String OTA_Password = ""; // Set an OTA password here -- leave blank if you don't want to be prompted for password
//******************************
// End Settings
//******************************
String themeColor = "light-green"; // this can be changed later in the web interface.

File diff suppressed because it is too large Load Diff