diff --git a/src/webserver.h b/src/webserver.h index a9a1b45..d002891 100644 --- a/src/webserver.h +++ b/src/webserver.h @@ -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); }