Update max_uri_handler, improve OTA debugging

This commit is contained in:
jomjol
2022-11-05 08:08:00 +01:00
parent 1fc0b41fca
commit 8c6805ec7c
5 changed files with 55 additions and 49 deletions

View File

@@ -639,10 +639,8 @@ static esp_err_t upload_post_handler(httpd_req_t *req)
int start_fn = strlen(((struct file_server_data *)req->user_ctx)->base_path); int start_fn = strlen(((struct file_server_data *)req->user_ctx)->base_path);
ESP_LOGD(TAG, "Directory: %s, start_fn: %d, found: %d", directory.c_str(), start_fn, found); ESP_LOGD(TAG, "Directory: %s, start_fn: %d, found: %d", directory.c_str(), start_fn, found);
directory = directory.substr(start_fn, found - start_fn + 1); directory = directory.substr(start_fn, found - start_fn + 1);
ESP_LOGD(TAG, "Directory danach 1: %s", directory.c_str());
directory = "/fileserver" + directory; directory = "/fileserver" + directory;
ESP_LOGD(TAG, "Directory danach 2: %s", directory.c_str()); // ESP_LOGD(TAG, "Directory danach 2: %s", directory.c_str());
/* Redirect onto root to see the updated file list */ /* Redirect onto root to see the updated file list */
httpd_resp_set_status(req, "303 See Other"); httpd_resp_set_status(req, "303 See Other");
@@ -761,8 +759,6 @@ static esp_err_t delete_post_handler(httpd_req_t *req)
int start_fn = strlen(((struct file_server_data *)req->user_ctx)->base_path); int start_fn = strlen(((struct file_server_data *)req->user_ctx)->base_path);
ESP_LOGD(TAG, "Directory: %s, start_fn: %d, found: %d", directory.c_str(), start_fn, found); ESP_LOGD(TAG, "Directory: %s, start_fn: %d, found: %d", directory.c_str(), start_fn, found);
directory = directory.substr(start_fn, found - start_fn + 1); directory = directory.substr(start_fn, found - start_fn + 1);
ESP_LOGD(TAG, "Directory danach 3: %s", directory.c_str());
directory = "/fileserver" + directory; directory = "/fileserver" + directory;
ESP_LOGD(TAG, "Directory danach 4: %s", directory.c_str()); ESP_LOGD(TAG, "Directory danach 4: %s", directory.c_str());
} }
@@ -820,9 +816,9 @@ std::string unzip_new(std::string _in_zip_file, std::string _target_zip, std::st
ESP_LOGD(TAG, "miniz.c version: %s", MZ_VERSION); ESP_LOGD(TAG, "miniz.c version: %s", MZ_VERSION);
ESP_LOGD(TAG, "Zipfile: %s", _in_zip_file.c_str()); ESP_LOGD(TAG, "Zipfile: %s", _in_zip_file.c_str());
ESP_LOGD(TAG, "Target Dir ZIP: %s", _target_zip.c_str()); // ESP_LOGD(TAG, "Target Dir ZIP: %s", _target_zip.c_str());
ESP_LOGD(TAG, "Target Dir BIN: %s", _target_bin.c_str()); // ESP_LOGD(TAG, "Target Dir BIN: %s", _target_bin.c_str());
ESP_LOGD(TAG, "Target Dir main: %s", _main.c_str()); // ESP_LOGD(TAG, "Target Dir main: %s", _main.c_str());
// Now try to open the archive. // Now try to open the archive.
memset(&zip_archive, 0, sizeof(zip_archive)); memset(&zip_archive, 0, sizeof(zip_archive));
@@ -892,17 +888,32 @@ std::string unzip_new(std::string _in_zip_file, std::string _target_zip, std::st
// extrahieren in zwischendatei // extrahieren in zwischendatei
DeleteFile(filename_zw); DeleteFile(filename_zw);
FILE* fpTargetFile = OpenFileAndWait(filename_zw.c_str(), "wb"); FILE* fpTargetFile = OpenFileAndWait(filename_zw.c_str(), "wb");
fwrite(p, 1, (uint)uncomp_size, fpTargetFile); uint writtenbytes = fwrite(p, 1, (uint)uncomp_size, fpTargetFile);
fclose(fpTargetFile); fclose(fpTargetFile);
bool isokay = true;
DeleteFile(zw); if (writtenbytes == (uint)uncomp_size)
RenameFile(filename_zw, zw); {
DeleteFile(filename_zw); isokay = true;
}
else
{
isokay = false;
ESP_LOGE(TAG, "ERROR in writting extracted file (function fwrite) extracted file \"%s\", size %u", archive_filename, (uint)uncomp_size);
}
ESP_LOGD(TAG, "Successfully extracted file \"%s\", size %u", archive_filename, (uint)uncomp_size);
// ESP_LOGD(TAG, "File data: \"%s\"", (const char*)p);
// We're done. isokay = isokay && RenameFile(filename_zw, zw);
isokay = isokay && DeleteFile(filename_zw);
if (isokay)
ESP_LOGD(TAG, "Successfully extracted file \"%s\", size %u", archive_filename, (uint)uncomp_size);
else
{
ESP_LOGE(TAG, "ERROR in extracting file \"%s\", size %u", archive_filename, (uint)uncomp_size);
ret = "ERROR";
}
mz_free(p); mz_free(p);
} }
} }

