Removed upload functions (not used)
This commit is contained in:
179
html/upload.htm
179
html/upload.htm
@ -1,179 +0,0 @@
|
||||
<!doctype html>
|
||||
<html lang="en">
|
||||
<head>
|
||||
<meta charset="utf-8">
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
|
||||
<meta name="description" content="">
|
||||
<title>Beer Gravity Monitor</title>
|
||||
<link href="https://cdn.jsdelivr.net/npm/bootstrap@5.1.3/dist/css/bootstrap.min.css" rel="stylesheet" integrity="sha384-1BmE4kWBq78iYhFldvKuhfTAU6auU8tT94WrHftjDbrCEXSU1oBoqyl2QvZ6jIW3" crossorigin="anonymous">
|
||||
<style>
|
||||
.row-margin-10 { margin-top: 1.0em; }
|
||||
</style>
|
||||
</head>
|
||||
|
||||
<body class="py-4">
|
||||
|
||||
<script src="https://cdn.jsdelivr.net/npm/bootstrap@5.1.3/dist/js/bootstrap.bundle.min.js" integrity="sha384-ka7Sk0Gln4gmtz2MlQnikT1wXgYsOg+OMhuP+IlRH9sENBO0LRn5q+8nbTov4+1p" crossorigin="anonymous"></script>
|
||||
<script src="https://code.jquery.com/jquery-3.6.0.min.js" integrity="sha256-/xUj+3OJU5yExlq6GSYGSHk7tPXikynS7ogEvDej/m4=" crossorigin="anonymous"></script>
|
||||
|
||||
<!-- START MENU -->
|
||||
|
||||
<nav class="navbar navbar-expand-lg navbar-dark bg-primary">
|
||||
<div class="container">
|
||||
<a class="navbar-brand" href="/index.htm">Beer Gravity Monitor</a>
|
||||
<button class="navbar-toggler" type="button" data-bs-toggle="collapse" data-bs-target="#navbarNav" aria-controls="navbarNav" aria-expanded="false" aria-label="Toggle navigation">
|
||||
<span class="navbar-toggler-icon"></span>
|
||||
</button>
|
||||
<div class="spinner-border text-light" id="spinner" role="status"></div>
|
||||
</div>
|
||||
</nav>
|
||||
|
||||
<!-- START MAIN INDEX -->
|
||||
|
||||
<div class="container row-margin-10">
|
||||
|
||||
<div class="alert alert-success alert-dismissible hide fade d-none" role="alert">
|
||||
<div id="alert"></div>
|
||||
<button type="button" class="btn-close" data-bs-dismiss="alert" aria-label="Close"></button>
|
||||
</div>
|
||||
|
||||
<script type="text/javascript">
|
||||
function showError( msg ) {
|
||||
$('.alert').removeClass('alert-success').addClass('alert-danger').removeClass('hide').addClass('show').removeClass('d-none');
|
||||
$('#alert').text( msg );
|
||||
}
|
||||
|
||||
function showSuccess( msg ) {
|
||||
$('.alert').addClass('alert-success').removeClass('alert-danger').removeClass('hide').addClass('show').removeClass('d-none');
|
||||
$('#alert').text( msg );
|
||||
}
|
||||
|
||||
$("#alert-btn").click(function(e){
|
||||
$('.alert').addClass('hide').removeClass('show').addClass('d-none');
|
||||
});
|
||||
</script>
|
||||
|
||||
<div class="accordion" id="accordion">
|
||||
<div class="accordion-item">
|
||||
<h2 class="accordion-header" id="headingUpload">
|
||||
<button class="accordion-button" type="button" data-bs-toggle="collapse" data-bs-target="#collapseUpload" aria-expanded="true" aria-controls="collapseUpload">
|
||||
<b>Upload missing html files</b>
|
||||
</button>
|
||||
</h2>
|
||||
<div id="collapseUpload" class="accordion-collapse collapse show" aria-labelledby="headingUpload" data-bs-parent="#accordion">
|
||||
<div class="accordion-body">
|
||||
|
||||
<div class="row mb-3">
|
||||
<div class="col-md-8 bg-light">The listed files below needs to be uploaded to the FileSystem in order for the GUI to work.
|
||||
You can also flash the LittleFS filesystem but in that case you will loose your device settings. An OTA upgrade will automatically download
|
||||
the files if they are found in the same location as the firmware.bin. This page is a fallback option.
|
||||
</div>
|
||||
<div class="col-md-8 bg-light"><br><strong>Once all the files are confirmed, please reboot the device for normal operation.</strong></div>
|
||||
</div>
|
||||
|
||||
<div class="row mb-3">
|
||||
<div class="col-md-2 bg-light">index.min.htm</div>
|
||||
<div class="col-md-6 bg-light" id="index">Checking...</div>
|
||||
</div>
|
||||
<div class="row mb-3">
|
||||
<div class="col-md-2 bg-light">config.min.htm</div>
|
||||
<div class="col-md-6 bg-light" id="config">Checking...</div>
|
||||
</div>
|
||||
<div class="row mb-3">
|
||||
<div class="col-md-2 bg-light">calibration.min.htm</div>
|
||||
<div class="col-md-6 bg-light" id="calibration">Checking...</div>
|
||||
</div>
|
||||
<div class="row mb-3">
|
||||
<div class="col-md-2 bg-light">format.min.htm</div>
|
||||
<div class="col-md-6 bg-light" id="format">Checking...</div>
|
||||
</div>
|
||||
<div class="row mb-3">
|
||||
<div class="col-md-2 bg-light">test.min.htm</div>
|
||||
<div class="col-md-6 bg-light" id="test">Checking...</div>
|
||||
</div>
|
||||
<div class="row mb-3">
|
||||
<div class="col-md-2 bg-light">about.min.htm</div>
|
||||
<div class="col-md-6 bg-light" id="about">Checking...</div>
|
||||
</div>
|
||||
|
||||
<form action="/api/upload" method="post" enctype="multipart/form-data">
|
||||
<div class="row mb-3">
|
||||
<div class="col-md-8 custom-file">
|
||||
<input type="file" accept=".min.htm" class="custom-file-input" name="name" id="name" data-bs-toggle="tooltip" title="Select a file that matches the name in the list above to upload it to the device">
|
||||
</div>
|
||||
</div>
|
||||
<div class="row mb-3">
|
||||
<div class="col-md-3">
|
||||
<button type="submit" class="btn btn-primary" id="upload-btn" value="upload" data-bs-toggle="tooltip" title="Upload the selected file to the device">Upload</button>
|
||||
</div>
|
||||
</div>
|
||||
</form>
|
||||
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<script type="text/javascript">
|
||||
window.onload = getUpload;
|
||||
|
||||
// Add the following code if you want the name of the file appear on select
|
||||
$(".custom-file-input").on("change", function() {
|
||||
var fileName = $(this).val().split("\\").pop();
|
||||
$(this).siblings(".custom-file-label").addClass("selected").html(fileName);
|
||||
});
|
||||
|
||||
function getUpload() {
|
||||
var url = "/api/upload";
|
||||
//var url = "/test/upload.json";
|
||||
$('#spinner').show();
|
||||
$.getJSON(url, function (cfg) {
|
||||
console.log( cfg );
|
||||
|
||||
if( cfg["index"] )
|
||||
$("#index").text("Completed.");
|
||||
else
|
||||
$("#index").text("File is missing.");
|
||||
|
||||
if( cfg["config"] )
|
||||
$("#config").text("Completed.");
|
||||
else
|
||||
$("#config").text("File is missing.");
|
||||
|
||||
if( cfg["calibration"] )
|
||||
$("#calibration").text("Completed.");
|
||||
else
|
||||
$("#calibration").text("File is missing.");
|
||||
|
||||
if( cfg["test"] )
|
||||
$("#test").text("Completed.");
|
||||
else
|
||||
$("#test").text("File is missing.");
|
||||
|
||||
if( cfg["format"] )
|
||||
$("#format").text("Completed.");
|
||||
else
|
||||
$("#format").text("File is missing.");
|
||||
|
||||
if( cfg["about"] )
|
||||
$("#about").text("Completed.");
|
||||
else
|
||||
$("#about").text("File is missing.");
|
||||
|
||||
|
||||
})
|
||||
.fail(function () {
|
||||
showError('Unable to get data from the device.');
|
||||
})
|
||||
.always(function() {
|
||||
$('#spinner').hide();
|
||||
});
|
||||
}
|
||||
</script>
|
||||
|
||||
<!-- START FOOTER -->
|
||||
|
||||
<div class="container themed-container bg-primary text-light row-margin-10">(C) Copyright 2021-22 Magnus Persson</div>
|
||||
</body>
|
||||
</html>
|
File diff suppressed because one or more lines are too long
@ -1,34 +0,0 @@
|
||||
Import("env")
|
||||
import shutil, os
|
||||
|
||||
print( "Executing custom step " )
|
||||
dir = env.GetLaunchDir()
|
||||
source = dir + "/html/"
|
||||
target = dir + "/data/"
|
||||
print( "Copy html-files from " + source + " -> " + target )
|
||||
|
||||
os.makedirs(os.path.dirname( target ), exist_ok=True)
|
||||
file = "about.min.htm"
|
||||
#print( "Copy file: " + source + file + "->" + target + file)
|
||||
shutil.copyfile( source + file, target + file )
|
||||
file = "calibration.min.htm"
|
||||
#print( "Copy file: " + source + file + "->" + target + file)
|
||||
shutil.copyfile( source + file, target + file )
|
||||
file = "config.min.htm"
|
||||
#print( "Copy file: " + source + file + "->" + target + file)
|
||||
shutil.copyfile( source + file, target + file )
|
||||
file = "index.min.htm"
|
||||
#print( "Copy file: " + source + file + "->" + target + file)
|
||||
shutil.copyfile( source + file, target + file )
|
||||
file = "upload.min.htm"
|
||||
#print( "Copy file: " + source + file + "->" + target + file)
|
||||
shutil.copyfile( source + file, target + file )
|
||||
file = "format.min.htm"
|
||||
#print( "Copy file: " + source + file + "->" + target + file)
|
||||
shutil.copyfile( source + file, target + file )
|
||||
file = "test.min.htm"
|
||||
#print( "Copy file: " + source + file + "->" + target + file)
|
||||
shutil.copyfile( source + file, target + file )
|
||||
file = "firmware.min.htm"
|
||||
#print( "Copy file: " + source + file + "->" + target + file)
|
||||
shutil.copyfile( source + file, target + file )
|
@ -23,23 +23,15 @@ SOFTWARE.
|
||||
*/
|
||||
#if defined(ESP8266)
|
||||
#define INCBIN_OUTPUT_SECTION ".irom.text"
|
||||
#endif
|
||||
#include <incbin.h>
|
||||
|
||||
#include <resources.hpp>
|
||||
|
||||
#if defined(EMBED_HTML)
|
||||
// Using minify to reduce memory usage. Reducing RAM memory usage with about 7%
|
||||
INCBIN(IndexHtm, "data/index.min.htm");
|
||||
INCBIN(ConfigHtm, "data/config.min.htm");
|
||||
INCBIN(CalibrationHtm, "data/calibration.min.htm");
|
||||
INCBIN(FormatHtm, "data/format.min.htm");
|
||||
INCBIN(TestHtm, "data/test.min.htm");
|
||||
INCBIN(AboutHtm, "data/about.min.htm");
|
||||
#else
|
||||
// Minium web interface for uploading htm files
|
||||
INCBIN(UploadHtm, "data/upload.min.htm");
|
||||
#endif
|
||||
INCBIN(FirmwareHtm, "data/firmware.min.htm");
|
||||
#endif
|
||||
|
||||
// EOF
|
||||
|
@ -37,9 +37,6 @@ WebServerHandler myWebServerHandler; // My wrapper class fr webserver functions
|
||||
extern bool sleepModeActive;
|
||||
extern bool sleepModeAlwaysSkip;
|
||||
|
||||
//
|
||||
// Callback from webServer when / has been accessed.
|
||||
//
|
||||
void WebServerHandler::webHandleConfig() {
|
||||
LOG_PERF_START("webserver-api-config");
|
||||
Log.notice(F("WEB : webServer callback for /api/config(get)." CR));
|
||||
@ -107,99 +104,19 @@ void WebServerHandler::webHandleConfig() {
|
||||
LOG_PERF_STOP("webserver-api-config");
|
||||
}
|
||||
|
||||
//
|
||||
// Callback from webServer when / has been accessed.
|
||||
//
|
||||
void WebServerHandler::webHandleUpload() {
|
||||
LOG_PERF_START("webserver-api-upload");
|
||||
Log.notice(F("WEB : webServer callback for /api/upload(get)." CR));
|
||||
DynamicJsonDocument doc(300);
|
||||
|
||||
doc["index"] = checkHtmlFile(WebServerHandler::HTML_INDEX);
|
||||
doc["config"] = checkHtmlFile(WebServerHandler::HTML_CONFIG);
|
||||
doc["calibration"] = checkHtmlFile(WebServerHandler::HTML_CALIBRATION);
|
||||
doc["format"] = checkHtmlFile(WebServerHandler::HTML_FORMAT);
|
||||
doc["about"] = checkHtmlFile(WebServerHandler::HTML_ABOUT);
|
||||
doc["test"] = checkHtmlFile(WebServerHandler::HTML_TEST);
|
||||
|
||||
#if defined(ESP8266)
|
||||
JsonArray files = doc.createNestedArray(PARAM_FILES);
|
||||
|
||||
// Show files in the filessytem at startup
|
||||
FSInfo fs;
|
||||
LittleFS.info(fs);
|
||||
Dir dir = LittleFS.openDir("/");
|
||||
while (dir.next()) {
|
||||
JsonObject obj = files.createNestedObject();
|
||||
obj[PARAM_FILE_NAME] = dir.fileName();
|
||||
obj[PARAM_FILE_SIZE] = dir.fileSize();
|
||||
}
|
||||
#else // defined(ESP32)
|
||||
JsonArray files = doc.createNestedArray(PARAM_FILES);
|
||||
|
||||
File dir = LittleFS.open("/");
|
||||
|
||||
while (true) {
|
||||
File entry = dir.openNextFile();
|
||||
if (!entry) {
|
||||
// no more files
|
||||
break;
|
||||
}
|
||||
|
||||
if (!entry.isDirectory()) {
|
||||
JsonObject obj = files.createNestedObject();
|
||||
obj[PARAM_FILE_NAME] = entry.name();
|
||||
obj[PARAM_FILE_SIZE] = entry.size();
|
||||
}
|
||||
entry.close();
|
||||
}
|
||||
dir.close();
|
||||
#endif
|
||||
|
||||
#if LOG_LEVEL == 6 && !defined(WEB_DISABLE_LOGGING)
|
||||
serializeJson(doc, Serial);
|
||||
Serial.print(CR);
|
||||
#endif
|
||||
|
||||
String out;
|
||||
out.reserve(300);
|
||||
serializeJson(doc, out);
|
||||
doc.clear();
|
||||
_server->send(200, "application/json", out.c_str());
|
||||
LOG_PERF_STOP("webserver-api-upload");
|
||||
}
|
||||
|
||||
void WebServerHandler::webHandleUploadFile() {
|
||||
LOG_PERF_START("webserver-api-upload-file");
|
||||
Log.verbose(F("WEB : webServer callback for /api/upload(post)." CR));
|
||||
HTTPUpload& upload = _server->upload();
|
||||
String f = upload.filename;
|
||||
bool validFilename = false;
|
||||
bool firmware = false;
|
||||
|
||||
if (f.equalsIgnoreCase("index.min.htm") ||
|
||||
f.equalsIgnoreCase("calibration.min.htm") ||
|
||||
f.equalsIgnoreCase("config.min.htm") ||
|
||||
f.equalsIgnoreCase("format.min.htm") ||
|
||||
f.equalsIgnoreCase("test.min.htm") ||
|
||||
f.equalsIgnoreCase("about.min.htm")) {
|
||||
validFilename = true;
|
||||
}
|
||||
|
||||
if (f.endsWith(".bin")) {
|
||||
validFilename = true;
|
||||
firmware = true;
|
||||
}
|
||||
|
||||
#if LOG_LEVEL == 6 && !defined(WEB_DISABLE_LOGGING)
|
||||
Log.verbose(
|
||||
F("WEB : webServer callback for /api/upload, receiving file %s, %d(%d) "
|
||||
"valid=%s, firmware=%s." CR),
|
||||
f.c_str(), upload.currentSize, upload.totalSize,
|
||||
validFilename ? "yes" : "no", firmware ? "yes" : "no");
|
||||
F("WEB : webServer callback for /api/upload, receiving file %s, %d(%d)." CR),
|
||||
f.c_str(), upload.currentSize, upload.totalSize);
|
||||
#endif
|
||||
|
||||
if (firmware) {
|
||||
// Handle firmware update, hardcode since function return wrong value.
|
||||
// (ESP.getFreeSketchSpace() - 0x1000) & 0xFFFFF000;
|
||||
uint32_t maxSketchSpace = MAX_SKETCH_SPACE;
|
||||
@ -243,37 +160,9 @@ void WebServerHandler::webHandleUploadFile() {
|
||||
}
|
||||
|
||||
delay(0);
|
||||
|
||||
} else {
|
||||
// Handle HTML file upload
|
||||
if (upload.status == UPLOAD_FILE_START) {
|
||||
_uploadReturn = 200;
|
||||
Log.notice(F("WEB : Start html upload." CR));
|
||||
|
||||
if (validFilename) _uploadFile = LittleFS.open(f, "w");
|
||||
} else if (upload.status == UPLOAD_FILE_WRITE) {
|
||||
Log.notice(F("WEB : Writing html upload." CR));
|
||||
if (_uploadFile) _uploadFile.write(upload.buf, upload.currentSize);
|
||||
} else if (upload.status == UPLOAD_FILE_END) {
|
||||
Log.notice(F("WEB : Finish html upload." CR));
|
||||
if (_uploadFile) {
|
||||
_uploadFile.close();
|
||||
Log.notice(F("WEB : Html file uploaded %d bytes." CR),
|
||||
upload.totalSize);
|
||||
}
|
||||
_server->sendHeader("Location", "/");
|
||||
_server->send(303);
|
||||
} else {
|
||||
_server->send(500, "text/plain", "Couldn't upload html file.");
|
||||
}
|
||||
}
|
||||
|
||||
LOG_PERF_STOP("webserver-api-upload-file");
|
||||
}
|
||||
|
||||
//
|
||||
// Callback from webServer when / has been accessed.
|
||||
//
|
||||
void WebServerHandler::webHandleCalibrate() {
|
||||
LOG_PERF_START("webserver-api-calibrate");
|
||||
String id = _server->arg(PARAM_ID);
|
||||
@ -439,9 +328,6 @@ void WebServerHandler::webHandleStatusSleepmode() {
|
||||
LOG_PERF_STOP("webserver-api-sleepmode");
|
||||
}
|
||||
|
||||
//
|
||||
// Update device settings.
|
||||
//
|
||||
void WebServerHandler::webHandleConfigDevice() {
|
||||
LOG_PERF_START("webserver-api-config-device");
|
||||
String id = _server->arg(PARAM_ID);
|
||||
@ -471,9 +357,6 @@ void WebServerHandler::webHandleConfigDevice() {
|
||||
LOG_PERF_STOP("webserver-api-config-device");
|
||||
}
|
||||
|
||||
//
|
||||
// Update push settings.
|
||||
//
|
||||
void WebServerHandler::webHandleConfigPush() {
|
||||
LOG_PERF_START("webserver-api-config-push");
|
||||
String id = _server->arg(PARAM_ID);
|
||||
@ -535,9 +418,6 @@ void WebServerHandler::webHandleConfigPush() {
|
||||
LOG_PERF_STOP("webserver-api-config-push");
|
||||
}
|
||||
|
||||
//
|
||||
// Get string with all received arguments. Used for debugging only.
|
||||
//
|
||||
String WebServerHandler::getRequestArguments() {
|
||||
String debug;
|
||||
|
||||
@ -554,9 +434,6 @@ String WebServerHandler::getRequestArguments() {
|
||||
return debug;
|
||||
}
|
||||
|
||||
//
|
||||
// Update gravity settings.
|
||||
//
|
||||
void WebServerHandler::webHandleConfigGravity() {
|
||||
LOG_PERF_START("webserver-api-config-gravity");
|
||||
String id = _server->arg(PARAM_ID);
|
||||
@ -591,9 +468,6 @@ void WebServerHandler::webHandleConfigGravity() {
|
||||
LOG_PERF_STOP("webserver-api-config-gravity");
|
||||
}
|
||||
|
||||
//
|
||||
// Update hardware settings.
|
||||
//
|
||||
void WebServerHandler::webHandleConfigHardware() {
|
||||
LOG_PERF_START("webserver-api-config-hardware");
|
||||
String id = _server->arg(PARAM_ID);
|
||||
@ -645,9 +519,6 @@ void WebServerHandler::webHandleConfigHardware() {
|
||||
LOG_PERF_STOP("webserver-api-config-hardware");
|
||||
}
|
||||
|
||||
//
|
||||
// Update advanced settings.
|
||||
//
|
||||
void WebServerHandler::webHandleConfigAdvancedWrite() {
|
||||
LOG_PERF_START("webserver-api-config-advanced");
|
||||
String id = _server->arg(PARAM_ID);
|
||||
@ -723,9 +594,6 @@ void WebServerHandler::webHandleConfigAdvancedWrite() {
|
||||
LOG_PERF_STOP("webserver-api-config-advanced");
|
||||
}
|
||||
|
||||
//
|
||||
// Read advanced settings
|
||||
//
|
||||
void WebServerHandler::webHandleConfigAdvancedRead() {
|
||||
LOG_PERF_START("webserver-api-config-advanced");
|
||||
Log.notice(F("WEB : webServer callback for /api/config/advanced(get)." CR));
|
||||
@ -766,9 +634,6 @@ void WebServerHandler::webHandleConfigAdvancedRead() {
|
||||
LOG_PERF_STOP("webserver-api-config-advanced");
|
||||
}
|
||||
|
||||
//
|
||||
// Callback from webServer when / has been accessed.
|
||||
//
|
||||
void WebServerHandler::webHandleFormulaRead() {
|
||||
LOG_PERF_START("webserver-api-formula-read");
|
||||
Log.notice(F("WEB : webServer callback for /api/formula(get)." CR));
|
||||
@ -852,9 +717,6 @@ void WebServerHandler::webHandleFormulaRead() {
|
||||
LOG_PERF_STOP("webserver-api-formula-read");
|
||||
}
|
||||
|
||||
//
|
||||
// Update format template
|
||||
//
|
||||
void WebServerHandler::webHandleConfigFormatWrite() {
|
||||
LOG_PERF_START("webserver-api-config-format-write");
|
||||
String id = _server->arg(PARAM_ID);
|
||||
@ -898,9 +760,6 @@ void WebServerHandler::webHandleConfigFormatWrite() {
|
||||
LOG_PERF_STOP("webserver-api-config-format-write");
|
||||
}
|
||||
|
||||
//
|
||||
// Get format with real data
|
||||
//
|
||||
void WebServerHandler::webHandleTestPush() {
|
||||
LOG_PERF_START("webserver-api-test-push");
|
||||
String id = _server->arg(PARAM_ID);
|
||||
@ -969,10 +828,6 @@ void WebServerHandler::webHandleTestPush() {
|
||||
LOG_PERF_STOP("webserver-api-test-push");
|
||||
}
|
||||
|
||||
//
|
||||
// Write file to disk, if there is no data then delete the current file (if it
|
||||
// exists) = reset to default.
|
||||
//
|
||||
bool WebServerHandler::writeFile(String fname, String data) {
|
||||
if (data.length()) {
|
||||
data = urldecode(data);
|
||||
@ -998,9 +853,6 @@ bool WebServerHandler::writeFile(String fname, String data) {
|
||||
return false;
|
||||
}
|
||||
|
||||
//
|
||||
// Read file from disk
|
||||
//
|
||||
String WebServerHandler::readFile(String fname) {
|
||||
File file = LittleFS.open(fname, "r");
|
||||
if (file) {
|
||||
@ -1014,9 +866,6 @@ String WebServerHandler::readFile(String fname) {
|
||||
return "";
|
||||
}
|
||||
|
||||
//
|
||||
// Get format templates
|
||||
//
|
||||
void WebServerHandler::webHandleConfigFormatRead() {
|
||||
LOG_PERF_START("webserver-api-config-format-read");
|
||||
Log.notice(F("WEB : webServer callback for /api/config/formula(get)." CR));
|
||||
@ -1071,9 +920,6 @@ void WebServerHandler::webHandleConfigFormatRead() {
|
||||
LOG_PERF_STOP("webserver-api-config-format-read");
|
||||
}
|
||||
|
||||
//
|
||||
// Update hardware settings.
|
||||
//
|
||||
void WebServerHandler::webHandleFormulaWrite() {
|
||||
LOG_PERF_START("webserver-api-formula-write");
|
||||
String id = _server->arg(PARAM_ID);
|
||||
@ -1166,57 +1012,11 @@ void WebServerHandler::webHandleFormulaWrite() {
|
||||
LOG_PERF_STOP("webserver-api-formula-write");
|
||||
}
|
||||
|
||||
//
|
||||
// Helper function to check if files exist on file system.
|
||||
//
|
||||
const char* WebServerHandler::getHtmlFileName(HtmlFile item) {
|
||||
Log.notice(F("WEB : Looking up filename for %d." CR), item);
|
||||
|
||||
switch (item) {
|
||||
case HtmlFile::HTML_INDEX:
|
||||
return "index.min.htm";
|
||||
case HtmlFile::HTML_CONFIG:
|
||||
return "config.min.htm";
|
||||
case HtmlFile::HTML_CALIBRATION:
|
||||
return "calibration.min.htm";
|
||||
case HtmlFile::HTML_FORMAT:
|
||||
return "format.min.htm";
|
||||
case HtmlFile::HTML_ABOUT:
|
||||
return "about.min.htm";
|
||||
case HtmlFile::HTML_TEST:
|
||||
return "test.min.htm";
|
||||
}
|
||||
|
||||
return "";
|
||||
}
|
||||
|
||||
//
|
||||
// Helper function to check if files exist on file system.
|
||||
//
|
||||
bool WebServerHandler::checkHtmlFile(HtmlFile item) {
|
||||
const char* fn = getHtmlFileName(item);
|
||||
|
||||
#if LOG_LEVEL == 6 && !defined(WEB_DISABLE_LOGGING)
|
||||
Log.verbose(F("WEB : Checking for file %s." CR), fn);
|
||||
#endif
|
||||
|
||||
// TODO: We might need to add more checks here like zero file size etc. But
|
||||
// for now we only check if the file exist.
|
||||
|
||||
return LittleFS.exists(fn);
|
||||
}
|
||||
|
||||
//
|
||||
// Handler for page not found
|
||||
//
|
||||
void WebServerHandler::webHandlePageNotFound() {
|
||||
Log.error(F("WEB : URL not found %s received." CR), _server->uri().c_str());
|
||||
_server->send(404, "text/plain", F("URL not found"));
|
||||
}
|
||||
|
||||
//
|
||||
// Setup the Web Server callbacks and start it
|
||||
//
|
||||
bool WebServerHandler::setupWebServer() {
|
||||
Log.notice(F("WEB : Configuring web server." CR));
|
||||
|
||||
@ -1240,7 +1040,7 @@ bool WebServerHandler::setupWebServer() {
|
||||
LittleFS.remove(dir.fileName().c_str());
|
||||
}
|
||||
}
|
||||
#else // defined( ESP32 )
|
||||
#else
|
||||
File root = LittleFS.open("/");
|
||||
File f = root.openNextFile();
|
||||
while (f) {
|
||||
@ -1258,7 +1058,6 @@ bool WebServerHandler::setupWebServer() {
|
||||
|
||||
// Static content
|
||||
Log.notice(F("WEB : Setting up handlers for web server." CR));
|
||||
#if defined(EMBED_HTML)
|
||||
_server->on("/", std::bind(&WebServerHandler::webReturnIndexHtm, this));
|
||||
_server->on("/index.htm",
|
||||
std::bind(&WebServerHandler::webReturnIndexHtm, this));
|
||||
@ -1272,31 +1071,6 @@ bool WebServerHandler::setupWebServer() {
|
||||
std::bind(&WebServerHandler::webReturnAboutHtm, this));
|
||||
_server->on("/test.htm",
|
||||
std::bind(&WebServerHandler::webReturnTestHtm, this));
|
||||
#else
|
||||
// Check if the html files exist, if so serve them, else show the static
|
||||
// upload page.
|
||||
if (checkHtmlFile(HTML_INDEX) && checkHtmlFile(HTML_CONFIG) &&
|
||||
checkHtmlFile(HTML_CALIBRATION) && checkHtmlFile(HTML_FORMAT) &&
|
||||
checkHtmlFile(HTML_ABOUT) && checkHtmlFile(HTML_TEST)) {
|
||||
Log.notice(F("WEB : All html files exist, starting in normal mode." CR));
|
||||
|
||||
_server->serveStatic("/", LittleFS, "/index.min.htm");
|
||||
_server->serveStatic("/index.htm", LittleFS, "/index.min.htm");
|
||||
_server->serveStatic("/config.htm", LittleFS, "/config.min.htm");
|
||||
_server->serveStatic("/about.htm", LittleFS, "/about.min.htm");
|
||||
_server->serveStatic("/test.htm", LittleFS, "/test.min.htm");
|
||||
_server->serveStatic("/calibration.htm", LittleFS, "/calibration.min.htm");
|
||||
_server->serveStatic("/format.htm", LittleFS, "/format.min.htm");
|
||||
|
||||
// Also add the static upload view in case we we have issues that needs to
|
||||
// be fixed.
|
||||
_server->on("/upload.htm",
|
||||
std::bind(&WebServerHandler::webReturnUploadHtm, this));
|
||||
} else {
|
||||
Log.error(F("WEB : Missing html files, starting with upload UI." CR));
|
||||
_server->on("/", std::bind(&WebServerHandler::webReturnUploadHtm, this));
|
||||
}
|
||||
#endif
|
||||
_server->on("/firmware.htm",
|
||||
std::bind(&WebServerHandler::webReturnFirmwareHtm, this));
|
||||
_server->serveStatic("/log", LittleFS, ERR_FILENAME);
|
||||
@ -1320,9 +1094,6 @@ bool WebServerHandler::setupWebServer() {
|
||||
std::bind(&WebServerHandler::webHandleStatus, this));
|
||||
_server->on("/api/clearwifi", HTTP_GET,
|
||||
std::bind(&WebServerHandler::webHandleClearWIFI, this));
|
||||
_server->on(
|
||||
"/api/upload", HTTP_GET,
|
||||
std::bind(&WebServerHandler::webHandleUpload, this)); // Get upload.json
|
||||
|
||||
_server->on("/api/upload", HTTP_POST,
|
||||
std::bind(&WebServerHandler::webReturnOK, this),
|
||||
|
@ -29,26 +29,39 @@ SOFTWARE.
|
||||
#include <ESP8266WiFi.h>
|
||||
#include <ESP8266mDNS.h>
|
||||
#define MAX_SKETCH_SPACE 1044464
|
||||
#else // defined (ESP32)
|
||||
#else
|
||||
#include <ESPmDNS.h>
|
||||
#include <Update.h>
|
||||
#include <WebServer.h>
|
||||
#include <WiFi.h>
|
||||
#define MAX_SKETCH_SPACE 1835008
|
||||
#endif
|
||||
#include <incbin.h>
|
||||
|
||||
#if defined(EMBED_HTML)
|
||||
#if defined(ESP8266)
|
||||
#include <incbin.h>
|
||||
INCBIN_EXTERN(IndexHtm);
|
||||
INCBIN_EXTERN(ConfigHtm);
|
||||
INCBIN_EXTERN(CalibrationHtm);
|
||||
INCBIN_EXTERN(FormatHtm);
|
||||
INCBIN_EXTERN(TestHtm);
|
||||
INCBIN_EXTERN(AboutHtm);
|
||||
#else
|
||||
INCBIN_EXTERN(UploadHtm);
|
||||
#endif
|
||||
INCBIN_EXTERN(FirmwareHtm);
|
||||
#else
|
||||
extern const uint8_t indexHtmStart[] asm("_binary_html_index_min_htm_start");
|
||||
extern const uint8_t indexHtmEnd[] asm("_binary_html_index_min_htm_end");
|
||||
extern const uint8_t configHtmStart[] asm("_binary_html_config_min_htm_start");
|
||||
extern const uint8_t configHtmEnd[] asm("_binary_html_config_min_htm_end");
|
||||
extern const uint8_t calibrationHtmStart[] asm("_binary_html_calibration_min_htm_start");
|
||||
extern const uint8_t calibrationHtmEnd[] asm("_binary_html_calibration_min_htm_end");
|
||||
extern const uint8_t formatHtmStart[] asm("_binary_html_format_min_htm_start");
|
||||
extern const uint8_t formatHtmEnd[] asm("_binary_html_format_min_htm_end");
|
||||
extern const uint8_t testHtmStart[] asm("_binary_html_test_min_htm_start");
|
||||
extern const uint8_t testHtmEnd[] asm("_binary_html_test_min_htm_end");
|
||||
extern const uint8_t aboutHtmStart[] asm("_binary_html_about_min_htm_start");
|
||||
extern const uint8_t aboutHtmEnd[] asm("_binary_html_about_min_htm_end");
|
||||
extern const uint8_t firmwareHtmStart[] asm("_binary_html_firmware_min_htm_start");
|
||||
extern const uint8_t firmwareHtmEnd[] asm("_binary_html_firmware_min_htm_end");
|
||||
#endif
|
||||
|
||||
class WebServerHandler {
|
||||
private:
|
||||
@ -75,7 +88,6 @@ class WebServerHandler {
|
||||
void webHandleFactoryDefaults();
|
||||
void webHandleCalibrate();
|
||||
void webHandleUploadFile();
|
||||
void webHandleUpload();
|
||||
void webHandleLogClear();
|
||||
void webHandlePageNotFound();
|
||||
|
||||
@ -86,7 +98,7 @@ class WebServerHandler {
|
||||
|
||||
// Inline functions.
|
||||
void webReturnOK() { _server->send(_uploadReturn); }
|
||||
#if defined(EMBED_HTML)
|
||||
#if defined(ESP8266)
|
||||
void webReturnIndexHtm() {
|
||||
_server->send_P(200, "text/html", (const char*)gIndexHtmData,
|
||||
gIndexHtmSize);
|
||||
@ -110,31 +122,37 @@ class WebServerHandler {
|
||||
void webReturnTestHtm() {
|
||||
_server->send_P(200, "text/html", (const char*)gTestHtmData, gTestHtmSize);
|
||||
}
|
||||
#else
|
||||
void webReturnUploadHtm() {
|
||||
_server->send_P(200, "text/html", (const char*)gUploadHtmData,
|
||||
gUploadHtmSize);
|
||||
}
|
||||
#endif
|
||||
void webReturnFirmwareHtm() {
|
||||
_server->send_P(200, "text/html", (const char*)gFirmwareHtmData,
|
||||
gFirmwareHtmSize);
|
||||
}
|
||||
#else
|
||||
void webReturnIndexHtm() {
|
||||
_server->send_P(200, "text/html", (const char*)indexHtmStart, indexHtmEnd-indexHtmStart);
|
||||
}
|
||||
void webReturnConfigHtm() {
|
||||
_server->send_P(200, "text/html", (const char*)configHtmStart, configHtmEnd-configHtmStart);
|
||||
}
|
||||
void webReturnCalibrationHtm() {
|
||||
_server->send_P(200, "text/html", (const char*)calibrationHtmStart, calibrationHtmEnd-calibrationHtmStart);
|
||||
}
|
||||
void webReturnFormatHtm() {
|
||||
_server->send_P(200, "text/html", (const char*)formatHtmStart, formatHtmEnd-formatHtmStart);
|
||||
}
|
||||
void webReturnAboutHtm() {
|
||||
_server->send_P(200, "text/html", (const char*)aboutHtmStart, aboutHtmEnd-aboutHtmStart);
|
||||
}
|
||||
void webReturnTestHtm() {
|
||||
_server->send_P(200, "text/html", (const char*)testHtmStart, testHtmEnd-testHtmStart);
|
||||
}
|
||||
void webReturnFirmwareHtm() {
|
||||
_server->send_P(200, "text/html", (const char*)firmwareHtmStart, firmwareHtmEnd-firmwareHtmStart);
|
||||
}
|
||||
#endif
|
||||
|
||||
public:
|
||||
enum HtmlFile {
|
||||
HTML_INDEX = 0,
|
||||
HTML_CONFIG = 1,
|
||||
HTML_ABOUT = 2,
|
||||
HTML_CALIBRATION = 3,
|
||||
HTML_FORMAT = 4,
|
||||
HTML_TEST = 5
|
||||
};
|
||||
|
||||
bool setupWebServer();
|
||||
void loop();
|
||||
bool checkHtmlFile(HtmlFile item);
|
||||
const char* getHtmlFileName(HtmlFile item);
|
||||
};
|
||||
|
||||
// Global instance created
|
||||
|
@ -91,8 +91,6 @@ This is a list of C++ defines that is used to enable/disable functions in the co
|
||||
- Done include verbose logging in the corresponding class. Excessive logging may crash device.
|
||||
* - USE_LITTLEFS
|
||||
- Use the new filesystem in Ardurino
|
||||
* - EMBED_HTML
|
||||
- Html files are included in code, if not defined they are served from the file system.
|
||||
* - USER_SSID
|
||||
- If defined the device will always use this SSID
|
||||
* - USER_SSID_PWD
|
||||
|
Reference in New Issue
Block a user