-
Notifications
You must be signed in to change notification settings - Fork 42
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #94 from lasselukkari/captive-portal-example
Captive portal example
- Loading branch information
Showing
4 changed files
with
63 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
arduino-ci.yml export-ignore | ||
/test/ export-ignore | ||
.git* export-ignore | ||
.travis.yml export-ignore | ||
Gemfile export-ignore |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
compile: | ||
platforms: | ||
- esp32 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
#if defined(ESP8266) | ||
#include <ESP8266WiFi.h> | ||
#else | ||
#include <WiFi.h> | ||
#endif | ||
#include <DNSServer.h> | ||
#include <aWOT.h> | ||
|
||
DNSServer dnsServer; | ||
WiFiServer server(80); | ||
Application app; | ||
char redirectURL[30]; | ||
|
||
void redirect(Request &req, Response &res) { | ||
if (!res.statusSent()) { | ||
res.set("Location", redirectURL); | ||
res.sendStatus(302); | ||
} | ||
} | ||
|
||
void index(Request &req, Response &res) { | ||
res.print("Captive portal index"); | ||
} | ||
|
||
void popup(Request &req, Response &res) { | ||
res.print("Captive portal popup"); | ||
} | ||
|
||
void setup() { | ||
Serial.begin(115200); | ||
|
||
WiFi.softAP("TestNetwork", "TestNetwork"); | ||
IPAddress ip = WiFi.softAPIP(); | ||
sprintf(redirectURL, "http://%d.%d.%d.%d/popup", ip[0], ip[1], ip[2], ip[3]); | ||
Serial.println(ip); | ||
|
||
app.get("/", &index); | ||
app.get("/popup", &popup); | ||
app.use(&redirect); | ||
|
||
server.begin(); | ||
|
||
dnsServer.start(53, "*", ip); | ||
} | ||
|
||
void loop() { | ||
WiFiClient client = server.available(); | ||
|
||
if (client.connected()) { | ||
app.process(&client); | ||
} | ||
|
||
dnsServer.processNextRequest(); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters