vintlabs / fauxmoESP

Add voice control of your ESP32 and ESP8266 devices using Amazon Alexa
MIT License
383 stars 69 forks source link

fauxmoESP with Esp8266webserver. #101

Closed pvint closed 3 years ago

pvint commented 4 years ago

Original report by Enrico A. (Bitbucket: [Enrico A.](https://bitbucket.org/Enrico A.), ).


Is possible to use fauxmoESP with Esp8266webserver as external webserver?
Looking at some messages seems that previous versions was using it, now require AsyncWebserver.

pvint commented 4 years ago

Original comment by Alexander Pankow (Bitbucket: [Alexander Pankow](https://bitbucket.org/Alexander Pankow), ).


+1 for support for ESP8266 webserver.

With the current Adafruit DHT sensor library the ESP8266 crashes if we try to get the DHT data via the web server. It does not crash with older versions of the library, but no data is output.

So, currently it is impossible for me to make the fauxmo library working for gen3 devices AND work with a webserver. :disappointed:

Regards,
Alexander

pvint commented 4 years ago

Original comment by Enrico A. (Bitbucket: [Enrico A.](https://bitbucket.org/Enrico A.), ).


Hi Alexander I made a small modify to source to redirect port80 of the internal webaserver to whatever port. So you can use ESP8266webserver or whatever server you want without problems:
is just a small mod that i hope that somebody will be merge it with source.
go in src folder of fauxmo exp lib:

in file fauxmoESP.cpp
in class bool fauxmoESP::_onTCPRequest(AsyncClient *client, bool isGet, String url, String body) {
at the end before of:
    return false; }

add this:

    if (_redirect_port!=0){
    char response[strlen_P(FAUXMO_REDIRECT)+5];
        snprintf_P(
            response, sizeof(response),
            FAUXMO_REDIRECT,
            _redirect_port
        );
    _sendTCPResponse(client, "200 OK", response, "text/html");
}

in the file fauxmoESP.h
after void setPort(unsigned long tcp_port) { _tcp_port = tcp_port; }

add this line:
void setRedirect(unsigned long redirect_port) { _redirect_port = redirect_port; }

and after the line: unsigned int _tcp_port = FAUXMO_TCP_PORT;

add this line:
unsigned int _redirect_port = 0;

and finally in file templates.h
after this code:

PROGMEM const char FAUXMO_TCP_STATE_RESPONSE[] = "["
"{"success":{"/lights/%d/state/on":%s}},"
"{"success":{"/lights/%d/state/bri":%d}}" // not needed?
"]";

add:

PROGMEM const char FAUXMO_REDIRECT[] = "<!DOCTYPE HTML>"
" Githubissues.

  • Githubissues is a development platform for aggregating issues.