simple serial monitor in httpserver

This commit is contained in:
Simon Schmidt 2021-06-26 10:49:29 +02:00
parent 4e6445fea8
commit b89604edc3
6 changed files with 75 additions and 15 deletions

View File

@ -60,6 +60,13 @@
</div> </div>
</div> </div>
<div class="terminal">
<input type="button" id="clear_term" value="clear" onclick="clearTerminal();">
<input type="checkbox" id="scroll" name="scroll" value="scroll">
<label for="scroll"> autoscroll </label>
<textarea id="term"> waiting for log messages ... </textarea>
</div>
</body> </body>
<script src="/input.js"></script> <script src="/input.js"></script>

View File

@ -1,8 +1,40 @@
var slider = document.getElementById("range1"); // var slider = document.getElementById("helligkeit");
var output = document.getElementById("l_pwm"); // var output = document.getElementById("l_pwm");
output.innerHTML = slider.value; // Display the default slider value // output.innerHTML = slider.value; // Display the default slider value
// Update the current slider value (each time you drag the slider handle) // // Update the current slider value (each time you drag the slider handle)
slider.oninput = function() { // slider.oninput = function() {
output.innerHTML = this.value; // 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 = '';
} }

View File

@ -3,7 +3,7 @@ html {
font-family: sans-serif, Arial, Helvetica; font-family: sans-serif, Arial, Helvetica;
background-color: #d4d4d4; background-color: #d4d4d4;
height: 100%; height: 100%;
background-image: url('Background.png'); /* background-image: url('Background.png'); */
background-repeat: repeat; background-repeat: repeat;
background-size: 150% 150%; background-size: 150% 150%;
} }
@ -103,4 +103,22 @@ input:checked + .slider:before {
-ms-transform: translateX(26px); -ms-transform: translateX(26px);
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;
}

View File

@ -1,12 +1,5 @@
#include "filesys.h" #include "filesys.h"
// listDir("/");
// deleteFile("/hello.txt");
// writeFile("/hello.txt", "Hello ");
// appendFile("/hello.txt", "World!\n\r");
// printFile("/hello.txt");
// listDir("/");
FSInfo fsinfo; FSInfo fsinfo;
bool mount_fs() { bool mount_fs() {

View File

@ -2,6 +2,8 @@
#include <LittleFS.h> #include <LittleFS.h>
// some usefull wrappers for Filesystem
bool mount_fs(); bool mount_fs();
bool format_fs(); bool format_fs();

View File

@ -38,6 +38,7 @@ public:
File f = open("/compress.html.gz"); File f = open("/compress.html.gz");
if (!f) { if (!f) {
Serial.println("Failed to open file for reading"); Serial.println("Failed to open file for reading");
send(404, "text/plain", "Failed to open file for reading");
} }
else else
{ {
@ -50,7 +51,7 @@ public:
File f = open("/comp.html.gz"); File f = open("/comp.html.gz");
if (!f) { if (!f) {
Serial.println("Failed to open file for reading"); Serial.println("Failed to open file for reading");
send(404, "text/plain", "Failed to open file for reading");
} }
else else
{ {
@ -59,6 +60,13 @@ public:
streamFile(f, cont); streamFile(f, cont);
} }
}); });
on("/terminal", [this]() {
String log_msg = "terminal: millis: ";
log_msg += millis();
send(200, "text/plain", log_msg);
});
onNotFound([this]() { onNotFound([this]() {
String message = "File Not Found\n\n"; String message = "File Not Found\n\n";
message += "URI: "; message += "URI: ";