mirror of
https://github.com/rstrouse/ESPSomfy-RTS.git
synced 2025-12-13 02:52:11 +01:00
Add FS recovery for failed FS updates.
This commit is contained in:
parent
2bb23e6d3e
commit
a3cb1d63fe
6 changed files with 41 additions and 4 deletions
24
GitOTA.cpp
24
GitOTA.cpp
|
|
@ -372,20 +372,38 @@ bool GitUpdater::beginUpdate(const char *version) {
|
|||
somfy.commit();
|
||||
strcpy(this->currentFile, "SomfyController.littlefs.bin");
|
||||
this->partition = U_SPIFFS;
|
||||
this->lockFS = true;
|
||||
this->error = this->downloadFile();
|
||||
this->lockFS = false;
|
||||
if(this->error == 0) {
|
||||
settings.fwVersion.parse(version);
|
||||
delay(100);
|
||||
Serial.println("Committing Configuration...");
|
||||
somfy.commit();
|
||||
rebootDelay.reboot = true;
|
||||
rebootDelay.rebootTime = millis() + 500;
|
||||
}
|
||||
rebootDelay.reboot = true;
|
||||
rebootDelay.rebootTime = millis() + 500;
|
||||
}
|
||||
this->status = GIT_UPDATE_COMPLETE;
|
||||
this->emitUpdateCheck();
|
||||
return true;
|
||||
}
|
||||
bool GitUpdater::recoverFilesystem() {
|
||||
sprintf(this->baseUrl, "https://github.com/rstrouse/ESPSomfy-RTS/releases/download/%s/", settings.fwVersion.name);
|
||||
strcpy(this->currentFile, "SomfyController.littlefs.bin");
|
||||
this->partition = U_SPIFFS;
|
||||
this->lockFS = true;
|
||||
this->error = this->downloadFile();
|
||||
this->lockFS = false;
|
||||
if(this->error == 0) {
|
||||
delay(100);
|
||||
Serial.println("Committing Configuration...");
|
||||
somfy.commit();
|
||||
}
|
||||
rebootDelay.reboot = true;
|
||||
rebootDelay.rebootTime = millis() + 500;
|
||||
return true;
|
||||
}
|
||||
bool GitUpdater::endUpdate() { return true; }
|
||||
int8_t GitUpdater::downloadFile() {
|
||||
WiFiClientSecure *client = new WiFiClientSecure;
|
||||
|
|
@ -457,7 +475,7 @@ int8_t GitUpdater::downloadFile() {
|
|||
}
|
||||
else {
|
||||
timeouts++;
|
||||
if(timeouts >= 300) {
|
||||
if(timeouts >= 500) {
|
||||
Update.abort();
|
||||
https.end();
|
||||
free(buff);
|
||||
|
|
|
|||
2
GitOTA.h
2
GitOTA.h
|
|
@ -37,6 +37,7 @@ class GitRepo {
|
|||
};
|
||||
class GitUpdater {
|
||||
public:
|
||||
bool lockFS = false;
|
||||
uint8_t status = 0;
|
||||
uint32_t lastCheck = 0;
|
||||
bool updateAvailable = false;
|
||||
|
|
@ -55,6 +56,7 @@ class GitUpdater {
|
|||
void setCurrentRelease(GitRepo &repo);
|
||||
void loop();
|
||||
void toJSON(JsonObject &obj);
|
||||
bool recoverFilesystem();
|
||||
int checkInternet();
|
||||
void emitUpdateCheck(uint8_t num=255);
|
||||
void emitDownloadProgress(size_t total, size_t loaded, const char *evt = "updateProgress");
|
||||
|
|
|
|||
|
|
@ -7,12 +7,14 @@
|
|||
#include "Sockets.h"
|
||||
#include "MQTT.h"
|
||||
#include "ConfigFile.h"
|
||||
#include "GitOTA.h"
|
||||
|
||||
extern Preferences pref;
|
||||
extern SomfyShadeController somfy;
|
||||
extern SocketEmitter sockEmit;
|
||||
extern ConfigSettings settings;
|
||||
extern MQTTClass mqtt;
|
||||
extern GitUpdater git;
|
||||
|
||||
|
||||
uint8_t rxmode = 0; // Indicates whether the radio is in receive mode. Just to ensure there isn't more than one interrupt hooked.
|
||||
|
|
@ -545,6 +547,7 @@ bool SomfyShadeController::begin() {
|
|||
return true;
|
||||
}
|
||||
void SomfyShadeController::commit() {
|
||||
if(git.lockFS) return;
|
||||
ShadeConfigFile file;
|
||||
file.begin();
|
||||
file.save(this);
|
||||
|
|
@ -553,6 +556,7 @@ void SomfyShadeController::commit() {
|
|||
this->lastCommit = millis();
|
||||
}
|
||||
void SomfyShadeController::writeBackup() {
|
||||
if(git.lockFS) return;
|
||||
ShadeConfigFile file;
|
||||
file.begin("/controller.backup", false);
|
||||
file.backup(this);
|
||||
|
|
|
|||
Binary file not shown.
Binary file not shown.
15
Web.cpp
15
Web.cpp
|
|
@ -203,6 +203,10 @@ void Web::handleLogin(WebServer &server) {
|
|||
return;
|
||||
}
|
||||
void Web::handleStreamFile(WebServer &server, const char *filename, const char *encoding) {
|
||||
if(git.lockFS) {
|
||||
server.send(500, _encoding_json, F("{\"status\":\"ERROR\",\"desc\":\"Filesystem update in progress\"}"));
|
||||
return;
|
||||
}
|
||||
webServer.sendCORSHeaders(server);
|
||||
if(server.method() == HTTP_OPTIONS) { server.send(200, "OK"); return; }
|
||||
|
||||
|
|
@ -1883,6 +1887,10 @@ void Web::begin() {
|
|||
}
|
||||
});
|
||||
server.on("/updateShadeConfig", HTTP_POST, []() {
|
||||
if(git.lockFS) {
|
||||
server.send(500, _encoding_json, F("{\"status\":\"ERROR\",\"desc\":\"Filesystem update in progress\"}"));
|
||||
return;
|
||||
}
|
||||
webServer.sendCORSHeaders(server);
|
||||
if(server.method() == HTTP_OPTIONS) { server.send(200, "OK"); return; }
|
||||
server.sendHeader("Connection", "close");
|
||||
|
|
@ -2438,7 +2446,12 @@ void Web::begin() {
|
|||
serializeJson(doc, g_content);
|
||||
server.send(200, _encoding_json, g_content);
|
||||
});
|
||||
|
||||
server.on("/recoverFilesystem", [] () {
|
||||
if(server.method() == HTTP_OPTIONS) { server.send(200, "OK"); return; }
|
||||
webServer.sendCORSHeaders(server);
|
||||
git.recoverFilesystem();
|
||||
server.send(200, "application/json", "{\"status\":\"OK\",\"desc\":\"Recovering filesystem from github please wait!!!\"}");
|
||||
});
|
||||
server.begin();
|
||||
apiServer.begin();
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue