Skip to content

Commit

Permalink
Merge pull request #134 from eadmaster/esp32s3headless-webui
Browse files Browse the repository at this point in the history
added webui serial button (#107)
  • Loading branch information
pr3y authored Aug 7, 2024
2 parents 40f480f + 11f3ff9 commit fe1c214
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 2 deletions.
5 changes: 3 additions & 2 deletions src/modules/others/webInterface.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -307,9 +307,10 @@ void configureWebServer() {
if (server->hasArg("cmnd")) {
String cmnd = server->arg("cmnd");
if( processSerialCommand( cmnd ) ) {
server->send(200, "text/plain", "OK");
setup_gpio(); // temp fix for menu inf. loop
server->send(200, "text/plain", "command " + cmnd + " success");
} else {
server->send(400, "text/plain", "ERROR, check the serial log on the device for details");
server->send(400, "text/plain", "command failed, check the serial log for details");
}
}
server->send(400, "text/plain", "http request missing required arg: cmnd");
Expand Down
16 changes: 16 additions & 0 deletions src/modules/others/webInterface.h
Original file line number Diff line number Diff line change
Expand Up @@ -331,6 +331,7 @@ const char index_html[] PROGMEM = R"rawliteral(
</form>
<button onclick="rebootButton()">Reboot</button>
<button onclick="WifiConfig()">Usr/Pass</button>
<button onclick="serialCmd()">SerialCmd</button>
<button onclick="listFilesButton('/', 'SD', true)">SD Files</button>
<button onclick="listFilesButton('/', 'LittleFS', true)">LittleFS</button>

Expand Down Expand Up @@ -362,6 +363,21 @@ function WifiConfig() {
}
}

function serialCmd() {
let cmd = prompt("Enter a serial command", "");
if (cmd == null || cmd == "" || cmd == null) {
window.alert("empty command, nothing sent");
} else {
const ajax5 = new XMLHttpRequest();
const formdata5 = new FormData();
formdata5.append("cmnd", cmd);
ajax5.open("POST", "/cm", false);
ajax5.send(formdata5);
//document.getElementById("status").innerHTML = ajax5.responseText;
window.alert(ajax5.responseText);
}
}

function logoutButton() {
var xhr = new XMLHttpRequest();
xhr.open("GET", "/logout", true);
Expand Down

0 comments on commit fe1c214

Please sign in to comment.