From 3f946692c4308f2bcd6c50efbf33e6ab52921fdf Mon Sep 17 00:00:00 2001 From: Max Prokhorov Date: Tue, 15 Jan 2019 18:36:05 +0300 Subject: [PATCH] Use built-in fauxmoESP HTTP handler when WEB_SUPPORT=0 --- code/espurna/alexa.ino | 22 ++++++++++++---------- 1 file changed, 12 insertions(+), 10 deletions(-) diff --git a/code/espurna/alexa.ino b/code/espurna/alexa.ino index c4449f22..6da42fe0 100644 --- a/code/espurna/alexa.ino +++ b/code/espurna/alexa.ino @@ -36,14 +36,16 @@ void _alexaConfigure() { alexa.enable(wifiConnected() && alexaEnabled()); } -bool _alexaBodyCallback(AsyncWebServerRequest *request, uint8_t *data, size_t len, size_t index, size_t total) { - return alexa.process(request->client(), request->method() == HTTP_GET, request->url(), String((char *)data)); -} +#if WEB_SUPPORT + bool _alexaBodyCallback(AsyncWebServerRequest *request, uint8_t *data, size_t len, size_t index, size_t total) { + return alexa.process(request->client(), request->method() == HTTP_GET, request->url(), String((char *)data)); + } -bool _alexaRequestCallback(AsyncWebServerRequest *request) { - String body = (request->hasParam("body", true)) ? request->getParam("body", true)->value() : String(); - return alexa.process(request->client(), request->method() == HTTP_GET, request->url(), body); -} + bool _alexaRequestCallback(AsyncWebServerRequest *request) { + String body = (request->hasParam("body", true)) ? request->getParam("body", true)->value() : String(); + return alexa.process(request->client(), request->method() == HTTP_GET, request->url(), body); + } +#endif #if BROKER_SUPPORT void _alexaBrokerCallback(const unsigned char type, const char * topic, unsigned char id, const char * payload) { @@ -79,7 +81,7 @@ void alexaSetup() { moveSetting("fauxmoEnabled", "alexaEnabled"); // Basic fauxmoESP configuration - alexa.createServer(false); + alexa.createServer(!WEB_SUPPORT); alexa.setPort(80); // Uses hostname as base name for all devices @@ -116,6 +118,8 @@ void alexaSetup() { // Websockets #if WEB_SUPPORT + webBodyRegister(_alexaBodyCallback); + webRequestRegister(_alexaRequestCallback); wsOnSendRegister(_alexaWebSocketOnSend); wsOnReceiveRegister(_alexaWebSocketOnReceive); #endif @@ -137,8 +141,6 @@ void alexaSetup() { }); // Register main callbacks - webBodyRegister(_alexaBodyCallback); - webRequestRegister(_alexaRequestCallback); #if BROKER_SUPPORT brokerRegister(_alexaBrokerCallback); #endif