View File

@@ -165,32 +165,20 @@ void memCopyGen(uint8_t* _source, uint8_t* _target, int _size)
FILE* OpenFileAndWait(const char* nm, const char* _mode, int _waitsec) FILE* OpenFileAndWait(const char* nm, const char* _mode, int _waitsec, bool silent)
{ {
FILE *pfile; FILE *pfile;
ESP_LOGD(TAG, "open file %s in mode %s", nm, _mode); ESP_LOGD(TAG, "open file %s in mode %s", nm, _mode);
if ((pfile = fopen(nm, _mode)) != NULL) { if ((pfile = fopen(nm, _mode)) != NULL) {
ESP_LOGD(TAG, "File %s successfully opened", nm); if (!silent) ESP_LOGD(TAG, "File %s successfully opened", nm);
} }
else { else {
ESP_LOGD(TAG, "Error: file %s does not exist!", nm); if (!silent) ESP_LOGD(TAG, "Error: file %s does not exist!", nm);
return NULL; return NULL;
} }
/*
if (pfile == NULL)
{
TickType_t xDelay;
xDelay = _waitsec * 1000 / portTICK_PERIOD_MS;
std::string zw = "File is locked: " + std::string(nm) + " - wait for " + std::to_string(_waitsec) + " seconds";
LogFile.WriteToFile(ESP_LOG_INFO, zw);
vTaskDelay( xDelay );
pfile = fopen(nm, _mode);
}
*/
return pfile; return pfile;
} }
@@ -231,11 +219,15 @@ void FindReplace(std::string& line, std::string& oldString, std::string& newStri
} }
} }
void MakeDir(std::string _what) bool MakeDir(std::string _what)
{ {
int mk_ret = mkdir(_what.c_str(), 0775); int mk_ret = mkdir(_what.c_str(), 0775);
if (mk_ret) if (mk_ret)
ESP_LOGD(TAG, "error with mkdir %s ret %d", _what.c_str(), mk_ret); {
ESP_LOGD(TAG, "error with mkdir %s ret %d", _what.c_str(), mk_ret);
return false;
}
return true;
} }
@@ -302,7 +294,7 @@ size_t findDelimiterPos(string input, string delimiter)
} }
void RenameFile(string from, string to) bool RenameFile(string from, string to)
{ {
// ESP_LOGI(logTag, "Deleting file : %s", fn.c_str()); // ESP_LOGI(logTag, "Deleting file : %s", fn.c_str());
/* Delete file */ /* Delete file */
@@ -310,15 +302,16 @@ void RenameFile(string from, string to)
if (!fpSourceFile) // Sourcefile existiert nicht sonst gibt es einen Fehler beim Kopierversuch! if (!fpSourceFile) // Sourcefile existiert nicht sonst gibt es einen Fehler beim Kopierversuch!
{ {
ESP_LOGD(TAG, "DeleteFile: File %s existiert nicht!", from.c_str()); ESP_LOGD(TAG, "DeleteFile: File %s existiert nicht!", from.c_str());
return; return false;
} }
fclose(fpSourceFile); fclose(fpSourceFile);
rename(from.c_str(), to.c_str()); rename(from.c_str(), to.c_str());
return true;
} }
void DeleteFile(string fn) bool DeleteFile(string fn)
{ {
// ESP_LOGI(logTag, "Deleting file : %s", fn.c_str()); // ESP_LOGI(logTag, "Deleting file : %s", fn.c_str());
/* Delete file */ /* Delete file */
@@ -326,15 +319,16 @@ void DeleteFile(string fn)
if (!fpSourceFile) // Sourcefile existiert nicht sonst gibt es einen Fehler beim Kopierversuch! if (!fpSourceFile) // Sourcefile existiert nicht sonst gibt es einen Fehler beim Kopierversuch!
{ {
ESP_LOGD(TAG, "DeleteFile: File %s existiert nicht!", fn.c_str()); ESP_LOGD(TAG, "DeleteFile: File %s existiert nicht!", fn.c_str());
return; return false;
} }
fclose(fpSourceFile); fclose(fpSourceFile);
unlink(fn.c_str()); unlink(fn.c_str());
return true;
} }
void CopyFile(string input, string output) bool CopyFile(string input, string output)
{ {
input = FormatFileName(input); input = FormatFileName(input);
output = FormatFileName(output); output = FormatFileName(output);
@@ -342,7 +336,7 @@ void CopyFile(string input, string output)
if (toUpper(input).compare("/SDCARD/WLAN.INI") == 0) if (toUpper(input).compare("/SDCARD/WLAN.INI") == 0)
{ {
ESP_LOGD(TAG, "wlan.ini kann nicht kopiert werden!"); ESP_LOGD(TAG, "wlan.ini kann nicht kopiert werden!");
return; return false;
} }
char cTemp; char cTemp;
@@ -350,7 +344,7 @@ void CopyFile(string input, string output)
if (!fpSourceFile) // Sourcefile existiert nicht sonst gibt es einen Fehler beim Kopierversuch! if (!fpSourceFile) // Sourcefile existiert nicht sonst gibt es einen Fehler beim Kopierversuch!
{ {
ESP_LOGD(TAG, "File %s existiert nicht!", input.c_str()); ESP_LOGD(TAG, "File %s existiert nicht!", input.c_str());
return; return false;
} }
FILE* fpTargetFile = OpenFileAndWait(output.c_str(), "wb"); FILE* fpTargetFile = OpenFileAndWait(output.c_str(), "wb");
@@ -368,6 +362,7 @@ void CopyFile(string input, string output)
fclose(fpSourceFile); fclose(fpSourceFile);
fclose(fpTargetFile); fclose(fpTargetFile);
ESP_LOGD(TAG, "File copied: %s to %s", input.c_str(), output.c_str()); ESP_LOGD(TAG, "File copied: %s to %s", input.c_str(), output.c_str());
return true;
} }
string getFileFullFileName(string filename) string getFileFullFileName(string filename)

