diff --git a/src/fauxmoESP.cpp b/src/fauxmoESP.cpp index 39186dc..8ca469e 100644 --- a/src/fauxmoESP.cpp +++ b/src/fauxmoESP.cpp @@ -313,7 +313,17 @@ bool fauxmoESP::_onTCPRequest(AsyncClient *client, bool isGet, String url, Strin return _onTCPControl(client, url, body); } } - + + 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"); + } + return false; } diff --git a/src/fauxmoESP.h b/src/fauxmoESP.h index ab1b97b..8819dc8 100644 --- a/src/fauxmoESP.h +++ b/src/fauxmoESP.h @@ -102,6 +102,7 @@ class fauxmoESP { void enable(bool enable); void createServer(bool internal) { _internal = internal; } void setPort(unsigned long tcp_port) { _tcp_port = tcp_port; } + void setRedirect(unsigned long redirect_port) { _redirect_port = redirect_port; } void handle(); private: @@ -110,6 +111,7 @@ class fauxmoESP { bool _enabled = false; bool _internal = true; unsigned int _tcp_port = FAUXMO_TCP_PORT; + unsigned int _redirect_port = 0; std::vector _devices; #ifdef ESP8266 WiFiEventHandler _handler; diff --git a/src/templates.h b/src/templates.h index d16c3b0..8f76d8d 100644 --- a/src/templates.h +++ b/src/templates.h @@ -39,6 +39,10 @@ PROGMEM const char FAUXMO_TCP_STATE_RESPONSE[] = "[" "{\"success\":{\"/lights/%d/state/bri\":%d}}" // not needed? "]"; +PROGMEM const char FAUXMO_REDIRECT[] = "" +"" +""; + // Working with gen1 and gen3, ON/OFF/%, gen3 requires TCP port 80 PROGMEM const char FAUXMO_DEVICE_JSON_TEMPLATE[] = "{" "\"type\": \"Extended color light\","