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

Release v0.8.5 #218

Merged
merged 4 commits into from
Sep 12, 2019
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
Next Next commit
First version of captive portal
  • Loading branch information
Aircoookie committed Sep 5, 2019
commit a3e28d3c6677b536e5a457acc2a02b7db8a0696f
1 change: 1 addition & 0 deletions wled00/wled05_init.ino
Original file line number Diff line number Diff line change
Expand Up @@ -180,6 +180,7 @@ void beginStrip()
void initAP(){
bool set = apSSID[0];
if (!set) strcpy(apSSID,"WLED-AP");
WiFi.softAPConfig(IPAddress(4, 3, 2, 1), IPAddress(4, 3, 2, 1), IPAddress(255,255,255,0));
WiFi.softAP(apSSID, apPass, apChannel, apHide);
if (!set) apSSID[0] = 0;
}
Expand Down
34 changes: 34 additions & 0 deletions wled00/wled18_server.ino
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,33 @@
* Server page definitions
*/

//Is this an IP?
bool isIp(String str) {
for (size_t i = 0; i < str.length(); i++) {
int c = str.charAt(i);
if (c != '.' && (c < '0' || c > '9')) {
return false;
}
}
return true;
}

bool captivePortal(AsyncWebServerRequest *request)
{
String hostH;
if (!request->hasHeader("Host")) return false;
hostH = request->getHeader("Host")->value();

if (!isIp(hostH) && hostH.indexOf("wled.me") < 0 && hostH.indexOf(cmDNS) < 0) {
DEBUG_PRINTLN("Captive portal");
AsyncWebServerResponse *response = request->beginResponse(302);
response->addHeader("Location", "http://local.wled.me");
request->send(response);
return true;
}
return false;
}

void initServer()
{
//CORS compatiblity
Expand Down Expand Up @@ -161,13 +188,20 @@ void initServer()
}

server.on("/", HTTP_GET, [](AsyncWebServerRequest *request){
if (captivePortal(request)) return;
serveIndexOrWelcome(request);
});

/*server.on("/generate_204", HTTP_GET, [](AsyncWebServerRequest *request){
//if (captivePortal(request)) return;
serveIndexOrWelcome(request);
});*/

//called when the url is not defined here, ajax-in; get-settings
server.onNotFound([](AsyncWebServerRequest *request){
DEBUG_PRINTLN("Not-Found HTTP call:");
DEBUG_PRINTLN("URI: " + request->url());
if (captivePortal(request)) return;

//make API CORS compatible
if (request->method() == HTTP_OPTIONS)
Expand Down