-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathPuzzle_box.ino
88 lines (68 loc) · 2.57 KB
/
Puzzle_box.ino
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
// ESP8266 WiFi Captive Portal
// By 125K (github.com/125K)
// Includes
#include <ESP8266WiFi.h>
#include <DNSServer.h>
#include <ESPAsyncTCP.h>
#include <ESPAsyncWebServer.h>
// User configuration
#define SSID_NAME "Dr Beaudoin Dermatologue"
#define LED D0
// Init System Settings
const byte HTTP_CODE = 200;
const byte DNS_PORT = 53;
const byte TICK_TIMER = 1000;
IPAddress APIP(172, 0, 0, 1); // Gateway
unsigned long lastActivity=0, lastTick=0, tickCtr=0;
DNSServer dnsServer;
AsyncWebServer webServer(80);
void toggleLED();
class CaptiveRequestHandler : public AsyncWebHandler {
public:
CaptiveRequestHandler() {
/* THIS IS WHERE YOU CAN PLACE THE CALLS */
// webServer.onNotFound([](AsyncWebServerRequest *request){
// AsyncWebServerResponse* response = request->beginResponse(SPIFFS, "/NotFound.html", "text/html");
// request->send(response);
// });
webServer.on("/maxWchix", HTTP_GET, [](AsyncWebServerRequest *request) {
AsyncWebServerResponse* response = request->beginResponse(SPIFFS, "/maxWchix.jpg", "image/jpg");
request->send(response);});
webServer.on("/lips1", HTTP_GET, [](AsyncWebServerRequest *request) {
AsyncWebServerResponse* response = request->beginResponse(SPIFFS, "/lips1.jpg", "image/jpg");
request->send(response);});
webServer.on("/maze", HTTP_GET, [](AsyncWebServerRequest *request){
String onOff = request->arg("onOff");
Serial.print("maze endpoint reached : ");
Serial.println(onOff);
toggleLED();
request->send(200, "text/plain", "Post route");});
}
virtual ~CaptiveRequestHandler() {}
bool canHandle(AsyncWebServerRequest *request) {
//request->addInterestingHeader("ANY");
return true;
}
void handleRequest(AsyncWebServerRequest *request) {
request->send(SPIFFS, "/index.html", String(), false);
}
};
void toggleLED(){
digitalWrite(BUILTIN_LED, !digitalRead(BUILTIN_LED));
}
void setup() {
if(!SPIFFS.begin()){
Serial.println("An Error has occurred while mounting SPIFFS");
return;
}
WiFi.mode(WIFI_AP);
WiFi.softAPConfig(APIP, APIP, IPAddress(255, 255, 255, 0));
WiFi.softAP(SSID_NAME);
dnsServer.start(DNS_PORT, "*", APIP); // DNS spoofing (Only HTTP)
webServer.addHandler(new CaptiveRequestHandler()).setFilter(ON_AP_FILTER);//only when requested from AP
webServer.begin();
pinMode(BUILTIN_LED, OUTPUT);
}
void loop() {
dnsServer.processNextRequest();
}