Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Redirect feature #193

Open
wants to merge 5 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 11 additions & 1 deletion src/fauxmoESP.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;

}
Expand Down
2 changes: 2 additions & 0 deletions src/fauxmoESP.h
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand All @@ -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<fauxmoesp_device_t> _devices;
#ifdef ESP8266
WiFiEventHandler _handler;
Expand Down
4 changes: 4 additions & 0 deletions src/templates.h
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,10 @@ PROGMEM const char FAUXMO_TCP_STATE_RESPONSE[] = "["
"{\"success\":{\"/lights/%d/state/bri\":%d}}" // not needed?
"]";

PROGMEM const char FAUXMO_REDIRECT[] = "<!DOCTYPE HTML><html><body>"
"<script>window.location = 'http://'+window.location.hostname+':%d'+window.location.pathname+window.location.search;</script>"
"</body></html>";

// Working with gen1 and gen3, ON/OFF/%, gen3 requires TCP port 80
PROGMEM const char FAUXMO_DEVICE_JSON_TEMPLATE[] = "{"
"\"type\": \"Extended color light\","
Expand Down