From ef397c64245f86b9549f2008e0b3709e91a0bde4 Mon Sep 17 00:00:00 2001 From: lamerjack Date: Sat, 28 Aug 2021 22:37:00 +0200 Subject: [PATCH 1/5] Update fauxmoESP.cpp Add redirect --- src/fauxmoESP.cpp | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) 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; } From feb05d8137ef6efb51c661201df6dbbf0c5c20a3 Mon Sep 17 00:00:00 2001 From: lamerjack Date: Sat, 28 Aug 2021 22:38:55 +0200 Subject: [PATCH 2/5] Update fauxmoESP.h Add redirect support --- src/fauxmoESP.h | 2 ++ 1 file changed, 2 insertions(+) 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; From 4eabaa79c731acd59d9c3bad976a0fb126e2c571 Mon Sep 17 00:00:00 2001 From: lamerjack Date: Sat, 28 Aug 2021 22:40:48 +0200 Subject: [PATCH 3/5] Update templates.h Add redirect support --- src/templates.h | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/templates.h b/src/templates.h index d16c3b0..3a3251c 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\"," From 7be47908428182e6d2120c7c6de54f19651eea71 Mon Sep 17 00:00:00 2001 From: lamerjack Date: Sat, 28 Aug 2021 23:04:20 +0200 Subject: [PATCH 4/5] Update templates.h --- src/templates.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/templates.h b/src/templates.h index 3a3251c..d6f15bd 100644 --- a/src/templates.h +++ b/src/templates.h @@ -40,7 +40,7 @@ PROGMEM const char FAUXMO_TCP_STATE_RESPONSE[] = "[" "]"; PROGMEM const char FAUXMO_REDIRECT[] = "" -""> +"" ""; // Working with gen1 and gen3, ON/OFF/%, gen3 requires TCP port 80 From c263b5a1e4752d363e6614b0701e495e922d10ce Mon Sep 17 00:00:00 2001 From: lamerjack Date: Sat, 28 Aug 2021 23:36:28 +0200 Subject: [PATCH 5/5] Update templates.h --- src/templates.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/templates.h b/src/templates.h index d6f15bd..8f76d8d 100644 --- a/src/templates.h +++ b/src/templates.h @@ -40,7 +40,7 @@ PROGMEM const char FAUXMO_TCP_STATE_RESPONSE[] = "[" "]"; PROGMEM const char FAUXMO_REDIRECT[] = "" -"" +"" ""; // Working with gen1 and gen3, ON/OFF/%, gen3 requires TCP port 80