-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathconfigBoot.ino
69 lines (57 loc) · 1.49 KB
/
configBoot.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
58
59
60
61
62
63
64
65
66
67
68
69
// Serve the HTML page
void handleRoot() {
File file = LittleFS.open("/index.html", "r");
if (file) {
server.streamFile(file, "text/html");
file.close();
} else {
server.send(404, "text/plain", "File not found");
}
}
// Serve the settings JSON file
void handleSettings() {
String json;
serializeJson(settings, json);
server.send(200, "application/json", json);
}
// Handle POST request to update the settings
void handleSubmit() {
if (server.hasArg("plain")) {
String body = server.arg("plain");
deserializeJson(settings, body);
// Save updated settings to LittleFS
saveSettings();
String json;
serializeJson(settings, json);
server.send(200, "application/json", json);
} else {
server.send(400, "text/plain", "No data received");
}
}
// Save settings to LittleFS
void saveSettings() {
File file = LittleFS.open("/config.json", "w");
if (file) {
serializeJson(settings, file);
file.close();
Serial.println("Config saved");
} else {
Serial.println("Failed to open config.json for writing");
}
}
void configSetup() {
WiFi.mode(WIFI_AP);
delay(250);
// Start the Wi-Fi in Access Point mode
WiFi.softAP(ssid, password);
Serial.println("startar SSID");
// Define server routes
server.on("/", HTTP_GET, handleRoot);
server.on("/settings.json", HTTP_GET, handleSettings);
server.on("/submit", HTTP_POST, handleSubmit);
// Start the server
server.begin();
}
void configLoop() {
server.handleClient();
}