-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathserverhandler.ino
57 lines (54 loc) · 2.49 KB
/
serverhandler.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
/********* Add Listeners For Server HTTP Requests ***********/
void addServerHandlers()
{
/*************** Redirect to correct domain *****************/
server.on("/", HTTP_GET, [](AsyncWebServerRequest * request) {
request->redirect("http://meter.local/view");
});
server.on("/view", HTTP_GET, [](AsyncWebServerRequest * request) {
AsyncWebServerResponse *response = request->beginResponse(SPIFFS, "/index.html.gz", "text/html");
response->addHeader("Content-Encoding", "gzip");
request->send(response);
});
/************************************************************/
/*************** GET requests to send data ******************/
server.on("/readings", HTTP_GET, [](AsyncWebServerRequest * request) {
request->send(200, "text/plain", data_string.c_str());
});
server.on("/check", HTTP_GET, [](AsyncWebServerRequest * request) {
request->send(200, "text/plain", "ACK");
});
/************************************************************/
/********* GET requests to set INA219 Calibration ***********/
server.on("/setcalc", HTTP_GET, [](AsyncWebServerRequest * request) {
request->send(204);
INA219.setCalibration_32V_2A();
});
server.on("/setcalb", HTTP_GET, [](AsyncWebServerRequest * request) {
request->send(204);
INA219.setCalibration_32V_1A();
});
server.on("/setcala", HTTP_GET, [](AsyncWebServerRequest * request) {
request->send(204);
INA219.setCalibration_16V_400mA();
});
/************************************************************/
/********* GET requests to send HTML from SPIFFS ***********/
server.on("/index.html", HTTP_GET, [](AsyncWebServerRequest * request) {
AsyncWebServerResponse *response = request->beginResponse(SPIFFS, "/index.html.gz", "text/html");
response->addHeader("Content-Encoding", "gzip");
request->send(response);
});
server.on("/manifest.json", HTTP_GET, [](AsyncWebServerRequest * request) {
AsyncWebServerResponse *response = request->beginResponse(SPIFFS, "/manifest.json", "application/json");
response->addHeader("Content-Encoding", "gzip");
request->send(response);
});
server.on("/meter-large.png", HTTP_GET, [](AsyncWebServerRequest * request) {
AsyncWebServerResponse *response = request->beginResponse(SPIFFS, "/meter-large.png", "image/png");
response->addHeader("Content-Encoding", "gzip");
request->send(response);
});
/************************************************************/
}
/************************************************************/