Skip to content

Commit

Permalink
Merge pull request #94 from lasselukkari/captive-portal-example
Browse files Browse the repository at this point in the history
Captive portal example
  • Loading branch information
lasselukkari authored Jan 16, 2021
2 parents 9899b64 + 7112e0d commit 376d8f3
Show file tree
Hide file tree
Showing 4 changed files with 63 additions and 1 deletion.
5 changes: 5 additions & 0 deletions .gitattributes
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
3 changes: 3 additions & 0 deletions examples/CaptivePortal/.arduino-ci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
compile:
platforms:
- esp32
54 changes: 54 additions & 0 deletions examples/CaptivePortal/CaptivePortal.ino
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();
}
2 changes: 1 addition & 1 deletion library.properties
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
name=aWOT
version=3.1.2
version=3.1.3
author=Lasse Lukkari <lasse.lukkari@gmail.com>
maintainer=Lasse Lukkari <lasse.lukkari@gmail.com>
sentence=Arduino web server library.
Expand Down

0 comments on commit 376d8f3

Please sign in to comment.