From 9280078f71a117420eb63785efff198b3756f2e2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Xose=20P=C3=A9rez?= Date: Mon, 14 Nov 2016 21:05:55 +0100 Subject: [PATCH] Bring back HTTP relay entry points --- code/src/web.ino | 19 ++++++++++++++++++- 1 file changed, 18 insertions(+), 1 deletion(-) diff --git a/code/src/web.ino b/code/src/web.ino index 165685cb..31bff6a2 100644 --- a/code/src/web.ino +++ b/code/src/web.ino @@ -242,6 +242,7 @@ void webSocketEvent(AsyncWebSocket * server, AsyncWebSocketClient * client, AwsE // ----------------------------------------------------------------------------- void onHome(AsyncWebServerRequest *request) { + DEBUG_MSG("[WEBSERVER] Request: %s\n", request->url().c_str()); String password = getSetting("adminPass", ADMIN_PASS); char httpPassword[password.length() + 1]; password.toCharArray(httpPassword, password.length() + 1); @@ -251,16 +252,32 @@ void onHome(AsyncWebServerRequest *request) { request->send(SPIFFS, "/index.html"); } +void onRelayOn(AsyncWebServerRequest *request) { + DEBUG_MSG("[WEBSERVER] Request: %s\n", request->url().c_str()); + switchRelayOn(); + request->send(200, "text/plain", "ON"); +}; + +void onRelayOff(AsyncWebServerRequest *request) { + DEBUG_MSG("[WEBSERVER] Request: %s\n", request->url().c_str()); + switchRelayOff(); + request->send(200, "text/plain", "OFF"); +}; + void webSetup() { // Setup websocket plugin ws.onEvent(webSocketEvent); server.addHandler(&ws); - // Serve home + // Serve home (password protected) server.on("/", HTTP_GET, onHome); server.on("/index.html", HTTP_GET, onHome); + // API entry points (non protected) + server.on("/relay/on", HTTP_GET, onRelayOn); + server.on("/relay/off", HTTP_GET, onRelayOff); + // Serve static files server.serveStatic("/", SPIFFS, "/");