Traducción al Español - Spanish translation

pull/176/head
Eduardo 2024-03-04 02:35:06 +00:00
parent bd8422b228
commit bc2cb9e25a
101 changed files with 1003 additions and 1003 deletions

View File

@ -1,414 +1,414 @@
/** 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.
*/
// Additional Contributions:
/* 15 Jan 2019 : Owen Carter : Add psucontrol query via POST api call */
#include "OctoPrintClient.h"
OctoPrintClient::OctoPrintClient(String ApiKey, String server, int port, String user, String pass, boolean psu) {
updatePrintClient(ApiKey, server, port, user, pass, psu);
}
void OctoPrintClient::updatePrintClient(String ApiKey, String server, int port, String user, String pass, boolean psu) {
server.toCharArray(myServer, 100);
myApiKey = ApiKey;
myPort = port;
encodedAuth = "";
if (user != "") {
String userpass = user + ":" + pass;
base64 b64;
encodedAuth = b64.encode(userpass, true);
}
pollPsu = psu;
}
boolean OctoPrintClient::validate() {
boolean rtnValue = false;
printerData.error = "";
if (String(myServer) == "") {
printerData.error += "Server address is required; ";
}
if (myApiKey == "") {
printerData.error += "ApiKey is required; ";
}
if (printerData.error == "") {
rtnValue = true;
}
return rtnValue;
}
WiFiClient OctoPrintClient::getSubmitRequest(String apiGetData) {
WiFiClient printClient;
printClient.setTimeout(5000);
Serial.println("Getting Octoprint Data via GET");
Serial.println(apiGetData);
result = "";
if (printClient.connect(myServer, myPort)) { //starts client connection, checks for connection
printClient.println(apiGetData);
printClient.println("Host: " + String(myServer) + ":" + String(myPort));
printClient.println("X-Api-Key: " + myApiKey);
if (encodedAuth != "") {
printClient.print("Authorization: ");
printClient.println("Basic " + encodedAuth);
}
printClient.println("User-Agent: ArduinoWiFi/1.1");
printClient.println("Connection: close");
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;
}
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() {
if (!validate()) {
return;
}
//**** get the Printer Job status
String apiGetData = "GET /api/job HTTP/1.1";
WiFiClient printClient = getSubmitRequest(apiGetData);
if (printerData.error != "") {
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;
DynamicJsonBuffer jsonBuffer(bufferSize);
// Parse JSON object
JsonObject& root = jsonBuffer.parseObject(printClient);
if (!root.success()) {
Serial.println("OctoPrint Data Parsing failed: " + String(myServer) + ":" + String(myPort));
printerData.error = "OctoPrint Data Parsing failed: " + String(myServer) + ":" + String(myPort);
printerData.state = "";
return;
}
printerData.averagePrintTime = (const char*)root["job"]["averagePrintTime"];
printerData.estimatedPrintTime = (const char*)root["job"]["estimatedPrintTime"];
printerData.fileName = (const char*)root["job"]["file"]["name"];
printerData.fileSize = (const char*)root["job"]["file"]["size"];
printerData.lastPrintTime = (const char*)root["job"]["lastPrintTime"];
printerData.progressCompletion = (const char*)root["progress"]["completion"];
printerData.progressFilepos = (const char*)root["progress"]["filepos"];
printerData.progressPrintTime = (const char*)root["progress"]["printTime"];
printerData.progressPrintTimeLeft = (const char*)root["progress"]["printTimeLeft"];
printerData.filamentLength = (const char*)root["job"]["filament"]["tool0"]["length"];
printerData.state = (const char*)root["state"];
if (isOperational()) {
Serial.println("Status: " + printerData.state);
} else {
Serial.println("Printer Not Operational");
}
//**** get the Printer Temps and Stat
apiGetData = "GET /api/printer?exclude=sd,history HTTP/1.1";
printClient = getSubmitRequest(apiGetData);
if (printerData.error != "") {
return;
}
const size_t bufferSize2 = 3*JSON_OBJECT_SIZE(2) + 2*JSON_OBJECT_SIZE(3) + JSON_OBJECT_SIZE(9) + 300;
DynamicJsonBuffer jsonBuffer2(bufferSize2);
// Parse JSON object
JsonObject& root2 = jsonBuffer2.parseObject(printClient);
if (!root2.success()) {
printerData.isPrinting = false;
printerData.toolTemp = "";
printerData.toolTargetTemp = "";
printerData.bedTemp = "";
printerData.bedTargetTemp = (const char*)root2["temperature"]["bed"]["target"];
return;
}
String printing = (const char*)root2["state"]["flags"]["printing"];
if (printing == "true") {
printerData.isPrinting = true;
} else {
printerData.isPrinting = false;
}
printerData.toolTemp = (const char*)root2["temperature"]["tool0"]["actual"];
printerData.toolTargetTemp = (const char*)root2["temperature"]["tool0"]["target"];
printerData.bedTemp = (const char*)root2["temperature"]["bed"]["actual"];
printerData.bedTargetTemp = (const char*)root2["temperature"]["bed"]["target"];
if (isPrinting()) {
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
} else {
printerData.isPSUoff = false; // we are not checking PSU state, so assume on
}
}
// Reset all PrinterData
void OctoPrintClient::resetPrintData() {
printerData.averagePrintTime = "";
printerData.estimatedPrintTime = "";
printerData.fileName = "";
printerData.fileSize = "";
printerData.lastPrintTime = "";
printerData.progressCompletion = "";
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);
}
String OctoPrintClient::getPrinterType() {
return printerType;
}
int OctoPrintClient::getPrinterPort() {
return myPort;
}
String OctoPrintClient::getPrinterName() {
return printerData.printerName;
}
void OctoPrintClient::setPrinterName(String printer) {
printerData.printerName = printer;
}
/** 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.
*/
// Additional Contributions:
/* 15 Jan 2019 : Owen Carter : Add psucontrol query via POST api call */
#include "OctoPrintClient.h"
OctoPrintClient::OctoPrintClient(String ApiKey, String server, int port, String user, String pass, boolean psu) {
updatePrintClient(ApiKey, server, port, user, pass, psu);
}
void OctoPrintClient::updatePrintClient(String ApiKey, String server, int port, String user, String pass, boolean psu) {
server.toCharArray(myServer, 100);
myApiKey = ApiKey;
myPort = port;
encodedAuth = "";
if (user != "") {
String userpass = user + ":" + pass;
base64 b64;
encodedAuth = b64.encode(userpass, true);
}
pollPsu = psu;
}
boolean OctoPrintClient::validate() {
boolean rtnValue = false;
printerData.error = "";
if (String(myServer) == "") {
printerData.error += "La dirección del servidor es obligatoria; ";
}
if (myApiKey == "") {
printerData.error += "La ApiKey es obligatoria; ";
}
if (printerData.error == "") {
rtnValue = true;
}
return rtnValue;
}
WiFiClient OctoPrintClient::getSubmitRequest(String apiGetData) {
WiFiClient printClient;
printClient.setTimeout(5000);
Serial.println("Obteniendo datos de Octoprint via GET");
Serial.println(apiGetData);
result = "";
if (printClient.connect(myServer, myPort)) { //starts client connection, checks for connection
printClient.println(apiGetData);
printClient.println("Host: " + String(myServer) + ":" + String(myPort));
printClient.println("X-Api-Key: " + myApiKey);
if (encodedAuth != "") {
printClient.print("Authorization: ");
printClient.println("Basic " + encodedAuth);
}
printClient.println("User-Agent: ArduinoWiFi/1.1");
printClient.println("Connection: close");
if (printClient.println() == 0) {
Serial.println("Conexión a " + String(myServer) + ":" + String(myPort) + " fallida.");
Serial.println();
resetPrintData();
printerData.error = "Conexión a " + String(myServer) + ":" + String(myPort) + " fallida.";
return printClient;
}
}
else {
Serial.println("Conexión a OctoPrint fallida: " + String(myServer) + ":" + String(myPort)); //error message if no client connect
Serial.println();
resetPrintData();
printerData.error = "Conexión a OctoPrint fallida: " + 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("Respuesta inesperada: "));
Serial.println(status);
printerData.state = "";
printerData.error = "Respuesta: " + String(status);
return printClient;
}
// Skip HTTP headers
char endOfHeaders[] = "\r\n\r\n";
if (!printClient.find(endOfHeaders)) {
Serial.println(F("Respuesta no válida"));
printerData.error = "Respuesta no válida de " + String(myServer) + ":" + String(myPort);
printerData.state = "";
}
return printClient;
}
WiFiClient OctoPrintClient::getPostRequest(String apiPostData, String apiPostBody) {
WiFiClient printClient;
printClient.setTimeout(5000);
Serial.println("Obteniendo datos de Octoprint 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("Conexión: 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("Conexión a " + String(myServer) + ":" + String(myPort) + " fallida.");
Serial.println();
resetPrintData();
printerData.error = "Conexión a " + String(myServer) + ":" + String(myPort) + " fallida.";
return printClient;
}
}
else {
Serial.println("Conexión a OctoPrint fallida: " + String(myServer) + ":" + String(myPort)); //error message if no client connect
Serial.println();
resetPrintData();
printerData.error = "Conexión a OctoPrint fallida: " + 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("Respuesta inesperada: "));
Serial.println(status);
printerData.state = "";
printerData.error = "Respuesta: " + String(status);
return printClient;
}
// Skip HTTP headers
char endOfHeaders[] = "\r\n\r\n";
if (!printClient.find(endOfHeaders)) {
Serial.println(F("Respuesta no válida"));
printerData.error = "Respuesta no válida de " + String(myServer) + ":" + String(myPort);
printerData.state = "";
}
return printClient;
}
void OctoPrintClient::getPrinterJobResults() {
if (!validate()) {
return;
}
//**** get the Printer Job status
String apiGetData = "GET /api/job HTTP/1.1";
WiFiClient printClient = getSubmitRequest(apiGetData);
if (printerData.error != "") {
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;
DynamicJsonBuffer jsonBuffer(bufferSize);
// Parse JSON object
JsonObject& root = jsonBuffer.parseObject(printClient);
if (!root.success()) {
Serial.println("Fallo al parsear los datos de OctoPrint: " + String(myServer) + ":" + String(myPort));
printerData.error = "Fallo al parsear los datos de OctoPrint: " + String(myServer) + ":" + String(myPort);
printerData.state = "";
return;
}
printerData.averagePrintTime = (const char*)root["job"]["averagePrintTime"];
printerData.estimatedPrintTime = (const char*)root["job"]["estimatedPrintTime"];
printerData.fileName = (const char*)root["job"]["file"]["name"];
printerData.fileSize = (const char*)root["job"]["file"]["size"];
printerData.lastPrintTime = (const char*)root["job"]["lastPrintTime"];
printerData.progressCompletion = (const char*)root["progress"]["completion"];
printerData.progressFilepos = (const char*)root["progress"]["filepos"];
printerData.progressPrintTime = (const char*)root["progress"]["printTime"];
printerData.progressPrintTimeLeft = (const char*)root["progress"]["printTimeLeft"];
printerData.filamentLength = (const char*)root["job"]["filament"]["tool0"]["length"];
printerData.state = (const char*)root["state"];
if (isOperational()) {
Serial.println("Estado: " + printerData.state);
} else {
Serial.println("Impresora no disponible");
}
//**** get the Printer Temps and Stat
apiGetData = "GET /api/printer?exclude=sd,history HTTP/1.1";
printClient = getSubmitRequest(apiGetData);
if (printerData.error != "") {
return;
}
const size_t bufferSize2 = 3*JSON_OBJECT_SIZE(2) + 2*JSON_OBJECT_SIZE(3) + JSON_OBJECT_SIZE(9) + 300;
DynamicJsonBuffer jsonBuffer2(bufferSize2);
// Parse JSON object
JsonObject& root2 = jsonBuffer2.parseObject(printClient);
if (!root2.success()) {
printerData.isPrinting = false;
printerData.toolTemp = "";
printerData.toolTargetTemp = "";
printerData.bedTemp = "";
printerData.bedTargetTemp = (const char*)root2["temperature"]["bed"]["target"];
return;
}
String printing = (const char*)root2["state"]["flags"]["printing"];
if (printing == "true") {
printerData.isPrinting = true;
} else {
printerData.isPrinting = false;
}
printerData.toolTemp = (const char*)root2["temperature"]["tool0"]["actual"];
printerData.toolTargetTemp = (const char*)root2["temperature"]["tool0"]["target"];
printerData.bedTemp = (const char*)root2["temperature"]["bed"]["actual"];
printerData.bedTargetTemp = (const char*)root2["temperature"]["bed"]["target"];
if (isPrinting()) {
Serial.println("Estado: " + 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
} else {
printerData.isPSUoff = false; // we are not checking PSU state, so assume on
}
}
// Reset all PrinterData
void OctoPrintClient::resetPrintData() {
printerData.averagePrintTime = "";
printerData.estimatedPrintTime = "";
printerData.fileName = "";
printerData.fileSize = "";
printerData.lastPrintTime = "";
printerData.progressCompletion = "";
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);
}
String OctoPrintClient::getPrinterType() {
return printerType;
}
int OctoPrintClient::getPrinterPort() {
return myPort;
}
String OctoPrintClient::getPrinterName() {
return printerData.printerName;
}
void OctoPrintClient::setPrinterName(String printer) {
printerData.printerName = printer;
}

0
printermonitor/OctoPrintClient.h Normal file → Executable file
View File

View File

@ -37,7 +37,7 @@ void OpenWeatherMapClient::updateWeatherApiKey(String ApiKey) {
void OpenWeatherMapClient::updateLanguage(String language) {
lang = language;
if (lang == "") {
lang = "en";
lang = "es";
}
}
@ -45,7 +45,7 @@ void OpenWeatherMapClient::updateWeather() {
WiFiClient weatherClient;
String apiGetData = "GET /data/2.5/group?id=" + myCityIDs + "&units=" + units + "&cnt=1&APPID=" + myApiKey + "&lang=" + lang + " HTTP/1.1";
Serial.println("Getting Weather Data");
Serial.println("Obteniendo datos de clima");
Serial.println(apiGetData);
result = "";
if (weatherClient.connect(servername, 80)) { //starts client connection, checks for connection
@ -56,14 +56,14 @@ void OpenWeatherMapClient::updateWeather() {
weatherClient.println();
}
else {
Serial.println("connection for weather data failed"); //error message if no client connect
Serial.println("conexión fallida al obtener datos del clima"); //error message if no client connect
Serial.println();
return;
}
while(weatherClient.connected() && !weatherClient.available()) delay(1); //waits for data
Serial.println("Waiting for data");
Serial.println("Esperando por datos");
// Check HTTP status
char status[32] = {0};
@ -78,7 +78,7 @@ void OpenWeatherMapClient::updateWeather() {
// Skip HTTP headers
char endOfHeaders[] = "\r\n\r\n";
if (!weatherClient.find(endOfHeaders)) {
Serial.println(F("Invalid response"));
Serial.println(F("Respuesta no válida"));
return;
}
@ -90,15 +90,15 @@ void OpenWeatherMapClient::updateWeather() {
// Parse JSON object
JsonObject& root = jsonBuffer.parseObject(weatherClient);
if (!root.success()) {
Serial.println(F("Weather Data Parsing failed!"));
weathers[0].error = "Weather Data Parsing failed!";
Serial.println(F("Fallo al parsear los datos del clima!"));
weathers[0].error = "Fallo al parsear los datos del clima!";
return;
}
weatherClient.stop(); //stop client
if (root.measureLength() <= 150) {
Serial.println("Error Does not look like we got the data. Size: " + String(root.measureLength()));
Serial.println("Error No parece que hayamos obtenido los datos. Tamaño: " + String(root.measureLength()));
weathers[0].cached = true;
weathers[0].error = (const char*)root["message"];
Serial.println("Error: " + weathers[0].error);
@ -308,4 +308,4 @@ String OpenWeatherMapClient::getWeatherIcon(int index)
default:break;
}
return W;
}
}

0
printermonitor/OpenWeatherMapClient.h Normal file → Executable file
View File

View File

@ -1,367 +1,367 @@
/** 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.
*/
// Additional Contributions:
/* 15 Jan 2019 : Owen Carter : Add psucontrol query via POST api call */
/* 07 April 2019 : Jon Smith : Redesigned this class for Repetier Server */
#include "RepetierClient.h"
RepetierClient::RepetierClient(String ApiKey, String server, int port, String user, String pass, boolean psu) {
updatePrintClient(ApiKey, server, port, user, pass, psu);
}
void RepetierClient::updatePrintClient(String ApiKey, String server, int port, String user, String pass, boolean psu) {
server.toCharArray(myServer, 100);
myApiKey = ApiKey;
myPort = port;
encodedAuth = "";
if (user != "") {
String userpass = user + ":" + pass;
base64 b64;
encodedAuth = b64.encode(userpass, true);
}
pollPsu = psu;
}
boolean RepetierClient::validate() {
boolean rtnValue = false;
printerData.error = "";
if (String(myServer) == "") {
printerData.error += "Server address is required; ";
}
if (myApiKey == "") {
printerData.error += "ApiKey is required; ";
}
if (printerData.error == "") {
rtnValue = true;
}
return rtnValue;
}
WiFiClient RepetierClient::getSubmitRequest(String apiGetData) {
WiFiClient printClient;
printClient.setTimeout(5000);
Serial.println("Getting Repetier Data via GET");
Serial.println(apiGetData);
result = "";
if (printClient.connect(myServer, myPort)) { //starts client connection, checks for connection
printClient.println(apiGetData);
printClient.println("Host: " + String(myServer) + ":" + String(myPort));
printClient.println("X-Api-Key: " + myApiKey);
if (encodedAuth != "") {
printClient.print("Authorization: ");
printClient.println("Basic " + encodedAuth);
}
printClient.println("User-Agent: ArduinoWiFi/1.1");
printClient.println("Connection: close");
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 Repetier failed: " + String(myServer) + ":" + String(myPort)); //error message if no client connect
Serial.println();
resetPrintData();
printerData.error = "Connection to Repetier 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) {
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 RepetierClient::getPrinterJobResults() {
if (!validate()) {
return;
}
//**** get the Printer Job status
String apiGetData = "GET /printer/api/?a=listPrinter&apikey=" + myApiKey;
WiFiClient printClient = getSubmitRequest(apiGetData);
if (printerData.error != "") {
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;
DynamicJsonBuffer jsonBuffer(bufferSize);
// Parse JSON object
JsonArray& root = jsonBuffer.parseArray(printClient);
if (!root.success()) {
printerData.error = "Repetier Data Parsing failed: " + String(myServer) + ":" + String(myPort);
Serial.println(printerData.error);
printerData.state = "";
return;
}
int inx = 0;
int count = root.size();
Serial.println("Size of root: " + String(count));
for (int i = 0; i < count; i++) {
Serial.println("Printer: " + String((const char*)root[i]["slug"]));
if (String((const char*)root[i]["slug"]) == printerData.printerName) {
inx = i;
break;
}
}
JsonObject& pr = root[inx];
//printerData.averagePrintTime = (const char*)pr[""];
printerData.estimatedPrintTime = (const char*)pr["printTime"];
printerData.fileName = (const char*) pr["job"];
printerData.fileSize = (const char*) pr["totalLines"];
//printerData.filamentLength = (const char*) pr[""];
printerData.state = (const char*) pr["online"];
//printerData.lastPrintTime = (const char*) pr[""];
printerData.progressCompletion = (const char*) pr["done"];
printerData.progressFilepos = (const char*) pr["linesSend"];
printerData.progressPrintTime = (const char*) pr["printedTimeComp"];
//Figure out Time Left
long timeTot=0;
long timeElap=0;
long timeLeft=0;
if (printerData.estimatedPrintTime != "" ) {
timeTot = atol(pr["printTime"]);
}
if (printerData.progressPrintTime != "") {
timeElap= atol(pr["printedTimeComp"]);
}
timeLeft = timeTot-timeElap;
printerData.progressPrintTimeLeft = String(timeLeft);
if (printerData.fileName != "none") {
printerData.isPrinting = true;
} else {
printerData.isPrinting = false;
}
if (printerData.isPrinting) {
Serial.println("Printing: " + printerData.fileName);
}
if (isOperational()) {
Serial.println("Status: " + printerData.state);
} else {
Serial.println("Printer Not Operational");
}
//**** get the Printer Temps and Stat
apiGetData = "GET /printer/api/?a=stateList&apikey=" + myApiKey;
printClient = getSubmitRequest(apiGetData);
if (printerData.error != "") {
return;
}
const size_t bufferSize2 = 3*JSON_OBJECT_SIZE(2) + 2*JSON_OBJECT_SIZE(3) + JSON_OBJECT_SIZE(9) + 300;
DynamicJsonBuffer jsonBuffer2(bufferSize2);
//Parse JSON object
JsonObject& root2 = jsonBuffer2.parseObject(printClient);
//Select printer
JsonObject& pr2 = root2[printerData.printerName];
if (!root2.success()) {
printerData.isPrinting = false;
printerData.toolTemp = "";
printerData.toolTargetTemp = "";
printerData.bedTemp = "";
printerData.bedTargetTemp = "";
return;
}
printerData.toolTemp = (const char*) pr2["extruder"][0]["tempRead"];
printerData.toolTargetTemp = (const char*) pr2["extruder"][0]["tempSet"];
printerData.bedTemp = (const char*) pr2["heatedBeds"][0]["tempRead"];
printerData.bedTargetTemp = (const char*) pr2["heatedBeds"][0]["tempSet"];
if (printerData.isPrinting) {
Serial.println("Status: " + printerData.state + " " + printerData.fileName + "(" + printerData.progressCompletion + "%)");
}
}
void RepetierClient::getPrinterPsuState() {
//**** get the PSU state (if enabled and printer operational)
//Not implemented in Repetier Server AFAIK
}
// Reset all PrinterData
void RepetierClient::resetPrintData() {
printerData.averagePrintTime = "";
printerData.estimatedPrintTime = "";
printerData.fileName = "";
printerData.fileSize = "";
printerData.lastPrintTime = "";
printerData.progressCompletion = "";
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 RepetierClient::getAveragePrintTime(){
return printerData.averagePrintTime;
}
String RepetierClient::getEstimatedPrintTime() {
return printerData.estimatedPrintTime;
}
String RepetierClient::getFileName() {
return printerData.fileName;
}
String RepetierClient::getFileSize() {
return printerData.fileSize;
}
String RepetierClient::getLastPrintTime(){
return printerData.lastPrintTime;
}
String RepetierClient::getProgressCompletion() {
return String(printerData.progressCompletion.toInt());
}
String RepetierClient::getProgressFilepos() {
return printerData.progressFilepos;
}
String RepetierClient::getProgressPrintTime() {
return printerData.progressPrintTime;
}
String RepetierClient::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 RepetierClient::getState() {
String rtnValue = "Offline";
if (printerData.state == "1") {
rtnValue = "Operational";
}
return rtnValue;
}
boolean RepetierClient::isPrinting() {
return printerData.isPrinting;
}
boolean RepetierClient::isPSUoff() {
return printerData.isPSUoff;
}
boolean RepetierClient::isOperational() {
boolean operational = false;
if (printerData.state == "1" || isPrinting()) {
operational = true;
}
return operational;
}
String RepetierClient::getTempBedActual() {
String temp = printerData.bedTemp;
temp.remove(temp.indexOf(".") + 3);
return temp;
}
String RepetierClient::getTempBedTarget() {
return printerData.bedTargetTemp;
}
String RepetierClient::getTempToolActual() {
String temp = printerData.toolTemp;
temp.remove(temp.indexOf(".") + 3);
return temp;
}
String RepetierClient::getTempToolTarget() {
return printerData.toolTargetTemp;
}
String RepetierClient::getFilamentLength() {
return printerData.filamentLength;
}
String RepetierClient::getError() {
return printerData.error;
}
String RepetierClient::getValueRounded(String value) {
float f = value.toFloat();
int rounded = (int)(f+0.5f);
return String(rounded);
}
String RepetierClient::getPrinterType() {
return printerType;
}
int RepetierClient::getPrinterPort() {
return myPort;
}
String RepetierClient::getPrinterName() {
return printerData.printerName;
}
void RepetierClient::setPrinterName(String printer) {
printerData.printerName = printer;
}
/** 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.
*/
// Additional Contributions:
/* 15 Jan 2019 : Owen Carter : Add psucontrol query via POST api call */
/* 07 April 2019 : Jon Smith : Redesigned this class for Repetier Server */
#include "RepetierClient.h"
RepetierClient::RepetierClient(String ApiKey, String server, int port, String user, String pass, boolean psu) {
updatePrintClient(ApiKey, server, port, user, pass, psu);
}
void RepetierClient::updatePrintClient(String ApiKey, String server, int port, String user, String pass, boolean psu) {
server.toCharArray(myServer, 100);
myApiKey = ApiKey;
myPort = port;
encodedAuth = "";
if (user != "") {
String userpass = user + ":" + pass;
base64 b64;
encodedAuth = b64.encode(userpass, true);
}
pollPsu = psu;
}
boolean RepetierClient::validate() {
boolean rtnValue = false;
printerData.error = "";
if (String(myServer) == "") {
printerData.error += "La dirección del servidor es obligatoria; ";
}
if (myApiKey == "") {
printerData.error += "La ApiKey es obligatoria; ";
}
if (printerData.error == "") {
rtnValue = true;
}
return rtnValue;
}
WiFiClient RepetierClient::getSubmitRequest(String apiGetData) {
WiFiClient printClient;
printClient.setTimeout(5000);
Serial.println("Obteniendo datos del Repetidor via GET");
Serial.println(apiGetData);
result = "";
if (printClient.connect(myServer, myPort)) { //starts client connection, checks for connection
printClient.println(apiGetData);
printClient.println("Host: " + String(myServer) + ":" + String(myPort));
printClient.println("X-Api-Key: " + myApiKey);
if (encodedAuth != "") {
printClient.print("Authorization: ");
printClient.println("Basic " + encodedAuth);
}
printClient.println("User-Agent: ArduinoWiFi/1.1");
printClient.println("Connection: close");
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("Conexión a OctoPrint fallida: " + String(myServer) + ":" + String(myPort)); //error message if no client connect
Serial.println();
resetPrintData();
printerData.error = "Conexión a OctoPrint fallida: " + 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) {
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 RepetierClient::getPrinterJobResults() {
if (!validate()) {
return;
}
//**** get the Printer Job status
String apiGetData = "GET /printer/api/?a=listPrinter&apikey=" + myApiKey;
WiFiClient printClient = getSubmitRequest(apiGetData);
if (printerData.error != "") {
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;
DynamicJsonBuffer jsonBuffer(bufferSize);
// Parse JSON object
JsonArray& root = jsonBuffer.parseArray(printClient);
if (!root.success()) {
printerData.error = "Fallo al parsear los datos de OctoPrint: " + String(myServer) + ":" + String(myPort);
Serial.println(printerData.error);
printerData.state = "";
return;
}
int inx = 0;
int count = root.size();
Serial.println("Size of root: " + String(count));
for (int i = 0; i < count; i++) {
Serial.println("Printer: " + String((const char*)root[i]["slug"]));
if (String((const char*)root[i]["slug"]) == printerData.printerName) {
inx = i;
break;
}
}
JsonObject& pr = root[inx];
//printerData.averagePrintTime = (const char*)pr[""];
printerData.estimatedPrintTime = (const char*)pr["printTime"];
printerData.fileName = (const char*) pr["job"];
printerData.fileSize = (const char*) pr["totalLines"];
//printerData.filamentLength = (const char*) pr[""];
printerData.state = (const char*) pr["online"];
//printerData.lastPrintTime = (const char*) pr[""];
printerData.progressCompletion = (const char*) pr["done"];
printerData.progressFilepos = (const char*) pr["linesSend"];
printerData.progressPrintTime = (const char*) pr["printedTimeComp"];
//Figure out Time Left
long timeTot=0;
long timeElap=0;
long timeLeft=0;
if (printerData.estimatedPrintTime != "" ) {
timeTot = atol(pr["printTime"]);
}
if (printerData.progressPrintTime != "") {
timeElap= atol(pr["printedTimeComp"]);
}
timeLeft = timeTot-timeElap;
printerData.progressPrintTimeLeft = String(timeLeft);
if (printerData.fileName != "none") {
printerData.isPrinting = true;
} else {
printerData.isPrinting = false;
}
if (printerData.isPrinting) {
Serial.println("Printing: " + printerData.fileName);
}
if (isOperational()) {
Serial.println("Estado: " + printerData.state);
} else {
Serial.println("Impresora no disponible");
}
//**** get the Printer Temps and Stat
apiGetData = "GET /printer/api/?a=stateList&apikey=" + myApiKey;
printClient = getSubmitRequest(apiGetData);
if (printerData.error != "") {
return;
}
const size_t bufferSize2 = 3*JSON_OBJECT_SIZE(2) + 2*JSON_OBJECT_SIZE(3) + JSON_OBJECT_SIZE(9) + 300;
DynamicJsonBuffer jsonBuffer2(bufferSize2);
//Parse JSON object
JsonObject& root2 = jsonBuffer2.parseObject(printClient);
//Select printer
JsonObject& pr2 = root2[printerData.printerName];
if (!root2.success()) {
printerData.isPrinting = false;
printerData.toolTemp = "";
printerData.toolTargetTemp = "";
printerData.bedTemp = "";
printerData.bedTargetTemp = "";
return;
}
printerData.toolTemp = (const char*) pr2["extruder"][0]["tempRead"];
printerData.toolTargetTemp = (const char*) pr2["extruder"][0]["tempSet"];
printerData.bedTemp = (const char*) pr2["heatedBeds"][0]["tempRead"];
printerData.bedTargetTemp = (const char*) pr2["heatedBeds"][0]["tempSet"];
if (printerData.isPrinting) {
Serial.println("Status: " + printerData.state + " " + printerData.fileName + "(" + printerData.progressCompletion + "%)");
}
}
void RepetierClient::getPrinterPsuState() {
//**** get the PSU state (if enabled and printer operational)
//Not implemented in Repetier Server AFAIK
}
// Reset all PrinterData
void RepetierClient::resetPrintData() {
printerData.averagePrintTime = "";
printerData.estimatedPrintTime = "";
printerData.fileName = "";
printerData.fileSize = "";
printerData.lastPrintTime = "";
printerData.progressCompletion = "";
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 RepetierClient::getAveragePrintTime(){
return printerData.averagePrintTime;
}
String RepetierClient::getEstimatedPrintTime() {
return printerData.estimatedPrintTime;
}
String RepetierClient::getFileName() {
return printerData.fileName;
}
String RepetierClient::getFileSize() {
return printerData.fileSize;
}
String RepetierClient::getLastPrintTime(){
return printerData.lastPrintTime;
}
String RepetierClient::getProgressCompletion() {
return String(printerData.progressCompletion.toInt());
}
String RepetierClient::getProgressFilepos() {
return printerData.progressFilepos;
}
String RepetierClient::getProgressPrintTime() {
return printerData.progressPrintTime;
}
String RepetierClient::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 RepetierClient::getState() {
String rtnValue = "Offline";
if (printerData.state == "1") {
rtnValue = "Operational";
}
return rtnValue;
}
boolean RepetierClient::isPrinting() {
return printerData.isPrinting;
}
boolean RepetierClient::isPSUoff() {
return printerData.isPSUoff;
}
boolean RepetierClient::isOperational() {
boolean operational = false;
if (printerData.state == "1" || isPrinting()) {
operational = true;
}
return operational;
}
String RepetierClient::getTempBedActual() {
String temp = printerData.bedTemp;
temp.remove(temp.indexOf(".") + 3);
return temp;
}
String RepetierClient::getTempBedTarget() {
return printerData.bedTargetTemp;
}
String RepetierClient::getTempToolActual() {
String temp = printerData.toolTemp;
temp.remove(temp.indexOf(".") + 3);
return temp;
}
String RepetierClient::getTempToolTarget() {
return printerData.toolTargetTemp;
}
String RepetierClient::getFilamentLength() {
return printerData.filamentLength;
}
String RepetierClient::getError() {
return printerData.error;
}
String RepetierClient::getValueRounded(String value) {
float f = value.toFloat();
int rounded = (int)(f+0.5f);
return String(rounded);
}
String RepetierClient::getPrinterType() {
return printerType;
}
int RepetierClient::getPrinterPort() {
return myPort;
}
String RepetierClient::getPrinterName() {
return printerData.printerName;
}
void RepetierClient::setPrinterName(String printer) {
printerData.printerName = printer;
}

0
printermonitor/RepetierClient.h Normal file → Executable file
View File

View File

@ -1,114 +1,114 @@
/** 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.
*/
// Additional Contributions:
/* 15 Jan 2019 : Owen Carter : Add psucontrol setting */
/******************************************************************************
* Printer Monitor is designed for the Wemos D1 ESP8266
* Wemos D1 Mini: https://amzn.to/2qLyKJd
* 0.96" OLED I2C 128x64 Display (12864) SSD1306
* OLED Display: https://amzn.to/2JDEAUF
******************************************************************************/
/******************************************************************************
* NOTE: The settings here are the default settings for the first loading.
* 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
* the Web Interface.
******************************************************************************/
#include <ESP8266WiFi.h>
#include <ESP8266WebServer.h>
#include <WiFiManager.h>
#include <ESP8266mDNS.h>
#include <ArduinoOTA.h>
#include <ESP8266HTTPUpdateServer.h>
#include "TimeClient.h"
#include "RepetierClient.h"
#include "OctoPrintClient.h"
#include "OpenWeatherMapClient.h"
#include "WeatherStationFonts.h"
#include "FS.h"
#include "SH1106Wire.h"
#include "SSD1306Wire.h"
#include "OLEDDisplayUi.h"
//******************************
// Start Settings
//******************************
// OctoPrint / Repetier Monitoring -- Monitor your 3D OctoPrint or Repetier Server
//#define USE_REPETIER_CLIENT // Uncomment this line to use the Repetier Printer Server -- OctoPrint is used by default and is most common
String PrinterApiKey = ""; // ApiKey from your User Account on OctoPrint / Repetier
String PrinterHostName = "octopi";// Default 'octopi' -- or hostname if different (optional if your IP changes)
String PrinterServer = ""; // IP or Address of your OctoPrint / Repetier Server (DO NOT include http://)
int PrinterPort = 80; // the port you are running your OctoPrint / Repetier server on (usually 80);
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
boolean DISPLAYWEATHER = true; // true = show weather when not printing / false = no weather
String WeatherApiKey = ""; // Your API Key from http://openweathermap.org/
// Default City Location (use http://openweathermap.org/find to find city ID)
int CityIDs[] = { 5304391 }; //Only USE ONE for weather marquee
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
String WeatherLanguage = "en"; //Default (en) English
// Webserver
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]/
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_password = "password"; // Password for the Web Interface
// Date and Time
float UtcOffset = -7; // Hour offset from GMT for your timezone
boolean IS_24HOUR = false; // 23:00 millitary 24 hour clock
int minutesBetweenDataRefresh = 15;
boolean DISPLAYCLOCK = true; // true = Show Clock when not printing / false = turn off display when not printing
// Display Settings
const int I2C_DISPLAY_ADDRESS = 0x3c; // I2C Address of your Display (usually 0x3c or 0x3d)
const int SDA_PIN = D2;
const int SCL_PIN = D5; // original code D5 -- Monitor Easy Board use D1
boolean INVERT_DISPLAY = false; // true = pins at top | false = pins at the bottom
//#define DISPLAY_SH1106 // Uncomment this line to use the SH1106 display -- SSD1306 is used by default and is most common
// LED Settings
const int externalLight = LED_BUILTIN; // LED will always flash on bootup or Wifi Errors
boolean USE_FLASH = true; // true = System LED will Flash on Service Calls; false = disabled LED flashing
// 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.
/** 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.
*/
// Additional Contributions:
/* 15 Jan 2019 : Owen Carter : Add psucontrol setting */
/******************************************************************************
* Printer Monitor is designed for the Wemos D1 ESP8266
* Wemos D1 Mini: https://amzn.to/2qLyKJd
* 0.96" OLED I2C 128x64 Display (12864) SSD1306
* OLED Display: https://amzn.to/2JDEAUF
******************************************************************************/
/******************************************************************************
* NOTE: The settings here are the default settings for the first loading.
* 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
* the Web Interface.
******************************************************************************/
#include <ESP8266WiFi.h>
#include <ESP8266WebServer.h>
#include <WiFiManager.h>
#include <ESP8266mDNS.h>
#include <ArduinoOTA.h>
#include <ESP8266HTTPUpdateServer.h>
#include "TimeClient.h"
#include "RepetierClient.h"
#include "OctoPrintClient.h"
#include "OpenWeatherMapClient.h"
#include "WeatherStationFonts.h"
#include "FS.h"
#include "SH1106Wire.h"
#include "SSD1306Wire.h"
#include "OLEDDisplayUi.h"
//******************************
// Start Settings
//******************************
// OctoPrint / Repetier Monitoring -- Monitor your 3D OctoPrint or Repetier Server
//#define USE_REPETIER_CLIENT // Uncomment this line to use the Repetier Printer Server -- OctoPrint is used by default and is most common
String PrinterApiKey = ""; // ApiKey from your User Account on OctoPrint / Repetier
String PrinterHostName = "octopi";// Default 'octopi' -- or hostname if different (optional if your IP changes)
String PrinterServer = ""; // IP or Address of your OctoPrint / Repetier Server (DO NOT include http://)
int PrinterPort = 80; // the port you are running your OctoPrint / Repetier server on (usually 80);
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
boolean DISPLAYWEATHER = true; // true = show weather when not printing / false = no weather
String WeatherApiKey = ""; // Your API Key from http://openweathermap.org/
// Default City Location (use http://openweathermap.org/find to find city ID)
int CityIDs[] = { 2515270 }; //Only USE ONE for weather marquee
boolean IS_METRIC = true; // 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
String WeatherLanguage = "es"; //Default (en) English
// Webserver
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]/
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_password[] = "password"; // Password for the Web Interface
// Date and Time
float UtcOffset = 0; // Hour offset from GMT for your timezone
boolean IS_24HOUR = true; // 23:00 millitary 24 hour clock
int minutesBetweenDataRefresh = 10;
boolean DISPLAYCLOCK = true; // true = Show Clock when not printing / false = turn off display when not printing
// Display Settings
const int I2C_DISPLAY_ADDRESS = 0x3c; // I2C Address of your Display (usually 0x3c or 0x3d)
const int SDA_PIN = D2;
const int SCL_PIN = D5; // original code D5 -- Monitor Easy Board use D1
boolean INVERT_DISPLAY = true; // true = pins at top | false = pins at the bottom
//#define DISPLAY_SH1106 // Uncomment this line to use the SH1106 display -- SSD1306 is used by default and is most common
// LED Settings
const int externalLight = LED_BUILTIN; // LED will always flash on bootup or Wifi Errors
boolean USE_FLASH = false; // true = System LED will Flash on Service Calls; false = disabled LED flashing
// 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-blue"; // this can be changed later in the web interface.

0
printermonitor/TimeClient.cpp Normal file → Executable file
View File

0
printermonitor/TimeClient.h Normal file → Executable file
View File

0
printermonitor/WeatherStationFonts.h Normal file → Executable file
View File

0
printermonitor/libs/ArduinoJson/ArduinoJson.h Normal file → Executable file
View File

0
printermonitor/libs/ArduinoJson/CHANGELOG.md Normal file → Executable file
View File

0
printermonitor/libs/ArduinoJson/CMakeLists.txt Normal file → Executable file
View File

0
printermonitor/libs/ArduinoJson/CONTRIBUTING.md Normal file → Executable file
View File

0
printermonitor/libs/ArduinoJson/LICENSE.md Normal file → Executable file
View File

0
printermonitor/libs/ArduinoJson/README.md Normal file → Executable file
View File

0
printermonitor/libs/ArduinoJson/SUPPORT.md Normal file → Executable file
View File

0
printermonitor/libs/ArduinoJson/appveyor.yml Normal file → Executable file
View File

0
printermonitor/libs/ArduinoJson/banner.svg Normal file → Executable file
View File

Before

Width:  |  Height:  |  Size: 32 KiB

After

Width:  |  Height:  |  Size: 32 KiB

0
printermonitor/libs/ArduinoJson/keywords.txt Normal file → Executable file
View File

0
printermonitor/libs/ArduinoJson/src/ArduinoJson.h Normal file → Executable file
View File

0
printermonitor/libs/ArduinoJson/src/ArduinoJson.hpp Normal file → Executable file
View File

View File

View File

View File

View File

View File

View File

View File

View File

View File

View File

View File

View File

View File

View File

View File

View File

View File

View File

View File

View File

View File

View File

View File

View File

View File

View File

View File

View File

View File

View File

View File

View File

View File

View File

View File

Some files were not shown because too many files have changed in this diff Show More