Browse Source

Merge pull request #1491 from mcspr/alexa/no-web-support

Use built-in fauxmoESP HTTP handler when WEB_SUPPORT=0
sensors
Xose Pérez 5 years ago
committed by GitHub
parent
commit
867b9e5fba
No known key found for this signature in database GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 12 additions and 10 deletions
  1. +12
    -10
      code/espurna/alexa.ino

+ 12
- 10
code/espurna/alexa.ino View File

@ -36,14 +36,16 @@ void _alexaConfigure() {
alexa.enable(wifiConnected() && alexaEnabled()); 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 #if BROKER_SUPPORT
void _alexaBrokerCallback(const unsigned char type, const char * topic, unsigned char id, const char * payload) { void _alexaBrokerCallback(const unsigned char type, const char * topic, unsigned char id, const char * payload) {
@ -79,7 +81,7 @@ void alexaSetup() {
moveSetting("fauxmoEnabled", "alexaEnabled"); moveSetting("fauxmoEnabled", "alexaEnabled");
// Basic fauxmoESP configuration // Basic fauxmoESP configuration
alexa.createServer(false);
alexa.createServer(!WEB_SUPPORT);
alexa.setPort(80); alexa.setPort(80);
// Uses hostname as base name for all devices // Uses hostname as base name for all devices
@ -116,6 +118,8 @@ void alexaSetup() {
// Websockets // Websockets
#if WEB_SUPPORT #if WEB_SUPPORT
webBodyRegister(_alexaBodyCallback);
webRequestRegister(_alexaRequestCallback);
wsOnSendRegister(_alexaWebSocketOnSend); wsOnSendRegister(_alexaWebSocketOnSend);
wsOnReceiveRegister(_alexaWebSocketOnReceive); wsOnReceiveRegister(_alexaWebSocketOnReceive);
#endif #endif
@ -137,8 +141,6 @@ void alexaSetup() {
}); });
// Register main callbacks // Register main callbacks
webBodyRegister(_alexaBodyCallback);
webRequestRegister(_alexaRequestCallback);
#if BROKER_SUPPORT #if BROKER_SUPPORT
brokerRegister(_alexaBrokerCallback); brokerRegister(_alexaBrokerCallback);
#endif #endif


Loading…
Cancel
Save