#include "WebServer.h" static const char WEB_ACTIONS[] PROGMEM = " Home" " Configure" " Weather" " Reset Settings" " Forget WiFi" " Firmware Update" " About"; static const char CLOCK_FORM[] PROGMEM = "
Display Clock when printer is off
" "Use 24 Hour Clock (military time)
" "Flip display orientation
" "Flash System LED on Service Calls
" "Use OctoPrint PSU control plugin for clock/blank
" "Clock Sync / Weather Refresh (minutes)
"; static const char THEME_FORM[] PROGMEM = "Theme Color
" "Use Security Credentials for Configuration Changes
" "" "" ""; static const char WEATHER_FORM[] PROGMEM = "" ""; static const char LANG_OPTIONS[] PROGMEM = "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" ""; static const char COLOR_THEMES[] PROGMEM = "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" ""; WebServer::WebServer(ESP8266WebServer *serverHandle, Debug *debugHandle, PrinterClientInterface *printerClient, TimeClient *timeClient, String themeColor, String swVersion, boolean hasPsu) { this->serverHandle = serverHandle; this->themeColor = themeColor; this->debugHandle = debugHandle; this->swVersion = swVersion; this->printerClient = printerClient; this->timeClient = timeClient; this->hostName = ""; this->hasPsu = hasPsu; this->isBasicAuth = false; this->wwwUsername = ""; this->wwwPassword = ""; } void WebServer::setHostname(String hostName) { this->hostName = hostName; } void WebServer::redirectHome() { // Send them back to the Root Directory this->serverHandle->sendHeader("Location", String("/"), true); this->serverHandle->sendHeader("Cache-Control", "no-cache, no-store"); this->serverHandle->sendHeader("Pragma", "no-cache"); this->serverHandle->sendHeader("Expires", "-1"); this->serverHandle->send(302, "text/plain", ""); this->serverHandle->client().stop(); } String WebServer::getHeader() { return this->getHeader(false); } String WebServer::getHeader(boolean refresh) { String menu = FPSTR(WEB_ACTIONS); String html = ""; html += "";
if (this->printerClient->getPrinterType() == "Repetier") {
html += "Printer Name: " + this->printerClient->getPrinterName() + "
";
} else {
html += "Host Name: " + this->hostName + "
";
}
if (this->printerClient->getError() != "") {
html += "Status: Offline
";
html += "Reason: " + this->printerClient->getError() + "
";
} else {
html += "Status: " + this->printerClient->getState();
if (this->printerClient->isPSUoff() && this->hasPsu) {
html += ", PSU off";
}
html += "
";
}
if (this->printerClient->isPrinting()) {
html += "File: " + this->printerClient->getFileName() + "
";
float fileSize = this->printerClient->getFileSize().toFloat();
if (fileSize > 0) {
fileSize = fileSize / 1024;
html += "File Size: " + String(fileSize) + "KB
";
}
int filamentLength = this->printerClient->getFilamentLength().toInt();
if (filamentLength > 0) {
float fLength = float(filamentLength) / 1000;
html += "Filament: " + String(fLength) + "m
";
}
html += "Tool Temperature: " + this->printerClient->getTempToolActual() + "° C
";
if ( this->printerClient->getTempBedActual() != 0 ) {
html += "Bed Temperature: " + this->printerClient->getTempBedActual() + "° C
";
}
int val = this->printerClient->getProgressPrintTimeLeft().toInt();
int hours = numberOfHours(val);
int minutes = numberOfMinutes(val);
int seconds = numberOfSeconds(val);
html += "Est. Print Time Left: " + zeroPad(hours) + ":" + zeroPad(minutes) + ":" + zeroPad(seconds) + "
";
val = this->printerClient->getProgressPrintTime().toInt();
hours = numberOfHours(val);
minutes = numberOfMinutes(val);
seconds = numberOfSeconds(val);
html += "Printing Time: " + zeroPad(hours) + ":" + zeroPad(minutes) + ":" + zeroPad(seconds) + "
";
html += "";
html += "
Please Configure Weather API
"; if (weatherClient.getError() != "") { html += "Weather Error: " + weatherClient.getError() + "
"; } } else { html += "";
html += weatherClient.getCondition(0) + " (" + weatherClient.getDescription(0) + ")
";
html += weatherClient.getTempRounded(0) + getTempSymbol(true) + "
";
html += " Map It!
";
html += "