-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathmain.cpp
52 lines (45 loc) · 1.43 KB
/
main.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
#include <Arduino.h>
#include <ESPAsyncWebServer.h>
#include <WiFi.h>
#include "base64.h"
#include "base_html.h"
String image_new = "";
String image_old = "";
String lidar_new = "";
String lidar_old = "";
AsyncWebServer server(80);
void setup() {
Serial.begin(350000);
WiFi.softAP(DEVICE_NAME.c_str(), "123456789");
server.on("/", HTTP_GET, [&](AsyncWebServerRequest *request) {
request->send(200, "text/html", BASE_HTML);
});
server.on("/pic", HTTP_GET, [&](AsyncWebServerRequest *request) {
request->send(200, "text/html", image_old);
});
server.on("/lidar", HTTP_GET, [&](AsyncWebServerRequest *request) {
request->send(200, "text/html", lidar_old);
});
server.on("/scenario", HTTP_GET, [&](AsyncWebServerRequest *request) {
auto count = request->params();
for (size_t i = 0; i < count; i++) {
auto param = request->getParam(i);
if (param->name() == "index") {
auto value = param->value();
Serial.write(value.toInt());
request->redirect("/?index=" + value);
return;
}
}
request->redirect("/");
});
server.begin();
}
void loop() {
if (Serial.available()) {
image_new = Serial.readStringUntil('*');
image_old = std::move(image_new);
lidar_new = Serial.readStringUntil('*');
lidar_old = std::move(lidar_new);
}
}