Device Discovery using external Webserver
Opened this issue · 1 comments
when using an external already existing Async webserver with the
espalexa.begin(&myexternalserver)
the discovery of Alexa will not work. I looked into and figured out, that the hue api calls (my.i.p.addr/api/...) are called by the 404 error Callback(the .onNotFound Callback of the async webserver class)
I hope I have no other mistake in using the library, but I needed to change the callback setting in Espalexa.h to this:
...void startHttpServer()
{
#ifdef ESPALEXA_ASYNC
if (serverAsync == nullptr) {
serverAsync = new AsyncWebServer(80);
//serverAsync->onNotFound([=](AsyncWebServerRequest *request){server = request; serveNotFound();});
}
serverAsync->onNotFound([=](AsyncWebServerRequest *request){server = request; serveNotFound();});
serverAsync->onRequestBody([=](AsyncWebServerRequest *request, uint8_t *data, size_t len, size_t index, size_t total){
...
After this change the api calls are working and the device was discovered by Alexa.
I had the same problem - and also just overlooked it...
you don't need to modify the the lib you need just add the following line at the end of the webserver definition:
webServer.onNotFound([=](AsyncWebServerRequest *request){if (!espalexa.handleAlexaApiCall(request)) request->send(404, "text/plain", "Not Found"); });