-
Notifications
You must be signed in to change notification settings - Fork 33
Expand file tree
/
Copy pathhttp_server.cpp
More file actions
54 lines (43 loc) · 1.2 KB
/
Copy pathhttp_server.cpp
File metadata and controls
54 lines (43 loc) · 1.2 KB
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
#include "http/http_server.h"
#include <Arduino.h>
#include "http/routes.h"
#include "http/server_context.h"
#include "network/wifi_connect.h"
#include "serial_log.h"
void startHttpServer() {
if (!wifiConnected() && !wifiProvisioningMode()) {
serialLogPrintln("HTTP: skipped (no wifi)");
return;
}
WebServer& server = httpServer();
refreshMdnsHostname();
static const char* kCollectHeaders[] = {"Authorization"};
server.collectHeaders(kCollectHeaders, 1);
registerHttpRoutes();
server.begin();
if (wifiProvisioningMode()) {
serialLogPrint("HTTP setup: http://");
serialLogPrint(wifiApIpText());
serialLogPrintln("/config");
return;
}
serialLogPrint("HTTP: http://");
serialLogPrint(wifiIpText());
serialLogPrintln("/");
serialLogPrint("HTTP: http://");
serialLogPrint(httpMdnsHostname());
serialLogPrintln("/");
serialLogPrint("HTTP: http://");
serialLogPrint(wifiIpText());
serialLogPrintln("/health");
serialLogPrint("HTTP: http://");
serialLogPrint(httpMdnsHostname());
serialLogPrintln("/health");
}
void pollHttpServer() {
if (!wifiConnected() && !wifiProvisioningMode()) {
delay(10);
return;
}
httpServer().handleClient();
}