-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathwebserver.c
67 lines (56 loc) · 1.28 KB
/
webserver.c
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
static const char PROGMEM rootPage[] = R"rawliteral(
<h2>NodeLife</h2>
<h3>Conway's Life on an ESP8266 and SSD1106</h3>
Commands: </br>
<ul>
<li><a href="/reset">reset</a></li>
<li><a href="/start">start</a></li>
<li><a href="/stop">stop</a></li>
</ul>
)rawliteral";
//void handleRoot() {
// Serial.println("received HTTP request");
// server.send(200, "text/html", "<h1>NodeLife</h1>\
// \
// Commands:</br>\
// reset, start, stop, ....\
// ");
//}
void handleRoot() {
Serial.println("received HTTP request");
server.send(200, "text/html", rootPage);
}
void handleReset() {
_resetCA = 1;
_runCA = 1;
handleRoot();
}
void handleStop() {
_runCA = 0;
togglePaused();
handleRoot();
}
void handleStart() {
_runCA = 1;
togglePaused();
handleRoot();
}
void handleConfigure() {
for (int i = 0; i < server.args(); i++) {
// p = probability of living cell in random setup
if (server.argName(i) == "p") {
p = server.arg(i).toInt();
}
}
handleRoot();
}
void initWebServer() {
server.on("/", handleRoot);
server.on("/reset", handleReset);
server.on("/restart", handleReset);
server.on("/stop", handleStop);
server.on("/start", handleStart);
server.on("/configure", handleConfigure);
server.begin();
Serial.println("HTTP server started");
}