summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--data/index.html31
-rw-r--r--data/script.js15
-rw-r--r--data/style.css40
-rw-r--r--webserver.cpp78
-rw-r--r--webserver.h26
5 files changed, 190 insertions, 0 deletions
diff --git a/data/index.html b/data/index.html
new file mode 100644
index 0000000..f3b7068
--- /dev/null
+++ b/data/index.html
@@ -0,0 +1,31 @@
1<!DOCTYPE html>
2<html lang="pl">
3 <head>
4 <meta charset="UTF-8">
5 <meta name="viewport" content="width=device-width, initial-scale=1.0">
6 <meta http-equiv="X-UA-Compatible" content="ie=edge">
7 <title>Schack v.0.0.1</title>
8 <link rel="stylesheet" href="./style.css">
9 <link rel="icon" href="./favicon.ico" type="image/x-icon">
10 </head>
11 <body>
12 <main>
13 <h1>Schack</h1>
14
15 <section id="container">
16 <div id="controll-buttons">
17 <input id="button-previous-s" type="button" value="<< Previous Section" />
18 <input id="button-previous" type="button" value="< Previous" />
19
20 <input id="button-next" type="button" value="Next >" />
21 <input id="button-next-s" type="button" value="Next Section >>" />
22 </div>
23 </section>
24
25 <footer>
26 Github: <a href="https://github.com/jdlugosz963/schack" target="_blank">jdlugosz963/schack</a>
27 </footer>
28 </main>
29 <script src="script.js"></script>
30 </body>
31</html>
diff --git a/data/script.js b/data/script.js
new file mode 100644
index 0000000..0f3101f
--- /dev/null
+++ b/data/script.js
@@ -0,0 +1,15 @@
1document.getElementById("button-previous-s").onclick = function() {
2 fetch("/previouss");
3}
4
5document.getElementById("button-previous").onclick = function() {
6 fetch("/previous");
7}
8
9document.getElementById("button-next").onclick = function() {
10 fetch("/next");
11}
12
13document.getElementById("button-next-s").onclick = function() {
14 fetch("/nexts");
15}
diff --git a/data/style.css b/data/style.css
new file mode 100644
index 0000000..52dfca6
--- /dev/null
+++ b/data/style.css
@@ -0,0 +1,40 @@
1:root {
2 --black: #333333;
3 --white: #eeeeee;
4}
5
6body {
7 background-color: var(--black);
8 color: var(--white);
9
10 font-family: monospace;
11 letter-spacing: 0.2em;
12}
13
14main {
15 padding: 2em;
16}
17
18a {
19 color: var(--white);
20}
21
22h1 {
23 font-size: 42px;
24
25 margin: 0;
26}
27
28#container {
29 padding-top: 2em;
30 padding-bottom: 2em;
31}
32
33input {
34 padding: 0.5em;
35
36 background-color: var(--white);
37 color: var(--black);
38
39 border: none;
40}
diff --git a/webserver.cpp b/webserver.cpp
new file mode 100644
index 0000000..36b5a14
--- /dev/null
+++ b/webserver.cpp
@@ -0,0 +1,78 @@
1#include "webserver.h"
2
3
4WebServer::WebServer(Controller *controller) {
5 this->controller = controller;
6 this->server = new ESP8266WebServer(80);
7
8 if(!setupST()) {
9 Serial.println("Cos sie zjebalo!!");
10 return;
11 }
12
13 if(!LittleFS.begin()){
14 Serial.println("An Error has occurred while mounting LittleFS");
15 return;
16 }
17 setupRoutes();
18}
19
20WebServer::~WebServer() {
21 delete server;
22}
23
24void WebServer::setupRoutes() {
25 server->serveStatic("/", LittleFS, "/index.html", "max-age=43200");
26 server->serveStatic("/script.js", LittleFS, "/script.js", "max-age=43200");
27 server->serveStatic("/style.css", LittleFS, "/style.css", "max-age=43200");
28
29 server->on("/next", [this]() {
30 this->server->send(200, "text/plain", "Next ok!");
31 this->controller->next();
32 });
33
34 server->on("/previous", [this]() {
35 this->server->send(200, "text/plain", "Previous ok!");
36 this->controller->previous();
37 });
38
39 server->on("/nexts", [this]() {
40 this->server->send(200, "text/plain", "Next_S ok!");
41 this->controller->nextS();
42 });
43
44 server->on("/previouss", [this]() {
45 this->server->send(200, "text/plain", "Previous_S ok!");
46 this->controller->previousS();
47 });
48
49 server->begin();
50}
51
52void WebServer::loop() {
53 server->handleClient();
54}
55
56bool WebServer::setupAP () {
57 WiFi.softAP(controller->getAPSSID(), controller->getAPPassword());
58 wifiStatus = WiFi.status();
59 return wifiStatus;
60}
61
62bool WebServer::setupST () {
63 Serial.println("Station connecting: ");
64
65 WiFi.begin("OpenWrt2");
66 while (WiFi.status() != WL_CONNECTED)
67 {
68 delay(500);
69 Serial.print(".");
70 }
71 Serial.println();
72
73 Serial.print("Connected, IP address: ");
74 Serial.println(WiFi.localIP());
75
76 wifiStatus = WiFi.status();
77 return wifiStatus;
78}
diff --git a/webserver.h b/webserver.h
new file mode 100644
index 0000000..940e5a5
--- /dev/null
+++ b/webserver.h
@@ -0,0 +1,26 @@
1//#include <ESPAsyncTCP.h>
2#include <ESP8266WebServer.h>
3#include <ESP8266WiFi.h>
4
5#include "controller.h"
6#include <LittleFS.h>
7
8
9#ifndef WEBSERVER_H
10#define WEBSERVER_H
11
12class WebServer {
13 ESP8266WebServer *server;
14 Controller *controller;
15
16 bool setupST();
17 bool setupAP();
18 void setupRoutes();
19 bool wifiStatus = false;
20public:
21 WebServer(Controller *controller);
22 ~WebServer();
23 void loop();
24};
25
26#endif