Skip to content

Commit

Permalink
Merge pull request #152 from v00g100skr/support_spiffs_update
Browse files Browse the repository at this point in the history
Технічне: Підтримка оновлення SPIFFS розділу
  • Loading branch information
v00g100skr authored Mar 2, 2024
2 parents 63fe09b + 6b534c4 commit def5c15
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 14 deletions.
12 changes: 10 additions & 2 deletions deploy/update_server/update_server.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,12 +30,12 @@

async def not_found(request: Request, exc: HTTPException):
logger.debug(f'Request time: {exc.args}')
return HTMLResponse(content=HTML_404_PAGE)
return HTMLResponse(content=HTML_404_PAGE, status_code=404)


async def server_error(request: Request, exc: HTTPException):
logger.debug(f'Request time: {exc.args}')
return HTMLResponse(content=HTML_500_PAGE)
return HTMLResponse(content=HTML_500_PAGE, status_code=500)


exception_handlers = {
Expand Down Expand Up @@ -67,6 +67,12 @@ async def update(request):
async def update_beta(request):
return FileResponse(f'{shared_beta_path}/{request.path_params["filename"]}.bin')

async def spiffs_update(request):
return FileResponse(f'{shared_path}/spiffs/{request.path_params["filename"]}.bin')

async def spiffs_update_beta(request):
return FileResponse(f'{shared_beta_path}/spiffs/{request.path_params["filename"]}.bin')


async def update_cache():
mc = Client(memcached_host, 11211)
Expand All @@ -81,7 +87,9 @@ async def update_cache():
Route('/list', list),
Route('/betalist', list_beta),
Route('/{filename}.bin', update),
Route('/spiffs/{filename}.bin', spiffs_update),
Route('/beta/{filename}.bin', update_beta),
Route('/beta/spiffs/{filename}.bin', spiffs_update_beta),
])


Expand Down
38 changes: 26 additions & 12 deletions src/firmware/firmware.ino
Original file line number Diff line number Diff line change
Expand Up @@ -835,8 +835,8 @@ void initUpdates() {
}

void showUpdateProgress(size_t progress, size_t total) {
if (total == 0) return;
String progressText = String(progress / (total / 100)) + "%";
Serial.println(progressText);
showServiceMessage(progressText, "Оновлення:");
}

Expand Down Expand Up @@ -1321,27 +1321,41 @@ void doUpdate() {
}

void downloadAndUpdateFw(String binFileName, bool isBeta) {
String firmwareUrlString = "http://" + settings.serverhost + ":" + settings.updateport;
if (isBeta) {
firmwareUrlString += "/beta";
}
firmwareUrlString += "/" + binFileName;
const char* firmwareUrl = firmwareUrlString.c_str();
Serial.println(firmwareUrl);
t_httpUpdate_return ret = httpUpdate.update(client, firmwareUrl);
char spiffUrlChar[100];
char firmwareUrlChar[100];
Serial.println("Building spiffs url...");
sprintf(spiffUrlChar, "http://%s:%d%s%s", settings.serverhost, settings.updateport, isBeta ? "/beta/spiffs/spiffs_" : "/spiffs/spiffs_", binFileName.c_str());
Serial.println("Building firmware url...");
sprintf(firmwareUrlChar, "http://%s:%d%s%s", settings.serverhost, settings.updateport, isBeta ? "/beta/" : "/", binFileName.c_str());

Serial.printf("Spiffs url: %s\n", spiffUrlChar);
t_httpUpdate_return spiffsRet = httpUpdate.updateSpiffs(client, spiffUrlChar, VERSION);
handleUpdateStatus(spiffsRet, true);

Serial.printf("Firmware url: %s\n", firmwareUrlChar);
t_httpUpdate_return fwRet = httpUpdate.update(client, firmwareUrlChar, VERSION);
handleUpdateStatus(fwRet, false);
}

void handleUpdateStatus(t_httpUpdate_return ret, bool isSpiffsUpdate) {
Serial.printf("%s update status:\n", isSpiffsUpdate ? "Spiffs" : "Firmware");
switch (ret) {
case HTTP_UPDATE_FAILED:
Serial.printf("Error Occurred. Error (%d): %s\n", httpUpdate.getLastError(), httpUpdate.getLastErrorString().c_str());
Serial.println();
break;
case HTTP_UPDATE_NO_UPDATES:
Serial.println("HTTP_UPDATE_NO_UPDATES");
break;
case HTTP_UPDATE_OK:
Serial.println("Update successfully completed. Rebooting...");
rebootDevice();
if (isSpiffsUpdate) {
Serial.println("Spiffs update successfully completed. Starting firmware update...");
} else {
Serial.println("Firmware update successfully completed. Rebooting...");
rebootDevice();
}
break;
}

}
//--Update end

Expand Down

0 comments on commit def5c15

Please sign in to comment.