From b89604edc377cbff71ae3037e6418c7e2adf323d Mon Sep 17 00:00:00 2001 From: Simon Schmidt Date: Sat, 26 Jun 2021 10:49:29 +0200 Subject: [PATCH] simple serial monitor in httpserver --- data/index.html | 7 ++++++ data/input.js | 44 ++++++++++++++++++++++++++++++++----- data/style.css | 20 ++++++++++++++++- lib/httpserver/filesys.cpp | 7 ------ lib/httpserver/filesys.h | 2 ++ lib/httpserver/httpserver.h | 10 ++++++++- 6 files changed, 75 insertions(+), 15 deletions(-) diff --git a/data/index.html b/data/index.html index d9f2860..204f746 100644 --- a/data/index.html +++ b/data/index.html @@ -60,6 +60,13 @@ +
+ + + + +
+ diff --git a/data/input.js b/data/input.js index f1ea08e..69ad112 100644 --- a/data/input.js +++ b/data/input.js @@ -1,8 +1,40 @@ -var slider = document.getElementById("range1"); -var output = document.getElementById("l_pwm"); -output.innerHTML = slider.value; // Display the default slider value +// var slider = document.getElementById("helligkeit"); +// var output = document.getElementById("l_pwm"); +// output.innerHTML = slider.value; // Display the default slider value -// Update the current slider value (each time you drag the slider handle) -slider.oninput = function() { - output.innerHTML = this.value; +// // Update the current slider value (each time you drag the slider handle) +// slider.oninput = function() { +// output.innerHTML = this.value; +// } + + + +let xhr = new XMLHttpRequest(); + +xhr.onreadystatechange = function(){ + if(xhr.readyState == 4) { + if (xhr.status == 200){ + console.log(xhr.responseText); + terminal = document.getElementById("term"); + autoscroll = document.getElementById("scroll"); + terminal.innerHTML += xhr.responseText + '\n'; + if(autoscroll.checked) + terminal.scrollTop = terminal.scrollHeight; + } + else { + console.log("status:", xhr.status); + } + } +} + +function reloadTerminal() { + xhr.open("GET", "/terminal", true); + xhr.send(); + setTimeout(reloadTerminal, 1000); +}; + +reloadTerminal(); + +function clearTerminal() { + document.getElementById("term").innerHTML = ''; } \ No newline at end of file diff --git a/data/style.css b/data/style.css index 1ac52d5..beb3812 100644 --- a/data/style.css +++ b/data/style.css @@ -3,7 +3,7 @@ html { font-family: sans-serif, Arial, Helvetica; background-color: #d4d4d4; height: 100%; - background-image: url('Background.png'); + /* background-image: url('Background.png'); */ background-repeat: repeat; background-size: 150% 150%; } @@ -103,4 +103,22 @@ input:checked + .slider:before { -ms-transform: translateX(26px); transform: translateX(26px); } +*/ +.terminal { + margin:5%; + padding: 1%; + width: 80%; + border: 1px solid black; + border-radius: 5px; +} + +#term { + font-size: large; + width: 100%; + height: 10em; +} + +#clear_term { + margin: 2px; +} \ No newline at end of file diff --git a/lib/httpserver/filesys.cpp b/lib/httpserver/filesys.cpp index b315964..2e2b1aa 100644 --- a/lib/httpserver/filesys.cpp +++ b/lib/httpserver/filesys.cpp @@ -1,12 +1,5 @@ #include "filesys.h" -// listDir("/"); -// deleteFile("/hello.txt"); -// writeFile("/hello.txt", "Hello "); -// appendFile("/hello.txt", "World!\n\r"); -// printFile("/hello.txt"); -// listDir("/"); - FSInfo fsinfo; bool mount_fs() { diff --git a/lib/httpserver/filesys.h b/lib/httpserver/filesys.h index 708c1f4..da4a754 100644 --- a/lib/httpserver/filesys.h +++ b/lib/httpserver/filesys.h @@ -2,6 +2,8 @@ #include +// some usefull wrappers for Filesystem + bool mount_fs(); bool format_fs(); diff --git a/lib/httpserver/httpserver.h b/lib/httpserver/httpserver.h index 3574b55..7078bff 100644 --- a/lib/httpserver/httpserver.h +++ b/lib/httpserver/httpserver.h @@ -38,6 +38,7 @@ public: File f = open("/compress.html.gz"); if (!f) { Serial.println("Failed to open file for reading"); + send(404, "text/plain", "Failed to open file for reading"); } else { @@ -50,7 +51,7 @@ public: File f = open("/comp.html.gz"); if (!f) { Serial.println("Failed to open file for reading"); - + send(404, "text/plain", "Failed to open file for reading"); } else { @@ -58,7 +59,14 @@ public: const String cont = "text/html"; streamFile(f, cont); } + }); + + on("/terminal", [this]() { + String log_msg = "terminal: millis: "; + log_msg += millis(); + send(200, "text/plain", log_msg); }); + onNotFound([this]() { String message = "File Not Found\n\n"; message += "URI: ";