Merge with 3.0 Branch, Night Mode !, Changes and Translations
I Cloned the Master Branch... did some changes and saw there are a 3.0 branch.....with similar changes -.-' Whats diffenrent here: -Merged with 3.0 and my Fork -Add Screensaver Mode (Display Clock and weather if the Printer ist operational or offline....this was some of changes wich i did too :D ) -Add a Night Mode wich dim the Display to the minimum (enable in the webinterface) -A lot of Cosmetic and Label changes for the Web Interface and the Printer Monitor -Add German translations for Weather Main Strings (because OWM.org only translate the descriptions ) -maybe thing i forget XDpull/92/head
parent
cd1bc2b62a
commit
5f9361ba77
Binary file not shown.
Binary file not shown.
Binary file not shown.
|
|
@ -27,10 +27,10 @@ SOFTWARE.
|
|||
#include "OctoPrintClient.h"
|
||||
|
||||
OctoPrintClient::OctoPrintClient(String ApiKey, String server, int port, String user, String pass, boolean psu) {
|
||||
updateOctoPrintClient(ApiKey, server, port, user, pass, psu);
|
||||
updatePrintClient(ApiKey, server, port, user, pass, psu);
|
||||
}
|
||||
|
||||
void OctoPrintClient::updateOctoPrintClient(String ApiKey, String server, int port, String user, String pass, boolean psu) {
|
||||
void OctoPrintClient::updatePrintClient(String ApiKey, String server, int port, String user, String pass, boolean psu) {
|
||||
server.toCharArray(myServer, 100);
|
||||
myApiKey = ApiKey;
|
||||
myPort = port;
|
||||
|
|
@ -82,7 +82,7 @@ WiFiClient OctoPrintClient::getSubmitRequest(String apiGetData) {
|
|||
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();
|
||||
|
|
@ -142,7 +142,7 @@ WiFiClient OctoPrintClient::getPostRequest(String apiPostData, String apiPostBod
|
|||
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();
|
||||
|
|
@ -194,7 +194,7 @@ void OctoPrintClient::getPrinterJobResults() {
|
|||
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"];
|
||||
|
|
@ -236,6 +236,8 @@ void OctoPrintClient::getPrinterJobResults() {
|
|||
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"];
|
||||
|
|
@ -263,14 +265,14 @@ void OctoPrintClient::getPrinterPsuState() {
|
|||
}
|
||||
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
|
||||
|
|
@ -330,7 +332,7 @@ String OctoPrintClient::getProgressCompletion() {
|
|||
}
|
||||
|
||||
String OctoPrintClient::getProgressFilepos() {
|
||||
return printerData.progressFilepos;
|
||||
return printerData.progressFilepos;
|
||||
}
|
||||
|
||||
String OctoPrintClient::getProgressPrintTime() {
|
||||
|
|
@ -394,3 +396,19 @@ String OctoPrintClient::getValueRounded(String value) {
|
|||
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;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -37,12 +37,13 @@ private:
|
|||
String myApiKey = "";
|
||||
String encodedAuth = "";
|
||||
boolean pollPsu;
|
||||
const String printerType = "OctoPrint";
|
||||
|
||||
void resetPrintData();
|
||||
boolean validate();
|
||||
WiFiClient getSubmitRequest(String apiGetData);
|
||||
WiFiClient getPostRequest(String apiPostData, String apiPostBody);
|
||||
|
||||
|
||||
String result;
|
||||
|
||||
typedef struct {
|
||||
|
|
@ -64,16 +65,17 @@ private:
|
|||
boolean isPrinting;
|
||||
boolean isPSUoff;
|
||||
String error;
|
||||
String printerName;
|
||||
} 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);
|
||||
void updatePrintClient(String ApiKey, String server, int port, String user, String pass, boolean psu);
|
||||
|
||||
String getAveragePrintTime();
|
||||
String getEstimatedPrintTime();
|
||||
|
|
@ -95,4 +97,8 @@ public:
|
|||
String getFilamentLength();
|
||||
String getValueRounded(String value);
|
||||
String getError();
|
||||
String getPrinterType();
|
||||
int getPrinterPort();
|
||||
String getPrinterName();
|
||||
void setPrinterName(String printer);
|
||||
};
|
||||
|
|
|
|||
|
|
@ -54,7 +54,7 @@ void OpenWeatherMapClient::updateWeather() {
|
|||
weatherClient.println("User-Agent: ArduinoWiFi/1.1");
|
||||
weatherClient.println("Connection: close");
|
||||
weatherClient.println();
|
||||
}
|
||||
}
|
||||
else {
|
||||
Serial.println("connection for weather data failed"); //error message if no client connect
|
||||
Serial.println();
|
||||
|
|
@ -62,7 +62,7 @@ void OpenWeatherMapClient::updateWeather() {
|
|||
}
|
||||
|
||||
while(weatherClient.connected() && !weatherClient.available()) delay(1); //waits for data
|
||||
|
||||
|
||||
Serial.println("Waiting for data");
|
||||
|
||||
// Check HTTP status
|
||||
|
|
@ -133,7 +133,7 @@ void OpenWeatherMapClient::updateWeather() {
|
|||
Serial.println("description: " + weathers[inx].description);
|
||||
Serial.println("icon: " + weathers[inx].icon);
|
||||
Serial.println();
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -150,7 +150,7 @@ void OpenWeatherMapClient::updateCityIdList(int CityIDs[], int cityCount) {
|
|||
if (myCityIDs != "") {
|
||||
myCityIDs = myCityIDs + ",";
|
||||
}
|
||||
myCityIDs = myCityIDs + String(CityIDs[inx]);
|
||||
myCityIDs = myCityIDs + String(CityIDs[inx]);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -250,7 +250,7 @@ String OpenWeatherMapClient::getWeatherIcon(int index)
|
|||
case 802: W = "H"; break;
|
||||
case 803: W = "H"; break;
|
||||
case 804: W = "Y"; break;
|
||||
|
||||
|
||||
case 200: W = "0"; break;
|
||||
case 201: W = "0"; break;
|
||||
case 202: W = "0"; break;
|
||||
|
|
@ -261,7 +261,7 @@ String OpenWeatherMapClient::getWeatherIcon(int index)
|
|||
case 230: W = "0"; break;
|
||||
case 231: W = "0"; break;
|
||||
case 232: W = "0"; break;
|
||||
|
||||
|
||||
case 300: W = "R"; break;
|
||||
case 301: W = "R"; break;
|
||||
case 302: W = "R"; break;
|
||||
|
|
@ -271,7 +271,7 @@ String OpenWeatherMapClient::getWeatherIcon(int index)
|
|||
case 313: W = "R"; break;
|
||||
case 314: W = "R"; break;
|
||||
case 321: W = "R"; break;
|
||||
|
||||
|
||||
case 500: W = "R"; break;
|
||||
case 501: W = "R"; break;
|
||||
case 502: W = "R"; break;
|
||||
|
|
@ -282,7 +282,7 @@ String OpenWeatherMapClient::getWeatherIcon(int index)
|
|||
case 521: W = "R"; break;
|
||||
case 522: W = "R"; break;
|
||||
case 531: W = "R"; break;
|
||||
|
||||
|
||||
case 600: W = "W"; break;
|
||||
case 601: W = "W"; break;
|
||||
case 602: W = "W"; break;
|
||||
|
|
@ -293,7 +293,7 @@ String OpenWeatherMapClient::getWeatherIcon(int index)
|
|||
case 620: W = "W"; break;
|
||||
case 621: W = "W"; break;
|
||||
case 622: W = "W"; break;
|
||||
|
||||
|
||||
case 701: W = "M"; break;
|
||||
case 711: W = "M"; break;
|
||||
case 721: W = "M"; break;
|
||||
|
|
@ -304,8 +304,8 @@ String OpenWeatherMapClient::getWeatherIcon(int index)
|
|||
case 762: W = "M"; break;
|
||||
case 771: W = "M"; break;
|
||||
case 781: W = "M"; break;
|
||||
|
||||
default:break;
|
||||
|
||||
default:break;
|
||||
}
|
||||
return W;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -32,7 +32,7 @@ private:
|
|||
String myApiKey = "";
|
||||
String units = "";
|
||||
String lang = "";
|
||||
|
||||
|
||||
const char* servername = "api.openweathermap.org"; // remote server we will connect to
|
||||
String result;
|
||||
|
||||
|
|
@ -56,7 +56,7 @@ private:
|
|||
weather weathers[5];
|
||||
|
||||
String roundValue(String value);
|
||||
|
||||
|
||||
public:
|
||||
OpenWeatherMapClient(String ApiKey, int CityIDs[], int cityCount, boolean isMetric, String language);
|
||||
void updateWeather();
|
||||
|
|
|
|||
|
|
@ -0,0 +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;
|
||||
}
|
||||
|
|
@ -0,0 +1,104 @@
|
|||
/** 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.
|
||||
*/
|
||||
|
||||
/* 07 April 2019 : Jon Smith : added class for Repetier Server (kg4iae@github)*/
|
||||
|
||||
|
||||
#pragma once
|
||||
#include <ESP8266WiFi.h>
|
||||
#include "libs/ArduinoJson/ArduinoJson.h"
|
||||
#include <base64.h>
|
||||
|
||||
class RepetierClient {
|
||||
|
||||
private:
|
||||
char myServer[100];
|
||||
int myPort = 3344;
|
||||
String myApiKey = "";
|
||||
String encodedAuth = "";
|
||||
boolean pollPsu;
|
||||
const String printerType = "Repetier";
|
||||
|
||||
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;
|
||||
String printerName;
|
||||
} PrinterStruct;
|
||||
|
||||
PrinterStruct printerData;
|
||||
|
||||
|
||||
public:
|
||||
RepetierClient(String ApiKey, String server, int port, String user, String pass, boolean psu);
|
||||
void getPrinterJobResults();
|
||||
void getPrinterPsuState();
|
||||
void updatePrintClient(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();
|
||||
String getPrinterType();
|
||||
int getPrinterPort();
|
||||
String getPrinterName();
|
||||
void setPrinterName(String printer);
|
||||
};
|
||||
|
|
@ -31,10 +31,10 @@ SOFTWARE.
|
|||
* 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
|
||||
* 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.
|
||||
******************************************************************************/
|
||||
|
||||
|
|
@ -45,6 +45,7 @@ SOFTWARE.
|
|||
#include <ArduinoOTA.h>
|
||||
#include <ESP8266HTTPUpdateServer.h>
|
||||
#include "TimeClient.h"
|
||||
#include "RepetierClient.h"
|
||||
#include "OctoPrintClient.h"
|
||||
#include "OpenWeatherMapClient.h"
|
||||
#include "WeatherStationFonts.h"
|
||||
|
|
@ -57,13 +58,14 @@ SOFTWARE.
|
|||
// Start Settings
|
||||
//******************************
|
||||
|
||||
// OctoPrint Monitoring -- Monitor your 3D printer OctoPrint Server
|
||||
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://)
|
||||
int OctoPrintPort = 80; // the port you are running your OctoPrint server on (usually 80);
|
||||
String OctoAuthUser = ""; // only used if you have haproxy or basic athentintication turned on (not default)
|
||||
String OctoAuthPass = ""; // only used with haproxy or basic auth (only needed if you must authenticate)
|
||||
// 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
|
||||
|
|
@ -87,6 +89,9 @@ 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
|
||||
|
||||
// Nightmode
|
||||
boolean USE_NIGHT = false; // Dim the Screen if enabled
|
||||
|
||||
// Display Settings
|
||||
const int I2C_DISPLAY_ADDRESS = 0x3c; // I2C Address of your Display (usually 0x3c or 0x3d)
|
||||
const int SDA_PIN = D2;
|
||||
|
|
@ -95,7 +100,8 @@ boolean INVERT_DISPLAY = false; // true = pins at top | false = pins at the bott
|
|||
//#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; // Set to unused pin, like D1, to disable use of built-in LED (LED_BUILTIN)
|
||||
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
|
||||
|
|
|
|||
|
|
@ -33,7 +33,7 @@ TimeClient::TimeClient(float utcOffset) {
|
|||
|
||||
void TimeClient::updateTime() {
|
||||
WiFiClient client;
|
||||
|
||||
|
||||
if (!client.connect(ntpServerName, httpPort)) {
|
||||
Serial.println("connection failed");
|
||||
return;
|
||||
|
|
@ -149,4 +149,4 @@ long TimeClient::getCurrentEpoch() {
|
|||
|
||||
long TimeClient::getCurrentEpochWithUtcOffset() {
|
||||
return (long)round(getCurrentEpoch() + 3600 * myUtcOffset + 86400L) % 86400L;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -40,13 +40,13 @@ class TimeClient {
|
|||
long localEpoc = 0;
|
||||
long localMillisAtUpdate;
|
||||
const char* ntpServerName = "www.google.com";
|
||||
const int httpPort = 80;
|
||||
const int httpPort = 80;
|
||||
byte packetBuffer[ NTP_PACKET_SIZE]; //buffer to hold incoming and outgoing packets
|
||||
|
||||
public:
|
||||
TimeClient(float utcOffset);
|
||||
void updateTime();
|
||||
|
||||
|
||||
void setUtcOffset(float utcOffset);
|
||||
String getHours();
|
||||
String getAmPmHours();
|
||||
|
|
@ -59,4 +59,3 @@ class TimeClient {
|
|||
long getCurrentEpochWithUtcOffset();
|
||||
|
||||
};
|
||||
|
||||
|
|
|
|||
|
|
@ -1298,4 +1298,3 @@ const char Meteocons_Plain_10[] PROGMEM = {
|
|||
0xFC,0x0F,0x20,0x02,0x10,0x02,0x10,0x02,0xE0,0x01, // 254
|
||||
0x30,0x08,0xC4,0x04,0x00,0x03,0xC4,0x00,0x30 // 255
|
||||
};
|
||||
|
||||
|
|
|
|||
File diff suppressed because it is too large
Load Diff
Loading…
Reference in New Issue