Skip to content

Commit

Permalink
Merge pull request #1073 from caco3/improve-ota
Browse files Browse the repository at this point in the history
Improve ota
  • Loading branch information
jomjol authored Sep 25, 2022
2 parents f993902 + efb35b1 commit 0ffaf99
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 7 deletions.
4 changes: 2 additions & 2 deletions code/components/jomjol_fileserver_ota/server_file.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -49,8 +49,8 @@ extern "C" {

/* Max size of an individual file. Make sure this
* value is same as that set in upload_script.html */
#define MAX_FILE_SIZE (2000*1024) // 200 KB
#define MAX_FILE_SIZE_STR "2000KB"
#define MAX_FILE_SIZE (8000*1024) // 8 MB
#define MAX_FILE_SIZE_STR "8MB"


/* Scratch buffer size */
Expand Down
11 changes: 8 additions & 3 deletions code/components/jomjol_fileserver_ota/server_ota.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,11 @@ static bool ota_update_task(std::string fn)
int data_read;

FILE* f = OpenFileAndWait(fn.c_str(), "rb"); // vorher nur "r"

if (f == NULL) { // File does not exist
return false;
}

data_read = fread(ota_write_data, 1, BUFFSIZE, f);

while (data_read > 0) {
Expand Down Expand Up @@ -435,7 +440,7 @@ esp_err_t handler_ota_update(httpd_req_t *req)
int _result = stat(fn.c_str(), &file_stat);
printf("Ergebnis %d\n", _result);
if (_result == 0) {
printf("Deleting file : %s", fn.c_str());
printf("Deleting file : %s\n", fn.c_str());
/* Delete file */
unlink(fn.c_str());
}
Expand All @@ -457,11 +462,11 @@ esp_err_t handler_ota_update(httpd_req_t *req)
gpio_handler_deinit();
if (ota_update_task(fn))
{
resp_str = "Firmware Update Successfull!<br><br>You can restart now.";
resp_str = "Firmware Update Successfull! You can restart now.";
}
else
{
resp_str = "Error during Firmware Update!!!<br><br>Please check console output.";
resp_str = "Error during Firmware Update!!! Please check console output.";
}

httpd_resp_send(req, resp_str, strlen(resp_str));
Expand Down
11 changes: 10 additions & 1 deletion code/components/jomjol_helper/Helper.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -88,8 +88,17 @@ void memCopyGen(uint8_t* _source, uint8_t* _target, int _size)

FILE* OpenFileAndWait(const char* nm, const char* _mode, int _waitsec)
{
FILE *pfile;

printf("open file %s in mode %s\n", nm, _mode);
FILE *pfile = fopen(nm, _mode);

if ((pfile = fopen(nm, _mode)) != NULL) {
printf("File %s successfully opened\n", nm);
}
else {
printf("Error: file %s does not exist!\n", nm);
return NULL;
}

/*
if (pfile == NULL)
Expand Down
2 changes: 1 addition & 1 deletion sd-card/html/ota_page.html
Original file line number Diff line number Diff line change
Expand Up @@ -160,7 +160,7 @@ <h2>Reboot</h2>


/* Max size of an individual file. Make sure this
* value is same as that set in file_server.c */
* value is same as that set in server_file.c */
var MAX_FILE_SIZE = 8000*1024;
var MAX_FILE_SIZE_STR = "8MB";

Expand Down

0 comments on commit 0ffaf99

Please sign in to comment.