From 1d23e6cfef077b987d61ec5a4b659efb905c36a1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fabian=20M=C3=BCller?= Date: Fri, 12 Apr 2024 03:22:24 +0200 Subject: [PATCH] Add HTTP API endpoint for raw messages RESTful version of simple socket listener. --- src/webserver.h | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) 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); }