Add HTTP API endpoint for raw messages

RESTful version of simple socket listener.
This commit is contained in:
Fabian Müller 2024-04-12 03:22:24 +02:00
parent 4a82fdc7f5
commit 1d23e6cfef

View File

@ -66,6 +66,21 @@ namespace {
sendTextToSign(text);
webServer.send(200, "text/plain", "ok");
}
// RESTful API endpoint -- returns a proper status code rather than a redirect
void handleRawApiSend() {
String toSend = webServer.arg("plain");
if (toSend.isEmpty()) {
webServer.send(404, "text/plain", "empty body");
return;
}
Serial.println("Raw message sent to device: " + toSend);
Serial.println("Hex dump: " + hexDump(toSend));
Serial1.print(toSend);
webServer.send(200, "text/plain", "ok");
}
}
void configureWebServer() {
@ -74,4 +89,5 @@ void configureWebServer() {
webServer.on("/", HTTPMethod::HTTP_GET, handleIndex);
webServer.on("/", HTTPMethod::HTTP_POST, handleFormSend);
webServer.on("/send", HTTPMethod::HTTP_POST, handleApiSend);
webServer.on("/raw", HTTPMethod::HTTP_POST, handleRawApiSend);
}