|
@ -36,6 +36,34 @@ 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)); |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
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); |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
#if BROKER_SUPPORT
|
|
|
|
|
|
void _alexaBrokerCallback(const char * topic, unsigned char id, const char * payload) { |
|
|
|
|
|
|
|
|
|
|
|
unsigned char value = atoi(payload); |
|
|
|
|
|
|
|
|
|
|
|
if (strcmp(MQTT_TOPIC_CHANNEL, topic) == 0) { |
|
|
|
|
|
alexa.setState(id+1, value > 0, value); |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
if (strcmp(MQTT_TOPIC_RELAY, topic) == 0) { |
|
|
|
|
|
#if RELAY_PROVIDER == RELAY_PROVIDER_LIGHT
|
|
|
|
|
|
if (id > 0) return; |
|
|
|
|
|
#endif
|
|
|
|
|
|
alexa.setState(id, value, value > 0 ? 255 : 0); |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
} |
|
|
|
|
|
#endif // BROKER_SUPPORT
|
|
|
|
|
|
|
|
|
// -----------------------------------------------------------------------------
|
|
|
// -----------------------------------------------------------------------------
|
|
|
|
|
|
|
|
|
bool alexaEnabled() { |
|
|
bool alexaEnabled() { |
|
@ -47,8 +75,9 @@ void alexaSetup() { |
|
|
// Backwards compatibility
|
|
|
// Backwards compatibility
|
|
|
moveSetting("fauxmoEnabled", "alexaEnabled"); |
|
|
moveSetting("fauxmoEnabled", "alexaEnabled"); |
|
|
|
|
|
|
|
|
// Load & cache settings
|
|
|
|
|
|
_alexaConfigure(); |
|
|
|
|
|
|
|
|
// Basic fauxmoESP configuration
|
|
|
|
|
|
alexa.createServer(false); |
|
|
|
|
|
alexa.setPort(80); |
|
|
|
|
|
|
|
|
// Uses hostname as base name for all devices
|
|
|
// Uses hostname as base name for all devices
|
|
|
// TODO: use custom switch name when available
|
|
|
// TODO: use custom switch name when available
|
|
@ -79,6 +108,9 @@ void alexaSetup() { |
|
|
|
|
|
|
|
|
#endif
|
|
|
#endif
|
|
|
|
|
|
|
|
|
|
|
|
// Load & cache settings
|
|
|
|
|
|
_alexaConfigure(); |
|
|
|
|
|
|
|
|
// Websockets
|
|
|
// Websockets
|
|
|
#if WEB_SUPPORT
|
|
|
#if WEB_SUPPORT
|
|
|
wsOnSendRegister(_alexaWebSocketOnSend); |
|
|
wsOnSendRegister(_alexaWebSocketOnSend); |
|
@ -102,8 +134,13 @@ void alexaSetup() { |
|
|
}); |
|
|
}); |
|
|
|
|
|
|
|
|
// Register main callbacks
|
|
|
// Register main callbacks
|
|
|
espurnaRegisterLoop(alexaLoop); |
|
|
|
|
|
|
|
|
webBodyRegister(_alexaBodyCallback); |
|
|
|
|
|
webRequestRegister(_alexaRequestCallback); |
|
|
|
|
|
#if BROKER_SUPPORT
|
|
|
|
|
|
brokerRegister(_alexaBrokerCallback); |
|
|
|
|
|
#endif
|
|
|
espurnaRegisterReload(_alexaConfigure); |
|
|
espurnaRegisterReload(_alexaConfigure); |
|
|
|
|
|
espurnaRegisterLoop(alexaLoop); |
|
|
|
|
|
|
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|