-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathwebserver.cpp
78 lines (61 loc) · 1.73 KB
/
webserver.cpp
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
#include "webserver.h"
WebServer::WebServer(Controller *controller) {
this->controller = controller;
this->server = new ESP8266WebServer(80);
if(!setupST()) {
Serial.println("Cos sie zjebalo!!");
return;
}
if(!LittleFS.begin()){
Serial.println("An Error has occurred while mounting LittleFS");
return;
}
setupRoutes();
}
WebServer::~WebServer() {
delete server;
}
void WebServer::setupRoutes() {
server->serveStatic("/", LittleFS, "/index.html", "max-age=43200");
server->serveStatic("/script.js", LittleFS, "/script.js", "max-age=43200");
server->serveStatic("/style.css", LittleFS, "/style.css", "max-age=43200");
server->on("/next", [this]() {
this->server->send(200, "text/plain", "Next ok!");
this->controller->next();
});
server->on("/previous", [this]() {
this->server->send(200, "text/plain", "Previous ok!");
this->controller->previous();
});
server->on("/nexts", [this]() {
this->server->send(200, "text/plain", "Next_S ok!");
this->controller->nextS();
});
server->on("/previouss", [this]() {
this->server->send(200, "text/plain", "Previous_S ok!");
this->controller->previousS();
});
server->begin();
}
void WebServer::loop() {
server->handleClient();
}
bool WebServer::setupAP () {
WiFi.softAP(controller->getAPSSID(), controller->getAPPassword());
wifiStatus = WiFi.status();
return wifiStatus;
}
bool WebServer::setupST () {
Serial.println("Station connecting: ");
WiFi.begin("OpenWrt2");
while (WiFi.status() != WL_CONNECTED)
{
delay(500);
Serial.print(".");
}
Serial.println();
Serial.print("Connected, IP address: ");
Serial.println(WiFi.localIP());
wifiStatus = WiFi.status();
return wifiStatus;
}