-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathSPIFFS.ino
59 lines (55 loc) · 1.87 KB
/
SPIFFS.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
void initSpiffs() {
if (!SPIFFS.begin()) {
while (1) {
BlinkLed(1000, 100);
}
}
}
void readSettings() {
if (SPIFFS.exists("/settings.conf")) {
File configFile = SPIFFS.open("/settings.conf", "r");
while (configFile.available()) {
String line = configFile.readStringUntil('\n');
if (line.startsWith("ssid=")) STA_ssid = line.substring(5);
else if (line.startsWith("password=")) STA_password = line.substring(9);
else if (line.startsWith("ipAddress=")) IP_address = line.substring(10);
else if (line.startsWith("subnetMask=")) SubnetMask = line.substring(11);
else if (line.startsWith("gateway=")) Gateway = line.substring(8);
else if (line.startsWith("protocol=")) protocol = line.substring(9);
}
configFile.close();
}
}
void updateSetting(const String& key, const String& value) {
if (SPIFFS.exists("/settings.conf")) {
String updatedSettings = "";
File configFile = SPIFFS.open("/settings.conf", "r");
while (configFile.available()) {
String line = configFile.readStringUntil('\n');
if (line.startsWith(key)) {
updatedSettings += key + "=" + value + "\n";
} else {
updatedSettings += line + "\n";
}
}
configFile.close();
configFile = SPIFFS.open("/settings.conf", "w");
configFile.print(updatedSettings);
configFile.close();
}
}
void changeWifiSettings(String ssid, String password, String ipAddress, String subnetMask, String gateway) {
updateSetting("ssid", ssid);
updateSetting("password", password);
updateSetting("ipAddress", ipAddress);
updateSetting("subnetMask", subnetMask);
updateSetting("gateway", gateway);
ESP.restart();
}
void changeCommunicationProtocol(String communicationProtocol) {
updateSetting("protocol", communicationProtocol);
protocol = communicationProtocol;
if (KLineStatus) {
KLineStatus = false;
}
}