Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merge with 3.0 Branch, Night Mode !, Changes and Translations #92

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Binary file removed printermonitor.ino.d1_mini_SH1106-2.5.bin
Binary file not shown.
Binary file removed printermonitor.ino.d1_mini_SSD1306-2.5.bin
Binary file not shown.
34 changes: 26 additions & 8 deletions printermonitor/OctoPrintClient.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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();
Expand Down Expand Up @@ -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();
Expand Down Expand Up @@ -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"];
Expand Down Expand Up @@ -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"];
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -330,7 +332,7 @@ String OctoPrintClient::getProgressCompletion() {
}

String OctoPrintClient::getProgressFilepos() {
return printerData.progressFilepos;
return printerData.progressFilepos;
}

String OctoPrintClient::getProgressPrintTime() {
Expand Down Expand Up @@ -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;
}
12 changes: 9 additions & 3 deletions printermonitor/OctoPrintClient.h
Original file line number Diff line number Diff line change
Expand Up @@ -37,12 +37,13 @@ class OctoPrintClient {
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 {
Expand All @@ -64,16 +65,17 @@ class OctoPrintClient {
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();
Expand All @@ -95,4 +97,8 @@ class OctoPrintClient {
String getFilamentLength();
String getValueRounded(String value);
String getError();
String getPrinterType();
int getPrinterPort();
String getPrinterName();
void setPrinterName(String printer);
};
24 changes: 12 additions & 12 deletions printermonitor/OpenWeatherMapClient.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -54,15 +54,15 @@ 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();
return;
}

while(weatherClient.connected() && !weatherClient.available()) delay(1); //waits for data

Serial.println("Waiting for data");

// Check HTTP status
Expand Down Expand Up @@ -133,7 +133,7 @@ void OpenWeatherMapClient::updateWeather() {
Serial.println("description: " + weathers[inx].description);
Serial.println("icon: " + weathers[inx].icon);
Serial.println();

}
}

Expand All @@ -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]);
}
}
}
Expand Down Expand Up @@ -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;
Expand All @@ -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;
Expand All @@ -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;
Expand All @@ -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;
Expand All @@ -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;
Expand All @@ -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;
}
}
4 changes: 2 additions & 2 deletions printermonitor/OpenWeatherMapClient.h
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ class OpenWeatherMapClient {
String myApiKey = "";
String units = "";
String lang = "";

const char* servername = "api.openweathermap.org"; // remote server we will connect to
String result;

Expand All @@ -56,7 +56,7 @@ class OpenWeatherMapClient {
weather weathers[5];

String roundValue(String value);

public:
OpenWeatherMapClient(String ApiKey, int CityIDs[], int cityCount, boolean isMetric, String language);
void updateWeather();
Expand Down
Loading