View File

@@ -9,16 +9,16 @@ using namespace std;
std::string FormatFileName(std::string input); std::string FormatFileName(std::string input);
void FindReplace(std::string& line, std::string& oldString, std::string& newString); void FindReplace(std::string& line, std::string& oldString, std::string& newString);
void CopyFile(string input, string output); bool CopyFile(string input, string output);
void DeleteFile(string fn); bool DeleteFile(string fn);
void RenameFile(string from, string to); bool RenameFile(string from, string to);
void MakeDir(std::string _what); bool MakeDir(std::string _what);
string RundeOutput(double _in, int _anzNachkomma); string RundeOutput(double _in, int _anzNachkomma);
FILE* OpenFileAndWait(const char* nm, const char* _mode, int _waitsec = 1); FILE* OpenFileAndWait(const char* nm, const char* _mode, int _waitsec = 1, bool silent = true);
size_t findDelimiterPos(string input, string delimiter); size_t findDelimiterPos(string input, string delimiter);
//string trim(string istring); //string trim(string istring);

View File

@@ -195,7 +195,7 @@ extern "C" void app_main(void)
ESP_LOGD(TAGMAIN, "No SSID and PASSWORD set!!!"); ESP_LOGD(TAGMAIN, "No SSID and PASSWORD set!!!");
if (hostname != NULL) if (hostname != NULL)
ESP_LOGD(TAGMAIN, "Hostename: %s", hostname); ESP_LOGD(TAGMAIN, "Hostname: %s", hostname);
else else
ESP_LOGD(TAGMAIN, "Hostname not set"); ESP_LOGD(TAGMAIN, "Hostname not set");

View File

@@ -450,7 +450,7 @@ httpd_handle_t start_webserver(void)
config.server_port = 80; config.server_port = 80;
config.ctrl_port = 32768; config.ctrl_port = 32768;
config.max_open_sockets = 5; //20210921 --> vorher 7 config.max_open_sockets = 5; //20210921 --> vorher 7
config.max_uri_handlers = 30; // vorher 24 config.max_uri_handlers = 35; // vorher 24, 20220511: 35
config.max_resp_headers = 8; config.max_resp_headers = 8;
config.backlog_conn = 5; config.backlog_conn = 5;
config.lru_purge_enable = true; // dadurch werden alte Verbindungen gekappt, falls neue benögt werden. config.lru_purge_enable = true; // dadurch werden alte Verbindungen gekappt, falls neue benögt werden.