-
Notifications
You must be signed in to change notification settings - Fork 24
/
Upgrade.ino
78 lines (75 loc) · 2.73 KB
/
Upgrade.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
70
71
72
73
74
75
76
77
78
void initUpgrade() {
// Добавляем функцию Update для перезаписи прошивки по Wi-Fi при 1М(256K SPIFFS) и выше
httpUpdater.setup(&HTTP);
HTTP.on("/upgrade", webUpgrade); // запустить обнавление
modulesReg("upgrade");
}
// ----------------------- Обновление с сайта
void webUpgrade() {
String refresh = "<html><head><meta http-equiv=\"refresh\" content=\"40;/\">Update module...</head></html>";
HTTP.send(200, "text/html", refresh);
String spiffsData = HTTP.arg("spiffs");
if (spiffsData != "") {
SPIFFS.format();
spiffsData = spiffsData.substring(spiffsData.lastIndexOf("/") + 1); // выделяем имя файла
ESPhttpUpdate.rebootOnUpdate(false);
t_httpUpdate_return ret = ESPhttpUpdate.updateSpiffs(HTTP.arg("spiffs"));
switch(ret) {
case HTTP_UPDATE_FAILED:
configSetup = jsonWrite(configSetup, "spiffsData", "HTTP_UPDATE_FAILED");
statistics();
break;
case HTTP_UPDATE_NO_UPDATES:
configSetup = jsonWrite(configSetup, "spiffsData", "HTTP_UPDATE_NO_UPDATES");
statistics();
break;
case HTTP_UPDATE_OK:
configSetup = jsonWrite(configSetup, "spiffsData", "HTTP_UPDATE_OK");
statistics();
break;
}
writeFile("timer.save.json", jsonTimer);
configSetup = jsonWrite(configSetup, "spiffsData", spiffsData);
saveConfigSetup ();
}
String buildData = HTTP.arg("build");
if (buildData != "") {
buildData = buildData.substring(buildData.lastIndexOf("/") + 1); // выделяем имя файла
configSetup = jsonWrite(configSetup, "buildData", buildData);
saveConfigSetup ();
ESPhttpUpdate.rebootOnUpdate(true);
t_httpUpdate_return jet = ESPhttpUpdate.update(HTTP.arg("build"));
}
}
void savePrevious(){
moveSetup ("lang");
moveSetup ("setIndex");
moveSetup ("SSDP");
moveSetup ("space");
moveSetup ("ssid");
moveSetup ("ssidPass");
moveSetupInt ("wifiConnect");
moveSetupInt ("wifiBlink");
moveSetup ("checkboxIP");
moveSetup ("ip");
moveSetup ("subnet");
moveSetup ("getway");
moveSetup ("dns");
moveSetupInt ("timeZone");
moveSetup ("ssidAP");
moveSetup ("ssidApPass");
moveSetup ("configs");
moveSetup ("ddns");
moveSetup ("ddnsName");
moveSetupInt ("ddnsPort");
moveSetup ("mqttServer");
moveSetupInt ("mqttPort");
moveSetup ("mqttUser");
moveSetup ("mqttPass");
}
void moveSetup (String Name){
configSetup = jsonWrite(previousSetup, Name, jsonRead(previousSetup, Name));
}
void moveSetupInt (String Name){
configSetup = jsonWrite(previousSetup, Name, jsonReadtoInt(previousSetup, Name));
}