-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.cpp
80 lines (67 loc) · 1.8 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
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
/*
* main.cpp - example use WiFiManager for esp32.
*
* aromprog 2023
*
*/
#include <Arduino.h>
#include <WebServer.h>
#include "WiFiManager.h"
WebServer server(80);
const char demo_page_html[] = R"rawliteral(<html>
<head>
<meta http-equiv='refresh' content='2'/>
<title>ESP32 Demo</title>
<style>body {font-size:20px;}</style>
</head>
<body>
<h1>Hello from ESP32</h1>
<p>Uptime: %02d:%02d:%02d</p>
<p>Hall Sensor: %d</p>
</body>
</html>)rawliteral";
void handleRoot() {
char temp[sizeof(demo_page_html) + 50];
int sec = millis() / 1000;
int min = sec / 60;
int hr = min / 60;
snprintf(temp, sizeof(temp), demo_page_html, hr, min % 60, sec % 60, hallRead());
server.send(200, "text/html", temp);
}
void OnFirstConnect() {
server.on("/", handleRoot);
server.onNotFound([]() {
server.send(404, "text/plain", "File Not Found");
});
server.begin();
Serial.println("Demo HTTP server started");
}
void setup() {
Serial.begin(115200);
Serial.setDebugOutput(false);
WiFiManager.setStaticIP();
WiFiManager.configAP("my_ap_ssid", "123456789");
WiFiManager.attachOnFirstConnect(OnFirstConnect);
WiFiManager.start("esp_hostname");
}
void loop() {
delay(1); // allow the cpu to switch to other tasks
server.handleClient();
if (Serial.available()) {
switch (Serial.read()) {
case '-':
WiFiManager.cleanWiFiAuthData();
Serial.println("cleanWiFiAuthData");
break;
case 'i':
Serial.printf("CPU freq=%lu MHz\n", ESP.getCpuFreqMHz());
WiFiManager.debugMemory("debugMemory");
break;
case 'r':
ESP.restart();
break;
default:
break;
}
}
}