From 4cd8cad83d73fce0230d7b6d73bf64b5cd6ece16 Mon Sep 17 00:00:00 2001 From: michael Date: Tue, 20 Jan 2026 23:43:45 +0100 Subject: [PATCH 1/2] test5 --- .../jomjol_fileserver_ota/server_file.cpp | 635 ++++++++++-------- .../ClassFlowCNNGeneral.cpp | 202 +++--- .../jomjol_flowcontroll/ClassFlowControll.cpp | 6 +- .../ClassFlowDefineTypes.h | 3 +- .../jomjol_flowcontroll/ClassFlowImage.cpp | 55 +- .../jomjol_flowcontroll/ClassFlowImage.h | 12 +- .../ClassFlowPostProcessing.cpp | 61 +- .../ClassFlowPostProcessing.h | 6 +- code/components/jomjol_helper/Helper.cpp | 52 +- .../components/jomjol_helper/sdcard_check.cpp | 129 +++- .../jomjol_image_proc/CImageBasis.h | 2 +- .../components/jomjol_image_proc/make_stb.cpp | 2 +- .../jomjol_network/network_init.cpp | 12 +- .../jomjol_network/read_network_config.cpp | 3 - .../jomjol_network/read_network_config.h | 2 +- .../jomjol_network/server_remote.cpp | 164 ++--- code/include/defines.h | 3 +- code/main/version.h | 51 +- ...rMessage.md => NUMBER.SkipErrorMessage.md} | 0 sd-card/config/config.ini | 2 +- sd-card/demo/config.ini | 2 +- sd-card/html/backup.html | 34 +- sd-card/html/data.html | 24 +- sd-card/html/data_export.html | 18 +- sd-card/html/edit_alignment.html | 22 +- sd-card/html/edit_analog.html | 36 +- sd-card/html/edit_config_raw.html | 22 +- sd-card/html/edit_config_template.html | 36 +- sd-card/html/edit_digits.html | 34 +- sd-card/html/edit_reference.html | 23 +- sd-card/html/graph.html | 41 +- sd-card/html/index.html | 5 +- sd-card/html/info.html | 47 +- sd-card/html/log.html | 26 +- sd-card/html/ota_page.html | 20 +- sd-card/html/overview.html | 31 +- sd-card/html/prevalue_set.html | 43 +- sd-card/html/readconfigcommon.js | 64 +- sd-card/html/readconfigparam.js | 539 ++++----------- sd-card/html/reboot_page.html | 5 +- sd-card/html/setup.html | 16 +- 41 files changed, 1184 insertions(+), 1306 deletions(-) rename param-docs/parameter-pages/PostProcessing/{SkipErrorMessage.md => NUMBER.SkipErrorMessage.md} (100%) diff --git a/code/components/jomjol_fileserver_ota/server_file.cpp b/code/components/jomjol_fileserver_ota/server_file.cpp index 15b302d1..7943fb60 100644 --- a/code/components/jomjol_fileserver_ota/server_file.cpp +++ b/code/components/jomjol_fileserver_ota/server_file.cpp @@ -42,6 +42,13 @@ static const char *TAG = "OTA FILE"; +using namespace std; + +string TEMP_SUFFIX = "_tmp"; + +static esp_err_t send_logfile(httpd_req_t *req, bool send_full_file); +static esp_err_t send_datafile(httpd_req_t *req, bool send_full_file); + struct file_server_data { /* Base path of file storage */ @@ -51,19 +58,10 @@ struct file_server_data char scratch[SERVER_FILER_SCRATCH_BUFSIZE]; }; -using namespace std; - -string SUFFIX_ZW = "_tmp"; - -static esp_err_t send_logfile(httpd_req_t *req, bool send_full_file); -static esp_err_t send_datafile(httpd_req_t *req, bool send_full_file); - esp_err_t get_numbers_file_handler(httpd_req_t *req) { std::string ret = flowctrl.getNumbersName(); - // ESP_LOGI(TAG, "Result get_numbers_file_handler: %s", ret.c_str()); - httpd_resp_set_hdr(req, "Access-Control-Allow-Origin", "*"); httpd_resp_set_type(req, "text/plain"); @@ -86,8 +84,8 @@ esp_err_t get_data_file_handler(httpd_req_t *req) httpd_resp_set_hdr(req, "Access-Control-Allow-Origin", "*"); httpd_resp_set_type(req, "text/plain"); - DIR *dir = opendir(verz_name); - while ((entry = readdir(dir)) != NULL) + DIR *pDir = opendir(verz_name); + while ((entry = readdir(pDir)) != NULL) { _filename = std::string(entry->d_name); ESP_LOGD(TAG, "File: %s", _filename.c_str()); @@ -100,8 +98,11 @@ esp_err_t get_data_file_handler(httpd_req_t *req) _fileext = _filename; pos = _fileext.find_last_of("."); + if (pos != std::string::npos) + { _fileext = _fileext.erase(0, pos + 1); + } ESP_LOGD(TAG, " Extension: %s", _fileext.c_str()); @@ -111,9 +112,10 @@ esp_err_t get_data_file_handler(httpd_req_t *req) httpd_resp_sendstr_chunk(req, _filename.c_str()); } } - closedir(dir); + closedir(pDir); httpd_resp_sendstr_chunk(req, NULL); + return ESP_OK; } @@ -130,8 +132,8 @@ esp_err_t get_tflite_file_handler(httpd_req_t *req) httpd_resp_set_hdr(req, "Access-Control-Allow-Origin", "*"); httpd_resp_set_type(req, "text/plain"); - DIR *dir = opendir(verz_name); - while ((entry = readdir(dir)) != NULL) + DIR *pDir = opendir(verz_name); + while ((entry = readdir(pDir)) != NULL) { _filename = std::string(entry->d_name); ESP_LOGD(TAG, "File: %s", _filename.c_str()); @@ -144,8 +146,11 @@ esp_err_t get_tflite_file_handler(httpd_req_t *req) _fileext = _filename; pos = _fileext.find_last_of("."); + if (pos != std::string::npos) + { _fileext = _fileext.erase(0, pos + 1); + } ESP_LOGD(TAG, " Extension: %s", _fileext.c_str()); @@ -155,9 +160,11 @@ esp_err_t get_tflite_file_handler(httpd_req_t *req) httpd_resp_sendstr_chunk(req, _filename.c_str()); } } - closedir(dir); + + closedir(pDir); httpd_resp_sendstr_chunk(req, NULL); + return ESP_OK; } @@ -168,11 +175,6 @@ esp_err_t get_tflite_file_handler(httpd_req_t *req) static esp_err_t http_resp_dir_html(httpd_req_t *req, const char *dirpath, const char *uripath, bool readonly) { char entrypath[FILE_PATH_MAX]; - char entrysize[16]; - const char *entrytype; - - struct dirent *entry; - struct stat entry_stat; char dirpath_corrected[FILE_PATH_MAX]; strcpy(dirpath_corrected, dirpath); @@ -197,11 +199,19 @@ static esp_err_t http_resp_dir_html(httpd_req_t *req, const char *dirpath, const if (!pdir) { LogFile.WriteToFile(ESP_LOG_ERROR, TAG, "Failed to stat dir: " + std::string(dirpath) + "!"); + // Respond with 404 Not Found httpd_resp_send_err(req, HTTPD_404_NOT_FOUND, get404()); + return ESP_FAIL; } + char entrysize[16]; + const char *entrytype; + + struct dirent *entry; + struct stat entry_stat; + httpd_resp_set_hdr(req, "Access-Control-Allow-Origin", "*"); // Send HTML file header @@ -231,9 +241,9 @@ static esp_err_t http_resp_dir_html(httpd_req_t *req, const char *dirpath, const httpd_resp_sendstr_chunk(req, ""); httpd_resp_sendstr_chunk(req, ""); - std::string _zw = std::string(dirpath); - _zw = _zw.substr(8, _zw.length() - 8); - _zw = "/delete/" + _zw + "?task=deldircontent"; + std::string temp_string = std::string(dirpath); + temp_string = temp_string.substr(8, temp_string.length() - 8); + temp_string = "/delete/" + temp_string + "?task=deldircontent"; // Send file-list table definition and column labels httpd_resp_sendstr_chunk(req, "" @@ -243,7 +253,7 @@ static esp_err_t http_resp_dir_html(httpd_req_t *req, const char *dirpath, const if (!readonly) { httpd_resp_sendstr_chunk(req, ""); } @@ -253,7 +263,7 @@ static esp_err_t http_resp_dir_html(httpd_req_t *req, const char *dirpath, const while ((entry = readdir(pdir)) != NULL) { // wlan.ini soll nicht angezeigt werden! - if (strcmp("wlan.ini", entry->d_name) != 0) + if ((strcmp("wlan.ini", entry->d_name) != 0) || (strcmp("network.ini", entry->d_name) != 0)) { entrytype = (entry->d_type == DT_DIR ? "directory" : "file"); @@ -325,6 +335,7 @@ static esp_err_t http_resp_dir_html(httpd_req_t *req, const char *dirpath, const // Send empty chunk to signal HTTP response completion httpd_resp_sendstr_chunk(req, NULL); + return ESP_OK; } @@ -351,46 +362,48 @@ static esp_err_t datafileact_get_last_part_handler(httpd_req_t *req) static esp_err_t send_datafile(httpd_req_t *req, bool send_full_file) { LogFile.WriteToFile(ESP_LOG_DEBUG, TAG, "data_get_last_part_handler"); - FILE *fd = NULL; - // struct stat file_stat; ESP_LOGD(TAG, "uri: %s", req->uri); std::string currentfilename = LogFile.GetCurrentFileNameData(); ESP_LOGD(TAG, "uri: %s, filename: %s, filepath: %s", req->uri, currentfilename.c_str(), currentfilename.c_str()); - fd = fopen(currentfilename.c_str(), "r"); - if (!fd) + FILE *pFile = fopen(currentfilename.c_str(), "r"); + if (!pFile) { LogFile.WriteToFile(ESP_LOG_ERROR, TAG, "Failed to read file: " + currentfilename + "!"); + /* Respond with 404 Error */ httpd_resp_send_err(req, HTTPD_404_NOT_FOUND, get404()); + return ESP_FAIL; } httpd_resp_set_hdr(req, "Access-Control-Allow-Origin", "*"); - - // ESP_LOGI(TAG, "Sending file: %s (%ld bytes)...", &filename, file_stat.st_size); set_content_type_from_file(req, currentfilename.c_str()); if (!send_full_file) - { // Send only last part of file + { + // Send only last part of file ESP_LOGD(TAG, "Sending last %d bytes of the actual datafile!", LOGFILE_LAST_PART_BYTES); /* Adapted from https://www.geeksforgeeks.org/implement-your-own-tail-read-last-n-lines-of-a-huge-file/ */ - if (fseek(fd, 0, SEEK_END)) + if (fseek(pFile, 0, SEEK_END)) { LogFile.WriteToFile(ESP_LOG_ERROR, TAG, "Failed to get to end of file!"); + return ESP_FAIL; } else { - long pos = ftell(fd); // Number of bytes in the file + long pos = ftell(pFile); // Number of bytes in the file ESP_LOGI(TAG, "File contains %ld bytes", pos); - if (fseek(fd, pos - std::min((long)LOGFILE_LAST_PART_BYTES, pos), SEEK_SET)) - { // Go LOGFILE_LAST_PART_BYTES bytes back from EOF + if (fseek(pFile, pos - std::min((long)LOGFILE_LAST_PART_BYTES, pos), SEEK_SET)) + { + // Go LOGFILE_LAST_PART_BYTES bytes back from EOF LogFile.WriteToFile(ESP_LOG_ERROR, TAG, "Failed to go back " + to_string(std::min((long)LOGFILE_LAST_PART_BYTES, pos)) + " bytes within the file!"); + return ESP_FAIL; } } @@ -398,7 +411,7 @@ static esp_err_t send_datafile(httpd_req_t *req, bool send_full_file) /* Find end of line */ while (1) { - if (fgetc(fd) == '\n') + if (fgetc(pFile) == '\n') { break; } @@ -408,20 +421,25 @@ static esp_err_t send_datafile(httpd_req_t *req, bool send_full_file) /* Retrieve the pointer to scratch buffer for temporary storage */ char *chunk = ((struct file_server_data *)req->user_ctx)->scratch; size_t chunksize; + do { /* Read file in chunks into the scratch buffer */ - chunksize = fread(chunk, 1, SERVER_FILER_SCRATCH_BUFSIZE, fd); + chunksize = fread(chunk, 1, SERVER_FILER_SCRATCH_BUFSIZE, pFile); /* Send the buffer contents as HTTP response chunk */ if (httpd_resp_send_chunk(req, chunk, chunksize) != ESP_OK) { - fclose(fd); + fclose(pFile); + LogFile.WriteToFile(ESP_LOG_ERROR, TAG, "File sending failed!"); + /* Abort sending file */ httpd_resp_sendstr_chunk(req, NULL); + /* Respond with 500 Internal Server Error */ httpd_resp_send_err(req, HTTPD_500_INTERNAL_SERVER_ERROR, "Failed to send file"); + return ESP_FAIL; } @@ -429,19 +447,18 @@ static esp_err_t send_datafile(httpd_req_t *req, bool send_full_file) } while (chunksize != 0); /* Close file after sending complete */ - fclose(fd); + fclose(pFile); ESP_LOGI(TAG, "File sending complete"); /* Respond with an empty chunk to signal HTTP response completion */ httpd_resp_send_chunk(req, NULL, 0); + return ESP_OK; } static esp_err_t send_logfile(httpd_req_t *req, bool send_full_file) { LogFile.WriteToFile(ESP_LOG_DEBUG, TAG, "log_get_last_part_handler"); - FILE *fd = NULL; - // struct stat file_stat; ESP_LOGI(TAG, "uri: %s", req->uri); const char *filename = ""; @@ -453,38 +470,42 @@ static esp_err_t send_logfile(httpd_req_t *req, bool send_full_file) // Since the log file is still could open for writing, we need to close it first LogFile.CloseLogFileAppendHandle(); - fd = fopen(currentfilename.c_str(), "r"); - if (!fd) + FILE *pFile = fopen(currentfilename.c_str(), "r"); + if (!pFile) { LogFile.WriteToFile(ESP_LOG_ERROR, TAG, "Failed to read file: " + currentfilename + "!"); + /* Respond with 404 Error */ httpd_resp_send_err(req, HTTPD_404_NOT_FOUND, get404()); + return ESP_FAIL; } httpd_resp_set_hdr(req, "Access-Control-Allow-Origin", "*"); - - // ESP_LOGI(TAG, "Sending file: %s (%ld bytes)...", &filename, file_stat.st_size); set_content_type_from_file(req, filename); if (!send_full_file) - { // Send only last part of file + { + // Send only last part of file ESP_LOGD(TAG, "Sending last %d bytes of the actual logfile!", LOGFILE_LAST_PART_BYTES); /* Adapted from https://www.geeksforgeeks.org/implement-your-own-tail-read-last-n-lines-of-a-huge-file/ */ - if (fseek(fd, 0, SEEK_END)) + if (fseek(pFile, 0, SEEK_END)) { LogFile.WriteToFile(ESP_LOG_ERROR, TAG, "Failed to get to end of file!"); + return ESP_FAIL; } else { - long pos = ftell(fd); // Number of bytes in the file + long pos = ftell(pFile); // Number of bytes in the file ESP_LOGI(TAG, "File contains %ld bytes", pos); - if (fseek(fd, pos - std::min((long)LOGFILE_LAST_PART_BYTES, pos), SEEK_SET)) - { // Go LOGFILE_LAST_PART_BYTES bytes back from EOF + if (fseek(pFile, pos - std::min((long)LOGFILE_LAST_PART_BYTES, pos), SEEK_SET)) + { + // Go LOGFILE_LAST_PART_BYTES bytes back from EOF LogFile.WriteToFile(ESP_LOG_ERROR, TAG, "Failed to go back " + to_string(std::min((long)LOGFILE_LAST_PART_BYTES, pos)) + " bytes within the file!"); + return ESP_FAIL; } } @@ -492,7 +513,7 @@ static esp_err_t send_logfile(httpd_req_t *req, bool send_full_file) /* Find end of line */ while (1) { - if (fgetc(fd) == '\n') + if (fgetc(pFile) == '\n') { break; } @@ -502,20 +523,24 @@ static esp_err_t send_logfile(httpd_req_t *req, bool send_full_file) /* Retrieve the pointer to scratch buffer for temporary storage */ char *chunk = ((struct file_server_data *)req->user_ctx)->scratch; size_t chunksize; + do { /* Read file in chunks into the scratch buffer */ - chunksize = fread(chunk, 1, SERVER_FILER_SCRATCH_BUFSIZE, fd); + chunksize = fread(chunk, 1, SERVER_FILER_SCRATCH_BUFSIZE, pFile); /* Send the buffer contents as HTTP response chunk */ if (httpd_resp_send_chunk(req, chunk, chunksize) != ESP_OK) { - fclose(fd); + fclose(pFile); LogFile.WriteToFile(ESP_LOG_ERROR, TAG, "File sending failed!"); + /* Abort sending file */ httpd_resp_sendstr_chunk(req, NULL); + /* Respond with 500 Internal Server Error */ httpd_resp_send_err(req, HTTPD_500_INTERNAL_SERVER_ERROR, "Failed to send file"); + return ESP_FAIL; } @@ -523,11 +548,12 @@ static esp_err_t send_logfile(httpd_req_t *req, bool send_full_file) } while (chunksize != 0); /* Close file after sending complete */ - fclose(fd); + fclose(pFile); ESP_LOGD(TAG, "File sending complete"); /* Respond with an empty chunk to signal HTTP response completion */ httpd_resp_send_chunk(req, NULL, 0); + return ESP_OK; } @@ -535,24 +561,22 @@ static esp_err_t send_logfile(httpd_req_t *req, bool send_full_file) static esp_err_t download_get_handler(httpd_req_t *req) { LogFile.WriteToFile(ESP_LOG_DEBUG, TAG, "download_get_handler"); + char filepath[FILE_PATH_MAX]; - FILE *fd = NULL; struct stat file_stat; ESP_LOGD(TAG, "uri: %s", req->uri); - const char *filename = get_path_from_uri(filepath, ((struct file_server_data *)req->user_ctx)->base_path, - req->uri + sizeof("/fileserver") - 1, sizeof(filepath)); + const char *filename = get_path_from_uri(filepath, ((struct file_server_data *)req->user_ctx)->base_path, req->uri + sizeof("/fileserver") - 1, sizeof(filepath)); ESP_LOGD(TAG, "uri: %s, filename: %s, filepath: %s", req->uri, filename, filepath); - // filename = get_path_from_uri(filepath, ((struct file_server_data *)req->user_ctx)->base_path, - // req->uri, sizeof(filepath)); - if (!filename) { LogFile.WriteToFile(ESP_LOG_ERROR, TAG, "Filename is too long"); + /* Respond with 414 Error */ httpd_resp_send_err(req, HTTPD_414_URI_TOO_LONG, "Filename too long"); + return ESP_FAIL; } @@ -561,13 +585,16 @@ static esp_err_t download_get_handler(httpd_req_t *req) { bool readonly = false; size_t buf_len = httpd_req_get_url_query_len(req) + 1; + if (buf_len > 1) { char buf[buf_len]; + if (httpd_req_get_url_query_str(req, buf, buf_len) == ESP_OK) { ESP_LOGI(TAG, "Found URL query => %s", buf); char param[32]; + /* Get value of expected key from query string */ if (httpd_query_key_value(buf, "readonly", param, sizeof(param)) == ESP_OK) { @@ -578,55 +605,67 @@ static esp_err_t download_get_handler(httpd_req_t *req) } ESP_LOGD(TAG, "uri: %s, filename: %s, filepath: %s", req->uri, filename, filepath); + return http_resp_dir_html(req, filepath, filename, readonly); } std::string testwlan = to_upper(std::string(filename)); - if ((stat(filepath, &file_stat) == -1) || (testwlan.compare("/WLAN.INI") == 0)) - { // wlan.ini soll nicht angezeigt werden! + if ((stat(filepath, &file_stat) == -1) || (testwlan.compare("/WLAN.INI") == 0) || (testwlan.compare("/NETWORK.INI") == 0)) + { + // wlan.ini soll nicht angezeigt werden! /* If file not present on SPIFFS check if URI * corresponds to one of the hardcoded paths */ LogFile.WriteToFile(ESP_LOG_ERROR, TAG, "Failed to stat file: " + std::string(filepath) + "!"); + /* Respond with 404 Not Found */ httpd_resp_send_err(req, HTTPD_404_NOT_FOUND, get404()); + return ESP_FAIL; } - fd = fopen(filepath, "r"); - if (!fd) + FILE *pFile = fopen(filepath, "r"); + if (!pFile) { LogFile.WriteToFile(ESP_LOG_ERROR, TAG, "Failed to read file: " + std::string(filepath) + "!"); + /* Respond with 404 Error */ httpd_resp_send_err(req, HTTPD_404_NOT_FOUND, get404()); + return ESP_FAIL; } httpd_resp_set_hdr(req, "Access-Control-Allow-Origin", "*"); ESP_LOGD(TAG, "Sending file: %s (%ld bytes)...", filename, file_stat.st_size); + set_content_type_from_file(req, filename); /* Retrieve the pointer to scratch buffer for temporary storage */ char *chunk = ((struct file_server_data *)req->user_ctx)->scratch; size_t chunksize; + do { /* Read file in chunks into the scratch buffer */ - chunksize = fread(chunk, 1, SERVER_FILER_SCRATCH_BUFSIZE, fd); + chunksize = fread(chunk, 1, SERVER_FILER_SCRATCH_BUFSIZE, pFile); /* Send buffer contents as HTTP chunk. If empty this functions as a * last-chunk message, signaling end-of-response, to the HTTP client. * See RFC 2616, section 3.6.1 for details on Chunked Transfer Encoding. */ if (httpd_resp_send_chunk(req, chunk, chunksize) != ESP_OK) { - fclose(fd); + fclose(pFile); + LogFile.WriteToFile(ESP_LOG_ERROR, TAG, "File sending failed!"); + /* Abort sending file */ httpd_resp_sendstr_chunk(req, NULL); + /* Respond with 500 Internal Server Error */ httpd_resp_send_err(req, HTTPD_500_INTERNAL_SERVER_ERROR, "Failed to send file!"); + return ESP_FAIL; } @@ -634,7 +673,7 @@ static esp_err_t download_get_handler(httpd_req_t *req) } while (chunksize != 0); /* Close file after sending complete */ - fclose(fd); + fclose(pFile); ESP_LOGD(TAG, "File successfully sent"); return ESP_OK; @@ -644,9 +683,8 @@ static esp_err_t download_get_handler(httpd_req_t *req) static esp_err_t upload_post_handler(httpd_req_t *req) { LogFile.WriteToFile(ESP_LOG_DEBUG, TAG, "upload_post_handler"); + char filepath[FILE_PATH_MAX]; - FILE *fd = NULL; - struct stat file_stat; ESP_LOGI(TAG, "uri: %s", req->uri); @@ -654,8 +692,7 @@ static esp_err_t upload_post_handler(httpd_req_t *req) /* Skip leading "/upload" from URI to get filename */ /* Note sizeof() counts NULL termination hence the -1 */ - const char *filename = get_path_from_uri(filepath, ((struct file_server_data *)req->user_ctx)->base_path, - req->uri + sizeof("/upload") - 1, sizeof(filepath)); + const char *filename = get_path_from_uri(filepath, ((struct file_server_data *)req->user_ctx)->base_path, req->uri + sizeof("/upload") - 1, sizeof(filepath)); if (!filename) { /* Respond with 413 Error */ @@ -672,6 +709,7 @@ static esp_err_t upload_post_handler(httpd_req_t *req) return ESP_FAIL; } + struct stat file_stat; if (stat(filepath, &file_stat) == 0) { LogFile.WriteToFile(ESP_LOG_ERROR, TAG, "File already exists: " + string(filepath)); @@ -685,15 +723,14 @@ static esp_err_t upload_post_handler(httpd_req_t *req) { LogFile.WriteToFile(ESP_LOG_ERROR, TAG, "File too large: " + to_string(req->content_len) + " bytes"); /* Respond with 400 Bad Request */ - httpd_resp_send_err(req, HTTPD_400_BAD_REQUEST, - "File size must be less than " MAX_FILE_SIZE_STR "!"); + httpd_resp_send_err(req, HTTPD_400_BAD_REQUEST, "File size must be less than " MAX_FILE_SIZE_STR "!"); /* Return failure to close underlying connection else the * incoming file content will keep the socket busy */ return ESP_FAIL; } - fd = fopen(filepath, "w"); - if (!fd) + FILE *pFile = fopen(filepath, "w"); + if (!pFile) { LogFile.WriteToFile(ESP_LOG_ERROR, TAG, "Failed to create file: " + string(filepath)); /* Respond with 500 Internal Server Error */ @@ -713,8 +750,8 @@ static esp_err_t upload_post_handler(httpd_req_t *req) while (remaining > 0) { - ESP_LOGI(TAG, "Remaining size: %d", remaining); + /* Receive the file part by part into a buffer */ if ((received = httpd_req_recv(req, buf, MIN(remaining, SERVER_FILER_SCRATCH_BUFSIZE))) <= 0) { @@ -726,7 +763,7 @@ static esp_err_t upload_post_handler(httpd_req_t *req) /* In case of unrecoverable error, * close and delete the unfinished file*/ - fclose(fd); + fclose(pFile); unlink(filepath); LogFile.WriteToFile(ESP_LOG_ERROR, TAG, "File reception failed!"); @@ -736,11 +773,11 @@ static esp_err_t upload_post_handler(httpd_req_t *req) } /* Write buffer content to file on storage */ - if (received && (received != fwrite(buf, 1, received, fd))) + if (received && (received != fwrite(buf, 1, received, pFile))) { /* Couldn't write everything to file! * Storage may be full? */ - fclose(fd); + fclose(pFile); unlink(filepath); LogFile.WriteToFile(ESP_LOG_ERROR, TAG, "File write failed!"); @@ -755,7 +792,7 @@ static esp_err_t upload_post_handler(httpd_req_t *req) } /* Close file upon upload completion */ - fclose(fd); + fclose(pFile); LogFile.WriteToFile(ESP_LOG_DEBUG, TAG, "File saved: " + string(filename)); ESP_LOGI(TAG, "File reception completed"); @@ -764,8 +801,8 @@ static esp_err_t upload_post_handler(httpd_req_t *req) { LogFile.WriteToFile(ESP_LOG_INFO, TAG, "Calculate and return MD5 sum..."); - fd = fopen(filepath, "r"); - if (!fd) + pFile = fopen(filepath, "r"); + if (!pFile) { LogFile.WriteToFile(ESP_LOG_ERROR, TAG, "Failed to open file for reading: " + string(filepath)); /* Respond with 500 Internal Server Error */ @@ -778,8 +815,8 @@ static esp_err_t upload_post_handler(httpd_req_t *req) string response = "{\"md5\":"; char hex[3]; - md5File(fd, result); - fclose(fd); + md5File(pFile, result); + fclose(pFile); for (int i = 0; i < sizeof(result); i++) { @@ -794,22 +831,26 @@ static esp_err_t upload_post_handler(httpd_req_t *req) httpd_resp_sendstr(req, response.c_str()); } else - { // Return file server page + { + // Return file server page std::string directory = std::string(filepath); - size_t zw = directory.find("/"); - size_t found = zw; - while (zw != std::string::npos) + size_t temp_size = directory.find("/"); + size_t found = temp_size; + + while (temp_size != std::string::npos) { - zw = directory.find("/", found + 1); - if (zw != std::string::npos) - found = zw; + temp_size = directory.find("/", found + 1); + if (temp_size != std::string::npos) + { + found = temp_size; + } } - 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); - directory = directory.substr(start_fn, found - start_fn + 1); + int start_filename = strlen(((struct file_server_data *)req->user_ctx)->base_path); + ESP_LOGD(TAG, "Directory: %s, start_filename: %d, found: %d", directory.c_str(), start_filename, found); + + directory = directory.substr(start_filename, found - start_filename + 1); directory = "/fileserver" + directory; - // ESP_LOGD(TAG, "Directory danach 2: %s", directory.c_str()); /* Redirect onto root to see the updated file list */ if (strcmp(filename, "/config/config.ini") == 0 || @@ -842,16 +883,16 @@ static esp_err_t upload_post_handler(httpd_req_t *req) static esp_err_t delete_post_handler(httpd_req_t *req) { LogFile.WriteToFile(ESP_LOG_DEBUG, TAG, "delete_post_handler"); + char filepath[FILE_PATH_MAX]; struct stat file_stat; ////////////////////////////////////////////////////////////// char _query[200]; char _valuechar[30]; - std::string fn = "/sdcard/firmware/"; + std::string _task; std::string directory; - std::string zw; httpd_resp_set_hdr(req, "Access-Control-Allow-Origin", "*"); @@ -870,36 +911,29 @@ static esp_err_t delete_post_handler(httpd_req_t *req) { /* Skip leading "/delete" from URI to get filename */ /* Note sizeof() counts NULL termination hence the -1 */ - const char *filename = get_path_from_uri(filepath, ((struct file_server_data *)req->user_ctx)->base_path, - req->uri + sizeof("/delete") - 1, sizeof(filepath)); + const char *filename = get_path_from_uri(filepath, ((struct file_server_data *)req->user_ctx)->base_path, req->uri + sizeof("/delete") - 1, sizeof(filepath)); if (!filename) { /* Respond with 414 Error */ httpd_resp_send_err(req, HTTPD_414_URI_TOO_LONG, "Filename too long"); return ESP_FAIL; } - zw = std::string(filename); - zw = zw.substr(0, zw.length() - 1); - directory = "/fileserver" + zw + "/"; - zw = "/sdcard" + zw; - ESP_LOGD(TAG, "Directory to delete: %s", zw.c_str()); - delete_all_in_directory(zw); - // directory = std::string(filepath); - // directory = "/fileserver" + directory; + std::string temp_filename = std::string(filename); + temp_filename = temp_filename.substr(0, temp_filename.length() - 1); + directory = "/fileserver" + temp_filename + "/"; + temp_filename = "/sdcard" + temp_filename; + ESP_LOGD(TAG, "Directory to delete: %s", temp_filename.c_str()); + + delete_all_in_directory(temp_filename); + ESP_LOGD(TAG, "Location after delete directory content: %s", directory.c_str()); - /* Redirect onto root to see the updated file list */ - // httpd_resp_set_status(req, "303 See Other"); - // httpd_resp_set_hdr(req, "Location", directory.c_str()); - // httpd_resp_sendstr(req, "File deleted successfully"); - // return ESP_OK; } else { /* Skip leading "/delete" from URI to get filename */ /* Note sizeof() counts NULL termination hence the -1 */ - const char *filename = get_path_from_uri(filepath, ((struct file_server_data *)req->user_ctx)->base_path, - req->uri + sizeof("/delete") - 1, sizeof(filepath)); + const char *filename = get_path_from_uri(filepath, ((struct file_server_data *)req->user_ctx)->base_path, req->uri + sizeof("/delete") - 1, sizeof(filepath)); if (!filename) { /* Respond with 500 Internal Server Error */ @@ -916,7 +950,7 @@ static esp_err_t delete_post_handler(httpd_req_t *req) return ESP_FAIL; } - if (strcmp(filename, "wlan.ini") == 0) + if ((strcmp(filename, "wlan.ini") == 0) || (strcmp(filename, "network.ini") == 0)) { LogFile.WriteToFile(ESP_LOG_ERROR, TAG, "Failed to delete protected file : " + string(filename)); httpd_resp_send_err(req, HTTPD_403_FORBIDDEN, "Not allowed to delete wlan.ini"); @@ -924,7 +958,8 @@ static esp_err_t delete_post_handler(httpd_req_t *req) } if (stat(filepath, &file_stat) == -1) - { // File does not exist + { + // File does not exist /* This is ok, we would delete it anyway */ LogFile.WriteToFile(ESP_LOG_INFO, TAG, "File does not exist: " + string(filename)); } @@ -935,19 +970,24 @@ static esp_err_t delete_post_handler(httpd_req_t *req) ESP_LOGI(TAG, "File deletion completed"); directory = std::string(filepath); - size_t zw = directory.find("/"); - size_t found = zw; - while (zw != std::string::npos) + size_t temp_size = directory.find("/"); + size_t found = temp_size; + + while (temp_size != std::string::npos) { - zw = directory.find("/", found + 1); - if (zw != std::string::npos) - found = zw; + temp_size = directory.find("/", found + 1); + if (temp_size != std::string::npos) + { + found = temp_size; + } } - 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); - directory = directory.substr(start_fn, found - start_fn + 1); + int start_filename = strlen(((struct file_server_data *)req->user_ctx)->base_path); + ESP_LOGD(TAG, "Directory: %s, start_fn: %d, found: %d", directory.c_str(), start_filename, found); + + directory = directory.substr(start_filename, found - start_filename + 1); directory = "/fileserver" + directory; + ESP_LOGD(TAG, "Directory danach 4: %s", directory.c_str()); ////////////////////////////////////////////////////////////// @@ -975,28 +1015,30 @@ static esp_err_t delete_post_handler(httpd_req_t *req) httpd_resp_set_hdr(req, "Location", directory.c_str()); httpd_resp_sendstr(req, "File successfully deleted"); + return ESP_OK; } void delete_all_in_directory(std::string _directory) { - struct dirent *entry; - DIR *dir = opendir(_directory.c_str()); - std::string filename; - - if (!dir) + DIR *pDir = opendir(_directory.c_str()); + if (!pDir) { LogFile.WriteToFile(ESP_LOG_ERROR, TAG, "Failed to stat dir: " + _directory); return; } + struct dirent *entry; + std::string filename; + /* Iterate over all files / folders and fetch their names and sizes */ - while ((entry = readdir(dir)) != NULL) + while ((entry = readdir(pDir)) != NULL) { if (!(entry->d_type == DT_DIR)) { - if (strcmp("wlan.ini", entry->d_name) != 0) - { // auf wlan.ini soll nicht zugegriffen werden !!! + if ((strcmp("wlan.ini", entry->d_name) != 0) || (strcmp("network.ini", entry->d_name) != 0)) + { + // auf wlan.ini soll nicht zugegriffen werden !!! filename = _directory + "/" + std::string(entry->d_name); LogFile.WriteToFile(ESP_LOG_INFO, TAG, "Deleting file: " + filename); /* Delete file */ @@ -1004,26 +1046,21 @@ void delete_all_in_directory(std::string _directory) } }; } - closedir(dir); + + closedir(pDir); } std::string unzip_new(std::string _in_zip_file, std::string _html_tmp, std::string _html_final, std::string _target_bin, std::string _main, bool _initial_setup) { - int i, sort_iter; - mz_bool status; - size_t uncomp_size; - mz_zip_archive zip_archive; - void *p; - char archive_filename[64]; - std::string zw, ret = ""; - std::string directory = ""; - ESP_LOGD(TAG, "minizip.c version: %s", MZ_VERSION); ESP_LOGD(TAG, "Zipfile: %s", _in_zip_file.c_str()); + std::string ret = ""; + // Now try to open the archive. + mz_zip_archive zip_archive; memset(&zip_archive, 0, sizeof(zip_archive)); - status = mz_zip_reader_init_file(&zip_archive, _in_zip_file.c_str(), 0); + mz_bool status = mz_zip_reader_init_file(&zip_archive, _in_zip_file.c_str(), 0); if (!status) { ESP_LOGD(TAG, "mzip_zip_reader_init_file() failed!"); @@ -1034,142 +1071,152 @@ std::string unzip_new(std::string _in_zip_file, std::string _html_tmp, std::stri int numberoffiles = (int)mz_zip_reader_get_num_files(&zip_archive); LogFile.WriteToFile(ESP_LOG_INFO, TAG, "Files to be extracted: " + to_string(numberoffiles)); - sort_iter = 0; + int sort_iter = 0; + + memset(&zip_archive, 0, sizeof(zip_archive)); + + status = mz_zip_reader_init_file(&zip_archive, _in_zip_file.c_str(), sort_iter ? MZ_ZIP_FLAG_DO_NOT_SORT_CENTRAL_DIRECTORY : 0); + if (!status) { - memset(&zip_archive, 0, sizeof(zip_archive)); - status = mz_zip_reader_init_file(&zip_archive, _in_zip_file.c_str(), sort_iter ? MZ_ZIP_FLAG_DO_NOT_SORT_CENTRAL_DIRECTORY : 0); - if (!status) - { - ESP_LOGD(TAG, "mzip_zip_reader_init_file() failed!"); - return ret; - } - - for (i = 0; i < numberoffiles; i++) - { - mz_zip_archive_file_stat file_stat; - mz_zip_reader_file_stat(&zip_archive, i, &file_stat); - sprintf(archive_filename, file_stat.m_filename); - - if (!file_stat.m_is_directory) - { - // Try to extract all the files to the heap. - p = mz_zip_reader_extract_file_to_heap(&zip_archive, archive_filename, &uncomp_size, 0); - if (!p) - { - LogFile.WriteToFile(ESP_LOG_ERROR, TAG, "mzip_zip_reader_extract_file_to_heap() failed on file " + string(archive_filename)); - mz_zip_reader_end(&zip_archive); - return ret; - } - - // Save to File. - zw = std::string(archive_filename); - ESP_LOGD(TAG, "Rohfilename: %s", zw.c_str()); - - if (to_upper(zw) == "FIRMWARE.BIN") - { - zw = _target_bin + zw; - ret = zw; - } - else - { - std::string _dir = get_directory(zw); - if ((_dir == "config-initial") && !_initial_setup) - { - continue; - } - else - { - _dir = "config"; - std::string _s1 = "config-initial"; - find_replace(zw, _s1, _dir); - } - - if (_dir.length() > 0) - { - zw = _main + zw; - } - else - { - zw = _html_tmp + zw; - } - } - - // files in the html folder shall be redirected to the temporary html folder - if (zw.find(_html_final) == 0) - { - find_replace(zw, _html_final, _html_tmp); - } - - string filename_zw = zw + SUFFIX_ZW; - - ESP_LOGI(TAG, "File to extract: %s, Temp. Filename: %s", zw.c_str(), filename_zw.c_str()); - - std::string folder = filename_zw.substr(0, filename_zw.find_last_of('/')); - make_dir(folder); - - // extrahieren in zwischendatei - delete_file(filename_zw); - - FILE *fpTargetFile = fopen(filename_zw.c_str(), "wb"); - uint writtenbytes = fwrite(p, 1, (uint)uncomp_size, fpTargetFile); - fclose(fpTargetFile); - - bool isokay = true; - - if (writtenbytes == (uint)uncomp_size) - { - isokay = true; - } - else - { - isokay = false; - LogFile.WriteToFile(ESP_LOG_ERROR, TAG, "ERROR in writting extracted file (function fwrite) extracted file \"" + string(archive_filename) + "\", size " + to_string(uncomp_size)); - } - - delete_file(zw); - if (!isokay) - LogFile.WriteToFile(ESP_LOG_ERROR, TAG, "ERROR in fwrite \"" + string(archive_filename) + "\", size " + to_string(uncomp_size)); - isokay = isokay && rename_file(filename_zw, zw); - if (!isokay) - LogFile.WriteToFile(ESP_LOG_ERROR, TAG, "ERROR in Rename \"" + filename_zw + "\" to \"" + zw); - - if (isokay) - LogFile.WriteToFile(ESP_LOG_DEBUG, TAG, "Successfully extracted file \"" + string(archive_filename) + "\", size " + to_string(uncomp_size)); - else - { - LogFile.WriteToFile(ESP_LOG_ERROR, TAG, "ERROR in extracting file \"" + string(archive_filename) + "\", size " + to_string(uncomp_size)); - ret = "ERROR"; - } - mz_free(p); - } - } - - // Close the archive, freeing any resources it was using - mz_zip_reader_end(&zip_archive); + ESP_LOGD(TAG, "mzip_zip_reader_init_file() failed!"); + return ret; } + void *pZip; + size_t uncomp_size; + char archive_filename[64]; + std::string directory = ""; + std::string temp_string = ""; + + for (int i = 0; i < numberoffiles; i++) + { + mz_zip_archive_file_stat file_stat; + mz_zip_reader_file_stat(&zip_archive, i, &file_stat); + sprintf(archive_filename, file_stat.m_filename); + + if (!file_stat.m_is_directory) + { + // Try to extract all the files to the heap. + pZip = mz_zip_reader_extract_file_to_heap(&zip_archive, archive_filename, &uncomp_size, 0); + if (!pZip) + { + LogFile.WriteToFile(ESP_LOG_ERROR, TAG, "mzip_zip_reader_extract_file_to_heap() failed on file " + string(archive_filename)); + mz_zip_reader_end(&zip_archive); + return ret; + } + + // Save to File. + temp_string = std::string(archive_filename); + ESP_LOGD(TAG, "Rohfilename: %s", temp_string.c_str()); + + if (to_upper(temp_string) == "FIRMWARE.BIN") + { + temp_string = _target_bin + temp_string; + ret = temp_string; + } + else + { + std::string _dir = get_directory(temp_string); + if ((_dir == "config-initial") && !_initial_setup) + { + continue; + } + else + { + _dir = "config"; + std::string _s1 = "config-initial"; + find_replace(temp_string, _s1, _dir); + } + + if (_dir.length() > 0) + { + temp_string = _main + temp_string; + } + else + { + temp_string = _html_tmp + temp_string; + } + } + + // files in the html folder shall be redirected to the temporary html folder + if (temp_string.find(_html_final) == 0) + { + find_replace(temp_string, _html_final, _html_tmp); + } + + string temp_filename = temp_string + TEMP_SUFFIX; + + ESP_LOGI(TAG, "File to extract: %s, Temp. Filename: %s", temp_string.c_str(), temp_filename.c_str()); + + std::string folder = temp_filename.substr(0, temp_filename.find_last_of('/')); + make_dir(folder); + + // extrahieren in zwischendatei + delete_file(temp_filename); + + FILE *fpTargetFile = fopen(temp_filename.c_str(), "wb"); + uint writtenbytes = fwrite(pZip, 1, (uint)uncomp_size, fpTargetFile); + fclose(fpTargetFile); + + bool isokay = true; + + if (writtenbytes == (uint)uncomp_size) + { + isokay = true; + } + else + { + isokay = false; + LogFile.WriteToFile(ESP_LOG_ERROR, TAG, "ERROR in writting extracted file (function fwrite) extracted file \"" + string(archive_filename) + "\", size " + to_string(uncomp_size)); + } + + delete_file(temp_string); + + if (!isokay) + { + LogFile.WriteToFile(ESP_LOG_ERROR, TAG, "ERROR in fwrite \"" + string(archive_filename) + "\", size " + to_string(uncomp_size)); + } + + isokay = isokay && rename_file(temp_filename, temp_string); + + if (!isokay) + { + LogFile.WriteToFile(ESP_LOG_ERROR, TAG, "ERROR in Rename \"" + temp_filename + "\" to \"" + temp_string); + } + + if (isokay) + { + LogFile.WriteToFile(ESP_LOG_DEBUG, TAG, "Successfully extracted file \"" + string(archive_filename) + "\", size " + to_string(uncomp_size)); + } + else + { + LogFile.WriteToFile(ESP_LOG_ERROR, TAG, "ERROR in extracting file \"" + string(archive_filename) + "\", size " + to_string(uncomp_size)); + ret = "ERROR"; + } + + mz_free(pZip); + } + } + + // Close the archive, freeing any resources it was using + mz_zip_reader_end(&zip_archive); + ESP_LOGD(TAG, "Success."); + return ret; } void unzip(std::string _in_zip_file, std::string _target_directory) { - int i, sort_iter; - mz_bool status; - size_t uncomp_size; - mz_zip_archive zip_archive; - void *p; - char archive_filename[64]; - std::string zw; - // static const char* s_Test_archive_filename = "testhtml.zip"; - ESP_LOGD(TAG, "minizip.c version: %s", MZ_VERSION); ESP_LOGD(TAG, "Zipfile: %s", _in_zip_file.c_str()); ESP_LOGD(TAG, "Target Dir: %s", _target_directory.c_str()); // Now try to open the archive. + mz_zip_archive zip_archive; memset(&zip_archive, 0, sizeof(zip_archive)); - status = mz_zip_reader_init_file(&zip_archive, _in_zip_file.c_str(), 0); + + mz_bool status = mz_zip_reader_init_file(&zip_archive, _in_zip_file.c_str(), 0); if (!status) { LogFile.WriteToFile(ESP_LOG_ERROR, TAG, "mzip_zip_reader_init_file() failed!"); @@ -1178,7 +1225,13 @@ void unzip(std::string _in_zip_file, std::string _target_directory) // Get and print information about each file in the archive. int numberoffiles = (int)mz_zip_reader_get_num_files(&zip_archive); - for (sort_iter = 0; sort_iter < 2; sort_iter++) + + void *pZip; + size_t uncomp_size; + char archive_filename[64]; + std::string temp_string; + + for (int sort_iter = 0; sort_iter < 2; sort_iter++) { memset(&zip_archive, 0, sizeof(zip_archive)); status = mz_zip_reader_init_file(&zip_archive, _in_zip_file.c_str(), sort_iter ? MZ_ZIP_FLAG_DO_NOT_SORT_CENTRAL_DIRECTORY : 0); @@ -1188,15 +1241,15 @@ void unzip(std::string _in_zip_file, std::string _target_directory) return; } - for (i = 0; i < numberoffiles; i++) + for (int i = 0; i < numberoffiles; i++) { mz_zip_archive_file_stat file_stat; mz_zip_reader_file_stat(&zip_archive, i, &file_stat); sprintf(archive_filename, file_stat.m_filename); // Try to extract all the files to the heap. - p = mz_zip_reader_extract_file_to_heap(&zip_archive, archive_filename, &uncomp_size, 0); - if (!p) + pZip = mz_zip_reader_extract_file_to_heap(&zip_archive, archive_filename, &uncomp_size, 0); + if (!pZip) { LogFile.WriteToFile(ESP_LOG_ERROR, TAG, "mzip_zip_reader_extract_file_to_heap() failed!"); mz_zip_reader_end(&zip_archive); @@ -1204,18 +1257,18 @@ void unzip(std::string _in_zip_file, std::string _target_directory) } // Save to File. - zw = std::string(archive_filename); - zw = _target_directory + zw; - ESP_LOGD(TAG, "File to extract: %s", zw.c_str()); - FILE *fpTargetFile = fopen(zw.c_str(), "wb"); - fwrite(p, 1, (uint)uncomp_size, fpTargetFile); + temp_string = std::string(archive_filename); + temp_string = _target_directory + temp_string; + ESP_LOGD(TAG, "File to extract: %s", temp_string.c_str()); + + FILE *fpTargetFile = fopen(temp_string.c_str(), "wb"); + fwrite(pZip, 1, (uint)uncomp_size, fpTargetFile); fclose(fpTargetFile); 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. - mz_free(p); + mz_free(pZip); } // Close the archive, freeing any resources it was using @@ -1250,60 +1303,60 @@ void file_server_register_uri(httpd_handle_t server, const char *base_path) /* URI handler for getting uploaded files */ httpd_uri_t file_download = { - .uri = "/fileserver*", // Match all URIs of type /path/to/file + .uri = "/fileserver*", .method = HTTP_GET, .handler = APPLY_BASIC_AUTH_FILTER(download_get_handler), - .user_ctx = server_data // Pass server data as context + .user_ctx = server_data, }; httpd_register_uri_handler(server, &file_download); httpd_uri_t file_datafileact = { - .uri = "/datafileact", // Match all URIs of type /path/to/file + .uri = "/datafileact", .method = HTTP_GET, .handler = APPLY_BASIC_AUTH_FILTER(datafileact_get_full_handler), - .user_ctx = server_data // Pass server data as context + .user_ctx = server_data, }; httpd_register_uri_handler(server, &file_datafileact); httpd_uri_t file_datafile_last_part_handle = { - .uri = "/data", // Match all URIs of type /path/to/file + .uri = "/data", .method = HTTP_GET, .handler = APPLY_BASIC_AUTH_FILTER(datafileact_get_last_part_handler), - .user_ctx = server_data // Pass server data as context + .user_ctx = server_data, }; httpd_register_uri_handler(server, &file_datafile_last_part_handle); httpd_uri_t file_logfileact = { - .uri = "/logfileact", // Match all URIs of type /path/to/file + .uri = "/logfileact", .method = HTTP_GET, .handler = APPLY_BASIC_AUTH_FILTER(logfileact_get_full_handler), - .user_ctx = server_data // Pass server data as context + .user_ctx = server_data, }; httpd_register_uri_handler(server, &file_logfileact); httpd_uri_t file_logfile_last_part_handle = { - .uri = "/log", // Match all URIs of type /path/to/file + .uri = "/log", .method = HTTP_GET, .handler = APPLY_BASIC_AUTH_FILTER(logfileact_get_last_part_handler), - .user_ctx = server_data // Pass server data as context + .user_ctx = server_data, }; httpd_register_uri_handler(server, &file_logfile_last_part_handle); /* URI handler for uploading files to server */ httpd_uri_t file_upload = { - .uri = "/upload/*", // Match all URIs of type /upload/path/to/file + .uri = "/upload/*", .method = HTTP_POST, .handler = APPLY_BASIC_AUTH_FILTER(upload_post_handler), - .user_ctx = server_data // Pass server data as context + .user_ctx = server_data, }; httpd_register_uri_handler(server, &file_upload); /* URI handler for deleting files from server */ httpd_uri_t file_delete = { - .uri = "/delete/*", // Match all URIs of type /delete/path/to/file + .uri = "/delete/*", .method = HTTP_POST, .handler = APPLY_BASIC_AUTH_FILTER(delete_post_handler), - .user_ctx = server_data // Pass server data as context + .user_ctx = server_data, }; httpd_register_uri_handler(server, &file_delete); } diff --git a/code/components/jomjol_flowcontroll/ClassFlowCNNGeneral.cpp b/code/components/jomjol_flowcontroll/ClassFlowCNNGeneral.cpp index 63e76a2a..be20318b 100644 --- a/code/components/jomjol_flowcontroll/ClassFlowCNNGeneral.cpp +++ b/code/components/jomjol_flowcontroll/ClassFlowCNNGeneral.cpp @@ -42,15 +42,15 @@ std::vector ClassFlowCNNGeneral::getMeterValues(int _number = 0) return meterValues; } - for (int i = 0; i < GENERAL[_number]->ROI.size(); ++i) + for (int _roi = 0; _roi < GENERAL[_number]->ROI.size(); ++_roi) { if (CNNType == Digit) { - meterValues.push_back(GENERAL[_number]->ROI[i]->result_klasse); + meterValues.push_back(GENERAL[_number]->ROI[_roi]->result_klasse); } else { - meterValues.push_back(GENERAL[_number]->ROI[i]->result_float); + meterValues.push_back(GENERAL[_number]->ROI[_roi]->result_float); } } @@ -81,9 +81,9 @@ std::string ClassFlowCNNGeneral::getReadout(int _number = 0, bool _extendedResol result = result + std::to_string(result_after_decimal_point); } - for (int i = GENERAL[_number]->ROI.size() - 2; i >= 0; --i) + for (int _roi = GENERAL[_number]->ROI.size() - 2; _roi >= 0; --_roi) { - prev = PointerEvalAnalog(GENERAL[_number]->ROI[i]->result_float, prev); + prev = PointerEvalAnalog(GENERAL[_number]->ROI[_roi]->result_float, prev); result = std::to_string(prev) + result; } return result; @@ -91,11 +91,11 @@ std::string ClassFlowCNNGeneral::getReadout(int _number = 0, bool _extendedResol if (CNNType == Digit) { - for (int i = 0; i < GENERAL[_number]->ROI.size(); ++i) + for (int _roi = 0; _roi < GENERAL[_number]->ROI.size(); ++_roi) { - if ((GENERAL[_number]->ROI[i]->result_klasse >= 0) && (GENERAL[_number]->ROI[i]->result_klasse < 10)) + if ((GENERAL[_number]->ROI[_roi]->result_klasse >= 0) && (GENERAL[_number]->ROI[_roi]->result_klasse < 10)) { - result = result + std::to_string(GENERAL[_number]->ROI[i]->result_klasse); + result = result + std::to_string(GENERAL[_number]->ROI[_roi]->result_klasse); } else { @@ -153,20 +153,20 @@ std::string ClassFlowCNNGeneral::getReadout(int _number = 0, bool _extendedResol } } - for (int i = GENERAL[_number]->ROI.size() - 2; i >= 0; --i) + for (int _roi = GENERAL[_number]->ROI.size() - 2; _roi >= 0; --_roi) { - if ((GENERAL[_number]->ROI[i]->result_float >= 0.0f) && (GENERAL[_number]->ROI[i]->result_float < 10.0f)) + if ((GENERAL[_number]->ROI[_roi]->result_float >= 0.0f) && (GENERAL[_number]->ROI[_roi]->result_float < 10.0f)) { - prev = PointerEvalHybrid(GENERAL[_number]->ROI[i]->result_float, GENERAL[_number]->ROI[i + 1]->result_float, prev); - LogFile.WriteToFile(ESP_LOG_DEBUG, TAG, "getReadout(DoubleHyprid10) - roi_" + std::to_string(i) + "prev= " + std::to_string(prev)); + prev = PointerEvalHybrid(GENERAL[_number]->ROI[_roi]->result_float, GENERAL[_number]->ROI[_roi + 1]->result_float, prev); + LogFile.WriteToFile(ESP_LOG_DEBUG, TAG, "getReadout(DoubleHyprid10) - roi_" + std::to_string(_roi) + "prev= " + std::to_string(prev)); result = std::to_string(prev) + result; - LogFile.WriteToFile(ESP_LOG_DEBUG, TAG, "getReadout(DoubleHyprid10) - roi_" + std::to_string(i) + "result= " + result); + LogFile.WriteToFile(ESP_LOG_DEBUG, TAG, "getReadout(DoubleHyprid10) - roi_" + std::to_string(_roi) + "result= " + result); } else { prev = -1; result = "N" + result; - LogFile.WriteToFile(ESP_LOG_DEBUG, TAG, "getReadout(result_float < 0 /'N') - roi_" + std::to_string(i) + "result_float=" + std::to_string(GENERAL[_number]->ROI[i]->result_float)); + LogFile.WriteToFile(ESP_LOG_DEBUG, TAG, "getReadout(result_float < 0 /'N') - roi_" + std::to_string(_roi) + "result_float=" + std::to_string(GENERAL[_number]->ROI[_roi]->result_float)); } } return result; @@ -194,7 +194,7 @@ int ClassFlowCNNGeneral::PointerEvalHybrid(float number, float number_of_predece { int result = -1; int result_after_decimal_point = ((int)floor(number * 10.0f)) % 10; - int result_before_decimal_point = ((int)floor(number) + 10) % 10; + int result_before_decimal_point = ((int)(floor(number) + 10.0f)) % 10; if (eval_predecessors < 0) { @@ -203,7 +203,7 @@ int ClassFlowCNNGeneral::PointerEvalHybrid(float number, float number_of_predece // add precisition of 2 digits and round before trunc // a number greater than 9.994999 is returned as 10, this leads to an error during the decimal shift because the NUMBERS[j]->ReturnRawValue is one digit longer. // To avoid this, an additional test must be carried out, see "if ((CNNType == DoubleHyprid10) || (CNNType == Digit100))" check in getReadout() - result = (int) (trunc(round((float)((int)(number + 10.0f) % 10) * 100.0f)) / 100.0f); + result = (int)(trunc(round((float)((int)(number + 10.0f) % 10) * 100.0f)) / 100.0f); LogFile.WriteToFile(ESP_LOG_DEBUG, TAG, "PointerEvalHybrid - No predecessor - Result = " + std::to_string(result) + " number: " + std::to_string(number) + " number_of_predecessors = " + std::to_string(number_of_predecessors) + " eval_predecessors = " + std::to_string(eval_predecessors) + " Digit_Uncertainty = " + std::to_string(Digit_Uncertainty)); return result; @@ -216,17 +216,17 @@ int ClassFlowCNNGeneral::PointerEvalHybrid(float number, float number_of_predece return result; } - if ((number_of_predecessors >= Digit_Transition_Area_Predecessor) && (number_of_predecessors <= (10.0 - Digit_Transition_Area_Predecessor))) + if ((number_of_predecessors >= (float)Digit_Transition_Area_Predecessor) && (number_of_predecessors <= (10.0f - (float)Digit_Transition_Area_Predecessor))) { // no digit change, because predecessor is far enough away (0+/-DigitTransitionRangePredecessor) --> number is rounded // Band around the digit --> Round off, as digit reaches inaccuracy in the frame if ((result_after_decimal_point <= DigitBand) || (result_after_decimal_point >= (10 - DigitBand))) { - result = ((int)round(number) + 10) % 10; + result = ((int)(round(number) + 10.0f)) % 10; } else { - result = ((int)trunc(number) + 10) % 10; + result = ((int)(trunc(number) + 10.0f)) % 10; } LogFile.WriteToFile(ESP_LOG_DEBUG, TAG, "PointerEvalHybrid - NO analogue predecessor, no change of digits, as pre-decimal point far enough away = " + std::to_string(result) + " number: " + std::to_string(number) + " number_of_predecessors = " + std::to_string(number_of_predecessors) + " eval_predecessors = " + std::to_string(eval_predecessors) + " Digit_Uncertainty = " + std::to_string(Digit_Uncertainty)); @@ -277,24 +277,24 @@ int ClassFlowCNNGeneral::PointerEvalAnalogToDigit(float number, float numeral_pr { int result = -1; int result_after_decimal_point = ((int)floor(number * 10.0f)) % 10; - int result_before_decimal_point = ((int)floor(number) + 10) % 10; + int result_before_decimal_point = ((int)(floor(number) + 10.0f)) % 10; bool roundedUp = false; // Within the digit inequalities // Band around the digit --> Round off, as digit reaches inaccuracy in the frame - if ((result_after_decimal_point >= (10 - (int)(Digit_Uncertainty * 10.0f))) || (eval_predecessors <= 4 && result_after_decimal_point >= 6)) + if ((result_after_decimal_point >= (int)(10.0f - ((float)Digit_Uncertainty * 10.0f))) || (eval_predecessors <= 4 && result_after_decimal_point >= 6)) { // or digit runs after (analogue =0..4, digit >=6) - result = (int)(round(number) + 10) % 10; + result = (int)(round(number) + 10.0f) % 10; roundedUp = true; // before/ after decimal point, because we adjust the number based on the uncertainty. - result_after_decimal_point = ((int)floor(result * 10)) % 10; - result_before_decimal_point = ((int)floor(result) + 10) % 10; + result_after_decimal_point = ((int)floor(result * 10.0f)) % 10; + result_before_decimal_point = ((int)(floor(result) + 10.0f)) % 10; LogFile.WriteToFile(ESP_LOG_DEBUG, TAG, "PointerEvalAnalogToDigit - Digit Uncertainty - Result = " + std::to_string(result) + " number: " + std::to_string(number) + " numeral_preceder: " + std::to_string(numeral_preceder) + " erg before comma: " + std::to_string(result_before_decimal_point) + " erg after comma: " + std::to_string(result_after_decimal_point)); } else { - result = (int)((int)trunc(number) + 10) % 10; + result = (int)((int)(trunc(number) + 10.0f)) % 10; LogFile.WriteToFile(ESP_LOG_DEBUG, TAG, "PointerEvalAnalogToDigit - NO digit Uncertainty - Result = " + std::to_string(result) + " number: " + std::to_string(number) + " numeral_preceder = " + std::to_string(numeral_preceder)); } @@ -321,26 +321,26 @@ int ClassFlowCNNGeneral::PointerEvalAnalog(float number, int numeral_preceder) return result; } - float number_min = number - (float)Analog_error / 10.0f; - float number_max = number + (float)Analog_error / 10.0f; + float number_min = number - ((float)Analog_error / 10.0f); + float number_max = number + ((float)Analog_error / 10.0f); if ((int)floor(number_max) - (int)floor(number_min) != 0) { - if (numeral_preceder <= Analog_error) + if (numeral_preceder <= (int)Analog_error) { - result = ((int)floor(number_max) + 10) % 10; + result = ((int)(floor(number_max) + 10.0f)) % 10; LogFile.WriteToFile(ESP_LOG_DEBUG, TAG, "PointerEvalAnalog - number ambiguous, correction upwards - result = " + std::to_string(result) + " number: " + std::to_string(number) + " numeral_preceder = " + std::to_string(numeral_preceder) + " Analog_error = " + std::to_string(Analog_error)); return result; } - if (numeral_preceder >= (10 - Analog_error)) + if (numeral_preceder >= (10 - (int)Analog_error)) { - result = ((int)floor(number_min) + 10) % 10; + result = ((int)(floor(number_min) + 10.0f)) % 10; LogFile.WriteToFile(ESP_LOG_DEBUG, TAG, "PointerEvalAnalog - number ambiguous, downward correction - result = " + std::to_string(result) + " number: " + std::to_string(number) + " numeral_preceder = " + std::to_string(numeral_preceder) + " Analog_error = " + std::to_string(Analog_error)); return result; } } - result = ((int)floor(number) + 10) % 10; + result = ((int)(floor(number) + 10.0f)) % 10; LogFile.WriteToFile(ESP_LOG_DEBUG, TAG, "PointerEvalAnalog - number unambiguous, no correction necessary - result = " + std::to_string(result) + " number: " + std::to_string(number) + " numeral_preceder = " + std::to_string(numeral_preceder) + " Analog_error = " + std::to_string(Analog_error)); return result; @@ -455,12 +455,12 @@ bool ClassFlowCNNGeneral::ReadParameter(FILE *pfile, std::string &aktparamgraph) return false; } - for (int i = 0; i < GENERAL.size(); ++i) + for (int _number = 0; _number < GENERAL.size(); ++_number) { - for (int j = 0; j < GENERAL[i]->ROI.size(); ++j) + for (int _roi = 0; _roi < GENERAL[_number]->ROI.size(); ++_roi) { - GENERAL[i]->ROI[j]->image = new CImageBasis("ROI " + GENERAL[i]->ROI[j]->name, model_x_size, model_y_size, model_channel); - GENERAL[i]->ROI[j]->image_org = new CImageBasis("ROI " + GENERAL[i]->ROI[j]->name + " original", GENERAL[i]->ROI[j]->delta_x, GENERAL[i]->ROI[j]->delta_y, 3); + GENERAL[_number]->ROI[_roi]->image = new CImageBasis("ROI " + GENERAL[_number]->ROI[_roi]->name, model_x_size, model_y_size, model_channel); + GENERAL[_number]->ROI[_roi]->image_org = new CImageBasis("ROI " + GENERAL[_number]->ROI[_roi]->name + " original", GENERAL[_number]->ROI[_roi]->delta_x, GENERAL[_number]->ROI[_roi]->delta_y, 3); } } @@ -469,11 +469,11 @@ bool ClassFlowCNNGeneral::ReadParameter(FILE *pfile, std::string &aktparamgraph) general *ClassFlowCNNGeneral::FindGENERAL(std::string _name_number) { - for (int i = 0; i < GENERAL.size(); ++i) + for (int _number = 0; _number < GENERAL.size(); ++_number) { - if (GENERAL[i]->name == _name_number) + if (GENERAL[_number]->name == _name_number) { - return GENERAL[i]; + return GENERAL[_number]; } } @@ -773,34 +773,34 @@ bool ClassFlowCNNGeneral::doNeuralNetwork(std::string time_value) LogFile.WriteToFile(ESP_LOG_DEBUG, TAG, "doNeuralNetwork, _imagetime: " + std::to_string(_imagetime)); // For each NUMBER - for (int j = 0; j < GENERAL.size(); ++j) + for (int _number = 0; _number < GENERAL.size(); ++_number) { - LogFile.WriteToFile(ESP_LOG_DEBUG, TAG, "Processing Number '" + GENERAL[j]->name + "'"); + LogFile.WriteToFile(ESP_LOG_DEBUG, TAG, "Processing Number '" + GENERAL[_number]->name + "'"); int start_roi = 0; - if ((numbers[j]->useMaxFlowRate) && (numbers[j]->PreValueValid) && (numbers[j]->timeStampLastValue == numbers[j]->timeStampLastPreValue)) + if ((numbers[_number]->useMaxFlowRate) && (numbers[_number]->PreValueValid) && (numbers[_number]->timeStampLastValue == numbers[_number]->timeStampLastPreValue)) { - int _AnzahlDigit = numbers[j]->AnzahlDigit; + int _AnzahlDigit = numbers[_number]->AnzahlDigit; LogFile.WriteToFile(ESP_LOG_DEBUG, TAG, "doNeuralNetwork, _AnzahlDigit: " + std::to_string(_AnzahlDigit)); - int _AnzahlAnalog = numbers[j]->AnzahlAnalog; + int _AnzahlAnalog = numbers[_number]->AnzahlAnalog; LogFile.WriteToFile(ESP_LOG_DEBUG, TAG, "doNeuralNetwork, _AnzahlAnalog: " + std::to_string(_AnzahlAnalog)); - float _MaxFlowRate = (numbers[j]->MaxFlowRate / 60); // in unit/minutes + float _MaxFlowRate = (numbers[_number]->MaxFlowRate / 60); // in unit/minutes LogFile.WriteToFile(ESP_LOG_DEBUG, TAG, "doNeuralNetwork, _MaxFlowRate: " + std::to_string(_MaxFlowRate)); - float _LastPreValueTimeDifference = (float)((difftime(_imagetime, numbers[j]->timeStampLastPreValue)) / 60); // in minutes + float _LastPreValueTimeDifference = (float)((difftime(_imagetime, numbers[_number]->timeStampLastPreValue)) / 60); // in minutes LogFile.WriteToFile(ESP_LOG_DEBUG, TAG, "doNeuralNetwork, _LastPreValueTimeDifference: " + std::to_string(_LastPreValueTimeDifference) + " minutes"); - std::string _PreValue_old = std::to_string((float)numbers[j]->PreValue); + std::string _PreValue_old = std::to_string((float)numbers[_number]->PreValue); LogFile.WriteToFile(ESP_LOG_DEBUG, TAG, "doNeuralNetwork, _PreValue_old: " + _PreValue_old); //////////////////////////////////////////////////// - std::string _PreValue_new1 = std::to_string((float)numbers[j]->PreValue + (_MaxFlowRate * _LastPreValueTimeDifference)); + std::string _PreValue_new1 = std::to_string((float)numbers[_number]->PreValue + (_MaxFlowRate * _LastPreValueTimeDifference)); LogFile.WriteToFile(ESP_LOG_DEBUG, TAG, "doNeuralNetwork, _PreValue_new1: " + _PreValue_new1); - std::string _PreValue_new2 = std::to_string((float)numbers[j]->PreValue - (_MaxFlowRate * _LastPreValueTimeDifference)); + std::string _PreValue_new2 = std::to_string((float)numbers[_number]->PreValue - (_MaxFlowRate * _LastPreValueTimeDifference)); LogFile.WriteToFile(ESP_LOG_DEBUG, TAG, "doNeuralNetwork, _PreValue_new2: " + _PreValue_new2); //////////////////////////////////////////////////// @@ -810,12 +810,12 @@ bool ClassFlowCNNGeneral::doNeuralNetwork(std::string time_value) if (_pospunkt > -1) { _CorrectionValue = _PreValue_old.length() - _pospunkt; - _CorrectionValue = _CorrectionValue - numbers[j]->Nachkomma; + _CorrectionValue = _CorrectionValue - numbers[_number]->Nachkomma; } LogFile.WriteToFile(ESP_LOG_DEBUG, TAG, "doNeuralNetwork, _CorrectionValue: " + std::to_string(_CorrectionValue)); int _PreValue_len = ((int)_PreValue_old.length() - _CorrectionValue); - if (numbers[j]->isExtendedResolution) + if (numbers[_number]->ExtendedResolution) { _PreValue_len = _PreValue_len - 1; } @@ -845,7 +845,7 @@ bool ClassFlowCNNGeneral::doNeuralNetwork(std::string time_value) //////////////////////////////////////////////////// // (-) Find out which Numbers should not change int _NumbersNotChanged2 = _NumbersNotChanged1; - if (numbers[j]->AllowNegativeRates) + if (numbers[_number]->AllowNegativeRates) { int _DecimalPoint2 = 0; while ((_PreValue_old.length() > _NumbersNotChanged2) && (_PreValue_old[_NumbersNotChanged2] == _PreValue_new2[_NumbersNotChanged2])) @@ -898,9 +898,9 @@ bool ClassFlowCNNGeneral::doNeuralNetwork(std::string time_value) } // For each ROI - for (int i = 0; i < GENERAL[j]->ROI.size(); ++i) + for (int _roi = 0; _roi < GENERAL[_number]->ROI.size(); ++_roi) { - LogFile.WriteToFile(ESP_LOG_DEBUG, TAG, "ROI #" + std::to_string(i) + " - TfLite"); + LogFile.WriteToFile(ESP_LOG_DEBUG, TAG, "ROI #" + std::to_string(_roi) + " - TfLite"); switch (CNNType) { @@ -908,7 +908,7 @@ bool ClassFlowCNNGeneral::doNeuralNetwork(std::string time_value) { LogFile.WriteToFile(ESP_LOG_DEBUG, TAG, "CNN Type: Analogue"); - tflite->LoadInputImageBasis(GENERAL[j]->ROI[i]->image); + tflite->LoadInputImageBasis(GENERAL[_number]->ROI[_roi]->image); tflite->Invoke(); LogFile.WriteToFile(ESP_LOG_DEBUG, TAG, "Analogue - After Invoke"); @@ -918,7 +918,7 @@ bool ClassFlowCNNGeneral::doNeuralNetwork(std::string time_value) float _result = fmod((atan2(_value1, _value2) / (M_PI * 2.0f) + 2.0f), 1.0f); - if (GENERAL[j]->ROI[i]->ccw) + if (GENERAL[_number]->ROI[_roi]->ccw) { _result = 10.0f - (_result * 10.0f); } @@ -927,34 +927,34 @@ bool ClassFlowCNNGeneral::doNeuralNetwork(std::string time_value) _result = _result * 10.0f; } - if (i >= start_roi) + if (_roi >= start_roi) { - GENERAL[j]->ROI[i]->result_float = _result; + GENERAL[_number]->ROI[_roi]->result_float = _result; } - GENERAL[j]->ROI[i]->raw_result_float = _result; + GENERAL[_number]->ROI[_roi]->raw_result_float = _result; if ((_result < 0.0f) || (_result >= 10.0f)) { - GENERAL[j]->ROI[i]->isReject = true; + GENERAL[_number]->ROI[_roi]->isReject = true; } else { - GENERAL[j]->ROI[i]->isReject = false; + GENERAL[_number]->ROI[_roi]->isReject = false; } - LogFile.WriteToFile(ESP_LOG_DEBUG, TAG, "General result (Analog) - roi_" + std::to_string(i) + ": " + std::to_string(GENERAL[j]->ROI[i]->raw_result_float)); - ESP_LOGD(TAG, "General result (Analog) - roi_%i - ccw: %d - %f", i, GENERAL[j]->ROI[i]->ccw, GENERAL[j]->ROI[i]->raw_result_float); + LogFile.WriteToFile(ESP_LOG_DEBUG, TAG, "General result (Analog) - roi_" + std::to_string(_roi) + ": " + std::to_string(GENERAL[_number]->ROI[_roi]->raw_result_float)); + ESP_LOGD(TAG, "General result (Analog) - roi_%i - ccw: %d - %f", _roi, GENERAL[_number]->ROI[_roi]->ccw, GENERAL[_number]->ROI[_roi]->raw_result_float); if (isLogImage) { - std::string _image_name = GENERAL[j]->name + "_" + GENERAL[j]->ROI[i]->name; + std::string _image_name = GENERAL[_number]->name + "_" + GENERAL[_number]->ROI[_roi]->name; if (isLogImageSelect) { - if (LogImageSelect.find(GENERAL[j]->ROI[i]->name) != std::string::npos) + if (LogImageSelect.find(GENERAL[_number]->ROI[_roi]->name) != std::string::npos) { - LogImage(logPath, _image_name, &GENERAL[j]->ROI[i]->raw_result_float, NULL, time_value, GENERAL[j]->ROI[i]->image_org); + LogImage(logPath, _image_name, &GENERAL[_number]->ROI[_roi]->raw_result_float, NULL, time_value, GENERAL[_number]->ROI[_roi]->image_org); } } } @@ -965,36 +965,36 @@ bool ClassFlowCNNGeneral::doNeuralNetwork(std::string time_value) { LogFile.WriteToFile(ESP_LOG_DEBUG, TAG, "CNN Type: Digit"); - int _result = tflite->GetClassFromImageBasis(GENERAL[j]->ROI[i]->image); + int _result = tflite->GetClassFromImageBasis(GENERAL[_number]->ROI[_roi]->image); - if (i >= start_roi) + if (_roi >= start_roi) { - GENERAL[j]->ROI[i]->result_klasse = _result; + GENERAL[_number]->ROI[_roi]->result_klasse = _result; } - GENERAL[j]->ROI[i]->raw_result_klasse = _result; + GENERAL[_number]->ROI[_roi]->raw_result_klasse = _result; if ((_result < 0) || (_result >= 10)) { - GENERAL[j]->ROI[i]->isReject = true; + GENERAL[_number]->ROI[_roi]->isReject = true; } else { - GENERAL[j]->ROI[i]->isReject = false; + GENERAL[_number]->ROI[_roi]->isReject = false; } - LogFile.WriteToFile(ESP_LOG_DEBUG, TAG, "General result (Digit) - roi_" + std::to_string(i) + ": " + std::to_string(GENERAL[j]->ROI[i]->raw_result_klasse)); - ESP_LOGD(TAG, "General result (Digit) - roi_%i: %d", i, GENERAL[j]->ROI[i]->raw_result_klasse); + LogFile.WriteToFile(ESP_LOG_DEBUG, TAG, "General result (Digit) - roi_" + std::to_string(_roi) + ": " + std::to_string(GENERAL[_number]->ROI[_roi]->raw_result_klasse)); + ESP_LOGD(TAG, "General result (Digit) - roi_%i: %d", _roi, GENERAL[_number]->ROI[_roi]->raw_result_klasse); if (isLogImage) { - std::string _image_name = GENERAL[j]->name + "_" + GENERAL[j]->ROI[i]->name; + std::string _image_name = GENERAL[_number]->name + "_" + GENERAL[_number]->ROI[_roi]->name; if (isLogImageSelect) { - if (LogImageSelect.find(GENERAL[j]->ROI[i]->name) != std::string::npos) + if (LogImageSelect.find(GENERAL[_number]->ROI[_roi]->name) != std::string::npos) { - LogImage(logPath, _image_name, NULL, &GENERAL[j]->ROI[i]->raw_result_klasse, time_value, GENERAL[j]->ROI[i]->image_org); + LogImage(logPath, _image_name, NULL, &GENERAL[_number]->ROI[_roi]->raw_result_klasse, time_value, GENERAL[_number]->ROI[_roi]->image_org); } } } @@ -1005,7 +1005,7 @@ bool ClassFlowCNNGeneral::doNeuralNetwork(std::string time_value) { LogFile.WriteToFile(ESP_LOG_DEBUG, TAG, "CNN Type: DoubleHyprid10"); - tflite->LoadInputImageBasis(GENERAL[j]->ROI[i]->image); + tflite->LoadInputImageBasis(GENERAL[_number]->ROI[_roi]->image); tflite->Invoke(); LogFile.WriteToFile(ESP_LOG_DEBUG, TAG, "DoubleHyprid10 - After Invoke"); @@ -1040,39 +1040,39 @@ bool ClassFlowCNNGeneral::doNeuralNetwork(std::string time_value) if (_fit < CNNGoodThreshold) { - GENERAL[j]->ROI[i]->isReject = true; + GENERAL[_number]->ROI[_roi]->isReject = true; _result = -1; temp_bufer = "DoubleHyprid10 - Value Rejected due to Threshold (Fit: " + std::to_string(_fit) + ", Threshold: " + std::to_string(CNNGoodThreshold) + ")"; LogFile.WriteToFile(ESP_LOG_WARN, TAG, temp_bufer); } else { - GENERAL[j]->ROI[i]->isReject = false; + GENERAL[_number]->ROI[_roi]->isReject = false; } - if (GENERAL[j]->ROI[i]->ccw) + if (GENERAL[_number]->ROI[_roi]->ccw) { } - if (i >= start_roi) + if (_roi >= start_roi) { - GENERAL[j]->ROI[i]->result_float = _result; + GENERAL[_number]->ROI[_roi]->result_float = _result; } - GENERAL[j]->ROI[i]->raw_result_float = _result; + GENERAL[_number]->ROI[_roi]->raw_result_float = _result; - LogFile.WriteToFile(ESP_LOG_DEBUG, TAG, "Result General(DoubleHyprid10) - roi_" + std::to_string(i) + ": " + std::to_string(GENERAL[j]->ROI[i]->raw_result_float)); - ESP_LOGD(TAG, "Result General(DoubleHyprid10) - roi_%i: %f", i, GENERAL[j]->ROI[i]->raw_result_float); + LogFile.WriteToFile(ESP_LOG_DEBUG, TAG, "Result General(DoubleHyprid10) - roi_" + std::to_string(_roi) + ": " + std::to_string(GENERAL[_number]->ROI[_roi]->raw_result_float)); + ESP_LOGD(TAG, "Result General(DoubleHyprid10) - roi_%i: %f", _roi, GENERAL[_number]->ROI[_roi]->raw_result_float); if (isLogImage) { - std::string _image_name = GENERAL[j]->name + "_" + GENERAL[j]->ROI[i]->name; + std::string _image_name = GENERAL[_number]->name + "_" + GENERAL[_number]->ROI[_roi]->name; if (isLogImageSelect) { - if (LogImageSelect.find(GENERAL[j]->ROI[i]->name) != std::string::npos) + if (LogImageSelect.find(GENERAL[_number]->ROI[_roi]->name) != std::string::npos) { - LogImage(logPath, _image_name, &_result_save_file, NULL, time_value, GENERAL[j]->ROI[i]->image_org); + LogImage(logPath, _image_name, &_result_save_file, NULL, time_value, GENERAL[_number]->ROI[_roi]->image_org); } } } @@ -1084,13 +1084,13 @@ bool ClassFlowCNNGeneral::doNeuralNetwork(std::string time_value) { LogFile.WriteToFile(ESP_LOG_DEBUG, TAG, "CNN Type: Digit100 or Analogue100"); - tflite->LoadInputImageBasis(GENERAL[j]->ROI[i]->image); + tflite->LoadInputImageBasis(GENERAL[_number]->ROI[_roi]->image); tflite->Invoke(); int _num = tflite->GetOutClassification(); float _result = 0.0f; - if (GENERAL[j]->ROI[i]->ccw) + if (GENERAL[_number]->ROI[_roi]->ccw) { _result = 10.0f - ((float)_num / 10.0f); } @@ -1099,34 +1099,34 @@ bool ClassFlowCNNGeneral::doNeuralNetwork(std::string time_value) _result = (float)_num / 10.0f; } - if (i >= start_roi) + if (_roi >= start_roi) { - GENERAL[j]->ROI[i]->result_float = _result; + GENERAL[_number]->ROI[_roi]->result_float = _result; } - GENERAL[j]->ROI[i]->raw_result_float = _result; + GENERAL[_number]->ROI[_roi]->raw_result_float = _result; if ((_result < 0.0f) || (_result >= 10.0f)) { - GENERAL[j]->ROI[i]->isReject = true; + GENERAL[_number]->ROI[_roi]->isReject = true; } else { - GENERAL[j]->ROI[i]->isReject = false; + GENERAL[_number]->ROI[_roi]->isReject = false; } - LogFile.WriteToFile(ESP_LOG_DEBUG, TAG, "Result General(Digit100 or Analogue100) - roi_" + std::to_string(i) + ": " + std::to_string(GENERAL[j]->ROI[i]->raw_result_float)); - ESP_LOGD(TAG, "Result General(Digit100 or Analogue100) - roi_%i - ccw: %d - %f", i, GENERAL[j]->ROI[i]->ccw, GENERAL[j]->ROI[i]->raw_result_float); + LogFile.WriteToFile(ESP_LOG_DEBUG, TAG, "Result General(Digit100 or Analogue100) - roi_" + std::to_string(_roi) + ": " + std::to_string(GENERAL[_number]->ROI[_roi]->raw_result_float)); + ESP_LOGD(TAG, "Result General(Digit100 or Analogue100) - roi_%i - ccw: %d - %f", _roi, GENERAL[_number]->ROI[_roi]->ccw, GENERAL[_number]->ROI[_roi]->raw_result_float); if (isLogImage) { - std::string _image_name = GENERAL[j]->name + "_" + GENERAL[j]->ROI[i]->name; + std::string _image_name = GENERAL[_number]->name + "_" + GENERAL[_number]->ROI[_roi]->name; if (isLogImageSelect) { - if (LogImageSelect.find(GENERAL[j]->ROI[i]->name) != std::string::npos) + if (LogImageSelect.find(GENERAL[_number]->ROI[_roi]->name) != std::string::npos) { - LogImage(logPath, _image_name, &GENERAL[j]->ROI[i]->raw_result_float, NULL, time_value, GENERAL[j]->ROI[i]->image_org); + LogImage(logPath, _image_name, &GENERAL[_number]->ROI[_roi]->raw_result_float, NULL, time_value, GENERAL[_number]->ROI[_roi]->image_org); } } } diff --git a/code/components/jomjol_flowcontroll/ClassFlowControll.cpp b/code/components/jomjol_flowcontroll/ClassFlowControll.cpp index 3d918918..88d96423 100644 --- a/code/components/jomjol_flowcontroll/ClassFlowControll.cpp +++ b/code/components/jomjol_flowcontroll/ClassFlowControll.cpp @@ -312,11 +312,11 @@ void ClassFlowControll::InitFlow(std::string config) flowpostprocessing = NULL; ClassFlow *cfc; + config = format_filename(config); FILE *pFile = fopen(config.c_str(), "r"); std::string line = ""; - char temp_char[1024]; if (pFile != NULL) @@ -632,7 +632,7 @@ bool ClassFlowControll::ReadParameter(FILE *pFile, std::string &aktparamgraph) int RSSIThresholdTMP = atoi(splitted[1].c_str()); RSSIThresholdTMP = min(0, max(-100, RSSIThresholdTMP)); // Verify input limits (-100 - 0) - if (ChangeRSSIThreshold(NETWORK_CONFIG_FILE, RSSIThresholdTMP)) + if ((ChangeRSSIThreshold(WLAN_CONFIG_FILE, RSSIThresholdTMP)) || (ChangeRSSIThreshold(NETWORK_CONFIG_FILE, RSSIThresholdTMP))) { // reboot necessary so that the new wlan.ini is also used !!! fclose(pFile); @@ -643,7 +643,7 @@ bool ClassFlowControll::ReadParameter(FILE *pFile, std::string &aktparamgraph) #endif else if (_param == "HOSTNAME") { - if (ChangeHostName(NETWORK_CONFIG_FILE, splitted[1])) + if ((ChangeHostName(WLAN_CONFIG_FILE, splitted[1])) || (ChangeHostName(NETWORK_CONFIG_FILE, splitted[1]))) { // reboot necessary so that the new wlan.ini is also used !!! fclose(pFile); diff --git a/code/components/jomjol_flowcontroll/ClassFlowDefineTypes.h b/code/components/jomjol_flowcontroll/ClassFlowDefineTypes.h index 8d9d3cd5..33f3af67 100644 --- a/code/components/jomjol_flowcontroll/ClassFlowDefineTypes.h +++ b/code/components/jomjol_flowcontroll/ClassFlowDefineTypes.h @@ -59,6 +59,7 @@ struct NumberPost string ReturnPreValue; // lastValidValueStr; corrected return value without error message bool ErrorMessage; // string ErrorMessageText; // errorMessage; Error message for consistency checks + bool SkipErrorMessage; int AnzahlAnalog; // numAnalogRoi; number of analog ROIs used in this sequence int AnzahlDigit; // numDigitRoi; number of digit ROIs used in this sequence int DecimalShift; // decimalShift; each increment shifts the decimal separator by one digit; value=value*10^decimalShift; pos. value shifts to the right @@ -74,7 +75,7 @@ struct NumberPost string FieldV2; // influxdbFieldName_v2; Name of the Field in InfluxDBv2 string MeasurementV2; // influxdbMeasurementName_v2; Name of the Measurement in InfluxDBv2 - bool isExtendedResolution; // extendResolution; Adds the decimal place of the least significant analog ROI to the value + bool ExtendedResolution; // extendResolution; Adds the decimal place of the least significant analog ROI to the value general *digit_roi; // digitRoi; set of digit ROIs for the sequence general *analog_roi; // analogRoi; set of analog ROIs for the sequence diff --git a/code/components/jomjol_flowcontroll/ClassFlowImage.cpp b/code/components/jomjol_flowcontroll/ClassFlowImage.cpp index 767daa51..22b45606 100644 --- a/code/components/jomjol_flowcontroll/ClassFlowImage.cpp +++ b/code/components/jomjol_flowcontroll/ClassFlowImage.cpp @@ -13,36 +13,39 @@ static const char *TAG = "FLOWIMAGE"; -ClassFlowImage::ClassFlowImage(const char *logTag) +ClassFlowImage::ClassFlowImage(const char *_logTag) { - this->logTag = logTag; + logTag = _logTag; isLogImage = false; disabled = false; - this->imagesRetention = 5; + imagesRetention = 5; } -ClassFlowImage::ClassFlowImage(std::vector *lfc, const char *logTag) : ClassFlow(lfc) +ClassFlowImage::ClassFlowImage(std::vector *_lfc, const char *_logTag) : ClassFlow(_lfc) { - this->logTag = logTag; + logTag = _logTag; isLogImage = false; disabled = false; - this->imagesRetention = 5; + imagesRetention = 5; } -ClassFlowImage::ClassFlowImage(std::vector *lfc, ClassFlow *_prev, const char *logTag) : ClassFlow(lfc, _prev) +ClassFlowImage::ClassFlowImage(std::vector *_lfc, ClassFlow *_prev, const char *_logTag) : ClassFlow(_lfc, _prev) { - this->logTag = logTag; + logTag = _logTag; isLogImage = false; disabled = false; - this->imagesRetention = 5; + imagesRetention = 5; } -string ClassFlowImage::CreateLogFolder(string time) +string ClassFlowImage::CreateLogFolder(string _time) { if (!isLogImage) + { return ""; + } + + string logPath = imagesLocation + "/" + _time.LOGFILE_TIME_FORMAT_DATE_EXTR + "/" + _time.LOGFILE_TIME_FORMAT_HOUR_EXTR; - string logPath = imagesLocation + "/" + time.LOGFILE_TIME_FORMAT_DATE_EXTR + "/" + time.LOGFILE_TIME_FORMAT_HOUR_EXTR; isLogImage = mkdir_r(logPath.c_str(), S_IRWXU) == 0; if (!isLogImage) { @@ -52,42 +55,50 @@ string ClassFlowImage::CreateLogFolder(string time) return logPath; } -void ClassFlowImage::LogImage(string logPath, string name, float *resultFloat, int *resultInt, string time, CImageBasis *_img) +void ClassFlowImage::LogImage(string _logPath, string _name, float *_resultFloat, int *_resultInt, string _time, CImageBasis *_img) { if (!isLogImage) + { return; + } char buf[10]; - if (resultFloat != NULL) + if (_resultFloat != NULL) { - if (*resultFloat < 0) + if (*_resultFloat < 0) + { sprintf(buf, "N.N_"); + } else { - sprintf(buf, "%.1f_", *resultFloat); + sprintf(buf, "%.1f_", *_resultFloat); if (strcmp(buf, "10.0_") == 0) - sprintf(buf, "0.0_"); + { + sprintf(buf, "N.N_"); + } } } - else if (resultInt != NULL) + else if (_resultInt != NULL) { - sprintf(buf, "%d_", *resultInt); + sprintf(buf, "%d_", *_resultInt); } else { buf[0] = '\0'; } - string nm = logPath + "/" + buf + name + "_" + time + ".jpg"; + string nm = _logPath + "/" + buf + _name + "_" + _time + ".jpg"; nm = format_filename(nm); - string output = "/sdcard/img_tmp/" + name + ".jpg"; + + string output = "/sdcard/img_tmp/" + _name + ".jpg"; output = format_filename(output); + ESP_LOGD(logTag, "save to file: %s", nm.c_str()); _img->SaveToFile(nm); } -void ClassFlowImage::RemoveOldLogs() +void ClassFlowImage::RemoveOldLogs(void) { if (!isLogImage) { @@ -121,6 +132,7 @@ void ClassFlowImage::RemoveOldLogs() struct dirent *entry; int deleted = 0; int notDeleted = 0; + while ((entry = readdir(dir)) != NULL) { string folderPath = imagesLocation + "/" + entry->d_name; @@ -137,6 +149,7 @@ void ClassFlowImage::RemoveOldLogs() } } } + ESP_LOGD(TAG, "Image folder deleted: %d | Image folder not deleted: %d", deleted, notDeleted); closedir(dir); } diff --git a/code/components/jomjol_flowcontroll/ClassFlowImage.h b/code/components/jomjol_flowcontroll/ClassFlowImage.h index 1bf8db92..785020ba 100644 --- a/code/components/jomjol_flowcontroll/ClassFlowImage.h +++ b/code/components/jomjol_flowcontroll/ClassFlowImage.h @@ -15,15 +15,15 @@ protected: unsigned short imagesRetention; const char *logTag; - string CreateLogFolder(string time); - void LogImage(string logPath, string name, float *resultFloat, int *resultInt, string time, CImageBasis *_img); + string CreateLogFolder(string _time); + void LogImage(string _logPath, string _name, float *_resultFloat, int *_resultInt, string _time, CImageBasis *_img); public: - ClassFlowImage(const char *logTag); - ClassFlowImage(std::vector *lfc, const char *logTag); - ClassFlowImage(std::vector *lfc, ClassFlow *_prev, const char *logTag); + ClassFlowImage(const char *_logTag); + ClassFlowImage(std::vector *_lfc, const char *_logTag); + ClassFlowImage(std::vector *_lfc, ClassFlow *_prev, const char *_logTag); - void RemoveOldLogs(); + void RemoveOldLogs(void); }; #endif // CLASSFLOWIMAGE_H diff --git a/code/components/jomjol_flowcontroll/ClassFlowPostProcessing.cpp b/code/components/jomjol_flowcontroll/ClassFlowPostProcessing.cpp index 16f89e27..7ecea32c 100644 --- a/code/components/jomjol_flowcontroll/ClassFlowPostProcessing.cpp +++ b/code/components/jomjol_flowcontroll/ClassFlowPostProcessing.cpp @@ -79,7 +79,7 @@ std::string ClassFlowPostProcessing::getJsonFromNumber(int i, std::string _linee { json += " \"rate\": \"\"," + _lineend; } - + if (NUMBERS[i]->ReturnChangeAbsolute.length() > 0) { json += " \"absrate\": \"" + NUMBERS[i]->ReturnChangeAbsolute + "\"," + _lineend; @@ -351,7 +351,6 @@ ClassFlowPostProcessing::ClassFlowPostProcessing(std::vector *lfc, { PreValueUse = false; PreValueAgeStartup = 30; - SkipErrorMessage = false; ListFlowControll = NULL; FilePreValue = format_filename("/sdcard/config/prevalue.ini"); ListFlowControll = lfc; @@ -369,7 +368,7 @@ ClassFlowPostProcessing::ClassFlowPostProcessing(std::vector *lfc, } } -void ClassFlowPostProcessing::handleDecimalExtendedResolution(std::string _decsep, std::string _value) +void ClassFlowPostProcessing::handleExtendedResolution(std::string _decsep, std::string _value) { std::string _digit; int _pospunkt = _decsep.find_first_of("."); @@ -390,12 +389,12 @@ void ClassFlowPostProcessing::handleDecimalExtendedResolution(std::string _decse // Set to default first (if nothing else is set) if ((_digit == "default") || (NUMBERS[j]->name == _digit)) { - NUMBERS[j]->isExtendedResolution = temp_value; + NUMBERS[j]->ExtendedResolution = temp_value; } } } -void ClassFlowPostProcessing::handleDecimalSeparator(std::string _decsep, std::string _value) +void ClassFlowPostProcessing::handleDecimalShift(std::string _decsep, std::string _value) { std::string _digit; int _pospunkt = _decsep.find_first_of("."); @@ -460,6 +459,32 @@ void ClassFlowPostProcessing::handleAnalogToDigitTransitionStart(std::string _de } } +void ClassFlowPostProcessing::handleSkipErrorMessage(std::string _decsep, std::string _value) +{ + std::string _digit; + int _pospunkt = _decsep.find_first_of("."); + + if (_pospunkt > -1) + { + _digit = _decsep.substr(0, _pospunkt); + } + else + { + _digit = "default"; + } + + for (int j = 0; j < NUMBERS.size(); ++j) + { + bool temp_value = alphanumeric_to_boolean(_value); + + // Set to default first (if nothing else is set) + if ((_digit == "default") || (NUMBERS[j]->name == _digit)) + { + NUMBERS[j]->SkipErrorMessage = temp_value; + } + } +} + void ClassFlowPostProcessing::handleAllowNegativeRate(std::string _decsep, std::string _value) { std::string _digit; @@ -679,7 +704,7 @@ bool ClassFlowPostProcessing::ReadParameter(FILE *pFile, std::string &aktparamgr } else if (_param == "SKIPERRORMESSAGE") { - SkipErrorMessage = alphanumeric_to_boolean(splitted[1]); + handleSkipErrorMessage(splitted[0], splitted[1]); } else if (_param == "ALLOWNEGATIVERATES") { @@ -687,7 +712,7 @@ bool ClassFlowPostProcessing::ReadParameter(FILE *pFile, std::string &aktparamgr } else if (_param == "DECIMALSHIFT") { - handleDecimalSeparator(splitted[0], splitted[1]); + handleDecimalShift(splitted[0], splitted[1]); } else if (_param == "ANALOGTODIGITTRANSITIONSTART") { @@ -711,7 +736,7 @@ bool ClassFlowPostProcessing::ReadParameter(FILE *pFile, std::string &aktparamgr } else if (_param == "EXTENDEDRESOLUTION") { - handleDecimalExtendedResolution(splitted[0], splitted[1]); + handleExtendedResolution(splitted[0], splitted[1]); } else if (_param == "IGNORELEADINGNAN") { @@ -788,6 +813,7 @@ void ClassFlowPostProcessing::InitNUMBERS() _number->PreValueValid = false; _number->ErrorMessage = false; _number->ErrorMessageText = ""; // Error message for consistency check + _number->SkipErrorMessage = false; _number->AllowNegativeRates = false; _number->DecimalShift = 0; _number->DecimalShiftInitial = 0; @@ -798,13 +824,13 @@ void ClassFlowPostProcessing::InitNUMBERS() _number->MaxRateType = AbsoluteChange; _number->useMaxRateValue = false; _number->ChangeRateThreshold = 2; - _number->isExtendedResolution = false; + _number->ExtendedResolution = false; _number->IgnoreLeadingNaN = false; - _number->Value = 0.0f; // last value read out, incl. corrections + _number->Value = 0.0f; // last value read out, incl. corrections _number->ReturnValue = ""; // corrected return value, possibly with error message _number->ReturnRawValue = ""; // raw value (with N & leading 0) - _number->FlowRateAct = 0.0f; // m3 / min + _number->FlowRateAct = 0.0f; // m3 / min _number->Nachkomma = _number->AnzahlAnalog; @@ -884,7 +910,7 @@ bool ClassFlowPostProcessing::doFlow(std::string temp_time) NUMBERS[j]->Value = -1; - if (SkipErrorMessage) + if (NUMBERS[j]->SkipErrorMessage) { NUMBERS[j]->ReturnValue = std::to_string(NUMBERS[j]->PreValue); NUMBERS[j]->ReturnRawValue = NUMBERS[j]->ReturnValue; @@ -923,11 +949,12 @@ bool ClassFlowPostProcessing::doFlow(std::string temp_time) int previous_value = -1; if (NUMBERS[j]->analog_roi) { - NUMBERS[j]->ReturnRawValue = flowAnalog->getReadout(j, NUMBERS[j]->isExtendedResolution); + NUMBERS[j]->ReturnRawValue = flowAnalog->getReadout(j, NUMBERS[j]->ExtendedResolution); if (NUMBERS[j]->ReturnRawValue.length() > 0) { char temp_char = NUMBERS[j]->ReturnRawValue[0]; + if (temp_char >= 48 && temp_char <= 57) { previous_value = temp_char - 48; @@ -948,7 +975,7 @@ bool ClassFlowPostProcessing::doFlow(std::string temp_time) } else { - NUMBERS[j]->ReturnRawValue = flowDigit->getReadout(j, NUMBERS[j]->isExtendedResolution, previous_value); // Extended Resolution only if there are no analogue digits + NUMBERS[j]->ReturnRawValue = flowDigit->getReadout(j, NUMBERS[j]->ExtendedResolution, previous_value); // Extended Resolution only if there are no analogue digits } } @@ -1143,7 +1170,7 @@ void ClassFlowPostProcessing::UpdateNachkommaDecimalShift() NUMBERS[j]->DecimalShift = NUMBERS[j]->DecimalShiftInitial; // Extended resolution is on and should also be used for this digit. - if (NUMBERS[j]->isExtendedResolution && flowDigit->isExtendedResolution()) + if (NUMBERS[j]->ExtendedResolution && flowDigit->isExtendedResolution()) { NUMBERS[j]->DecimalShift = NUMBERS[j]->DecimalShift - 1; } @@ -1156,7 +1183,7 @@ void ClassFlowPostProcessing::UpdateNachkommaDecimalShift() // ESP_LOGD(TAG, "Nur analog"); NUMBERS[j]->DecimalShift = NUMBERS[j]->DecimalShiftInitial; - if (NUMBERS[j]->isExtendedResolution && flowAnalog->isExtendedResolution()) + if (NUMBERS[j]->ExtendedResolution && flowAnalog->isExtendedResolution()) { NUMBERS[j]->DecimalShift = NUMBERS[j]->DecimalShift - 1; } @@ -1173,7 +1200,7 @@ void ClassFlowPostProcessing::UpdateNachkommaDecimalShift() NUMBERS[j]->Nachkomma = NUMBERS[j]->analog_roi->ROI.size() - NUMBERS[j]->DecimalShift; // Extended resolution is on and should also be used for this digit. - if (NUMBERS[j]->isExtendedResolution && flowAnalog->isExtendedResolution()) + if (NUMBERS[j]->ExtendedResolution && flowAnalog->isExtendedResolution()) { NUMBERS[j]->Nachkomma = NUMBERS[j]->Nachkomma + 1; } diff --git a/code/components/jomjol_flowcontroll/ClassFlowPostProcessing.h b/code/components/jomjol_flowcontroll/ClassFlowPostProcessing.h index 9ae1a81e..0a4cac1c 100644 --- a/code/components/jomjol_flowcontroll/ClassFlowPostProcessing.h +++ b/code/components/jomjol_flowcontroll/ClassFlowPostProcessing.h @@ -16,7 +16,6 @@ protected: bool UpdatePreValueINI; int PreValueAgeStartup; - bool SkipErrorMessage; ClassFlowCNNGeneral *flowAnalog; ClassFlowCNNGeneral *flowDigit; @@ -32,11 +31,12 @@ protected: void InitNUMBERS(); - void handleDecimalSeparator(std::string _decsep, std::string _value); + void handleDecimalShift(std::string _decsep, std::string _value); void handleMaxRateValue(std::string _decsep, std::string _value); - void handleDecimalExtendedResolution(std::string _decsep, std::string _value); + void handleExtendedResolution(std::string _decsep, std::string _value); void handleMaxRateType(std::string _decsep, std::string _value); void handleAnalogToDigitTransitionStart(std::string _decsep, std::string _value); + void handleSkipErrorMessage(std::string _decsep, std::string _value); void handleAllowNegativeRate(std::string _decsep, std::string _value); void handleIgnoreLeadingNaN(std::string _decsep, std::string _value); void handleChangeRateThreshold(std::string _decsep, std::string _value); diff --git a/code/components/jomjol_helper/Helper.cpp b/code/components/jomjol_helper/Helper.cpp index d19b72c1..b68c3acf 100644 --- a/code/components/jomjol_helper/Helper.cpp +++ b/code/components/jomjol_helper/Helper.cpp @@ -368,15 +368,8 @@ std::string decrypt_pw_string(std::string toDecrypt) // Checks if all passwords on the SD are encrypted and if they are not encrypted, it encrypts them. esp_err_t encrypt_decrypt_pw_on_sd(bool _encrypt, std::string filename) { - std::string line = ""; - - std::vector splitted; - std::vector temp_file; - - all_pw_were_encrypted = false; - - std::string fn = format_filename(filename); - FILE *pFile = fopen(fn.c_str(), "r"); + std::string _filename = format_filename(filename); + FILE *pFile = fopen(_filename.c_str(), "r"); if (pFile == NULL) { @@ -387,6 +380,7 @@ esp_err_t encrypt_decrypt_pw_on_sd(bool _encrypt, std::string filename) ESP_LOGD(TAG, "EncryptDecryptConfigPwOnSD: config.ini opened"); + std::string line = ""; char temp_line[256]; if (fgets(temp_line, sizeof(temp_line), pFile) == NULL) @@ -401,6 +395,11 @@ esp_err_t encrypt_decrypt_pw_on_sd(bool _encrypt, std::string filename) line = std::string(temp_line); } + all_pw_were_encrypted = false; + + std::vector splitted; + std::vector temp_file; + if (_encrypt) { while ((line.size() > 0) || !(feof(pFile))) @@ -425,7 +424,7 @@ esp_err_t encrypt_decrypt_pw_on_sd(bool _encrypt, std::string filename) line = "apikey = " + encrypt_pw_string(splitted[1]) + "\n"; } } - else if (filename == NETWORK_CONFIG_FILE) + else if ((filename == WLAN_CONFIG_FILE) || (filename == NETWORK_CONFIG_FILE)) { if (_param == "PASSWORD") { @@ -474,7 +473,7 @@ esp_err_t encrypt_decrypt_pw_on_sd(bool _encrypt, std::string filename) line = "apikey = " + decrypt_pw_string(splitted[1]) + "\n"; } } - else if (filename == NETWORK_CONFIG_FILE) + else if ((filename == WLAN_CONFIG_FILE) || (filename == NETWORK_CONFIG_FILE)) { if (_param == "PASSWORD") { @@ -505,7 +504,7 @@ esp_err_t encrypt_decrypt_pw_on_sd(bool _encrypt, std::string filename) // Only write to the SD if not all passwords are encrypted if ((all_pw_were_encrypted == false && _encrypt == true) || (all_pw_were_encrypted == true && _encrypt == false)) { - pFile = fopen(fn.c_str(), "w+"); + pFile = fopen(_filename.c_str(), "w+"); if (pFile == NULL) { @@ -1140,16 +1139,16 @@ size_t find_delimiter_pos(string input, string delimiter) bool rename_file(string from, string to) { // ESP_LOGI(logTag, "Renaming File: %s", from.c_str()); - FILE *fpSourceFile = fopen(from.c_str(), "rb"); + FILE *pFile = fopen(from.c_str(), "rb"); // Sourcefile does not exist otherwise there is a mistake when renaming! - if (!fpSourceFile) + if (!pFile) { ESP_LOGE(TAG, "RenameFile: File %s does not exist!", from.c_str()); return false; } - fclose(fpSourceFile); + fclose(pFile); rename(from.c_str(), to.c_str()); return true; @@ -1175,15 +1174,15 @@ bool rename_folder(string from, string to) bool file_exists(string filename) { - FILE *fpSourceFile = fopen(filename.c_str(), "rb"); + FILE *pFile = fopen(filename.c_str(), "rb"); // Sourcefile does not exist - if (!fpSourceFile) + if (!pFile) { return false; } - fclose(fpSourceFile); + fclose(pFile); return true; } @@ -1207,16 +1206,16 @@ bool delete_file(string filename) { // ESP_LOGI(logTag, "Deleting file: %s", filename.c_str()); /* Delete file */ - FILE *fpSourceFile = fopen(filename.c_str(), "rb"); + FILE *pFile = fopen(filename.c_str(), "rb"); // Sourcefile does not exist otherwise there is a mistake in copying! - if (!fpSourceFile) + if (!pFile) { ESP_LOGD(TAG, "DeleteFile: File %s existiert nicht!", filename.c_str()); return false; } - fclose(fpSourceFile); + fclose(pFile); unlink(filename.c_str()); return true; @@ -1227,13 +1226,12 @@ bool copy_file(string input, string output) input = format_filename(input); output = format_filename(output); - if (to_upper(input).compare(NETWORK_CONFIG_FILE) == 0) + if ((to_upper(input).compare(WLAN_CONFIG_FILE) == 0) || (to_upper(input).compare(NETWORK_CONFIG_FILE) == 0)) { ESP_LOGD(TAG, "wlan.ini kann nicht kopiert werden!"); return false; } - char cTemp; FILE *fpSourceFile = fopen(input.c_str(), "rb"); // Sourcefile existiert nicht sonst gibt es einen Fehler beim Kopierversuch! @@ -1245,18 +1243,19 @@ bool copy_file(string input, string output) FILE *fpTargetFile = fopen(output.c_str(), "wb"); - // Code Section + char temp_char[1024]; // Read From The Source File - "Copy" - while (fread(&cTemp, 1, 1, fpSourceFile) == 1) + while (fread(&temp_char, 1, 1, fpSourceFile) == 1) { // Write To The Target File - "Paste" - fwrite(&cTemp, 1, 1, fpTargetFile); + fwrite(&temp_char, 1, 1, fpTargetFile); } // Close The Files fclose(fpSourceFile); fclose(fpTargetFile); + ESP_LOGD(TAG, "File copied: %s to %s", input.c_str(), output.c_str()); return true; @@ -1466,7 +1465,6 @@ string round_output(double _in, int _anzNachkomma) { std::stringstream stream; int temp_value = _in; - // ESP_LOGD(TAG, "AnzNachkomma: %d", _anzNachkomma); if (_anzNachkomma > 0) { diff --git a/code/components/jomjol_helper/sdcard_check.cpp b/code/components/jomjol_helper/sdcard_check.cpp index 94e5e7cb..f669084b 100644 --- a/code/components/jomjol_helper/sdcard_check.cpp +++ b/code/components/jomjol_helper/sdcard_check.cpp @@ -7,7 +7,7 @@ #include #include -#include "esp_rom_crc.h" +#include "esp_rom_crc.h" #include "ClassLogFile.h" static const char *TAG = "SDCARD"; @@ -15,52 +15,60 @@ static const char *TAG = "SDCARD"; int SDCardCheckRW(void) { LogFile.WriteToFile(ESP_LOG_INFO, TAG, "Basic R/W check started..."); - FILE* pFile = NULL; int iCRCMessage = 0; - - pFile = fopen("/sdcard/sdcheck.txt","w"); - if (pFile == NULL) { + + FILE *pFile = fopen("/sdcard/sdcheck.txt", "w"); + if (pFile == NULL) + { LogFile.WriteToFile(ESP_LOG_ERROR, TAG, "Basic R/W check: (E1) No able to open file to write"); return -1; - } - else { + } + else + { std::string sMessage = "This message is used for a SD-Card basic check!"; - iCRCMessage = esp_rom_crc16_le(0, (uint8_t*)sMessage.c_str(), sMessage.length()); - if (fwrite(sMessage.c_str(), sMessage.length(), 1, pFile) == 0 ) { + iCRCMessage = esp_rom_crc16_le(0, (uint8_t *)sMessage.c_str(), sMessage.length()); + if (fwrite(sMessage.c_str(), sMessage.length(), 1, pFile) == 0) + { LogFile.WriteToFile(ESP_LOG_ERROR, TAG, "Basic R/W check: (E2) Not able to write file"); fclose(pFile); unlink("/sdcard/sdcheck.txt"); return -2; } - fclose(pFile); + fclose(pFile); } - pFile = fopen("/sdcard/sdcheck.txt","r"); - if (pFile == NULL) { + pFile = fopen("/sdcard/sdcheck.txt", "r"); + if (pFile == NULL) + { LogFile.WriteToFile(ESP_LOG_ERROR, TAG, "Basic R/W check: (E3) Not able to open file to read back"); unlink("/sdcard/sdcheck.txt"); return -3; - } - else { + } + else + { char cReadBuf[50]; - if (fgets(cReadBuf, sizeof(cReadBuf), pFile) == 0) { + if (fgets(cReadBuf, sizeof(cReadBuf), pFile) == 0) + { LogFile.WriteToFile(ESP_LOG_ERROR, TAG, "Basic R/W check: (E4) Not able to read file back"); fclose(pFile); unlink("/sdcard/sdcheck.txt"); return -4; } - else { - if (esp_rom_crc16_le(0, (uint8_t*)cReadBuf, strlen(cReadBuf)) != iCRCMessage) { + else + { + if (esp_rom_crc16_le(0, (uint8_t *)cReadBuf, strlen(cReadBuf)) != iCRCMessage) + { LogFile.WriteToFile(ESP_LOG_ERROR, TAG, "Basic R/W check: (E5) Read back, but wrong CRC"); fclose(pFile); unlink("/sdcard/sdcheck.txt"); return -5; } - } + } fclose(pFile); } - if (unlink("/sdcard/sdcheck.txt") != 0) { + if (unlink("/sdcard/sdcheck.txt") != 0) + { LogFile.WriteToFile(ESP_LOG_ERROR, TAG, "Basic R/W check: (E6) Unable to delete the file"); return -6; } @@ -76,86 +84,135 @@ bool SDCardCheckFolderFilePresence() LogFile.WriteToFile(ESP_LOG_INFO, TAG, "Folder/file presence check started..."); /* check if folder exists: config */ - if (stat("/sdcard/config", &sb) != 0) { + if (stat("/sdcard/config", &sb) != 0) + { LogFile.WriteToFile(ESP_LOG_ERROR, TAG, "Folder/file check: Folder /config not found"); bRetval = false; } /* check if folder exists: html */ - if (stat("/sdcard/html", &sb) != 0) { + if (stat("/sdcard/html", &sb) != 0) + { LogFile.WriteToFile(ESP_LOG_ERROR, TAG, "Folder/file check: Folder /html not found"); bRetval = false; } /* check if folder exists: firmware */ - if (stat("/sdcard/firmware", &sb) != 0) { + if (stat("/sdcard/firmware", &sb) != 0) + { LogFile.WriteToFile(ESP_LOG_ERROR, TAG, "Folder/file check: Folder /firmware not found"); bRetval = false; } /* check if folder exists: img_tmp */ - if (stat("/sdcard/img_tmp", &sb) != 0) { + if (stat("/sdcard/img_tmp", &sb) != 0) + { LogFile.WriteToFile(ESP_LOG_ERROR, TAG, "Folder/file check: Folder /img_tmp not found"); bRetval = false; } /* check if folder exists: log */ - if (stat("/sdcard/log", &sb) != 0) { + if (stat("/sdcard/log", &sb) != 0) + { LogFile.WriteToFile(ESP_LOG_ERROR, TAG, "Folder/file check: Folder /log not found"); bRetval = false; } /* check if folder exists: demo */ - if (stat("/sdcard/demo", &sb) != 0) { + if (stat("/sdcard/demo", &sb) != 0) + { LogFile.WriteToFile(ESP_LOG_ERROR, TAG, "Folder/file check: Folder /demo not found"); bRetval = false; } /* check if file exists: wlan.ini */ - if (stat("/sdcard/wlan.ini", &sb) != 0) { + if ((stat("/sdcard/wlan.ini", &sb) != 0) && (stat("/sdcard/network.ini", &sb) != 0)) + { LogFile.WriteToFile(ESP_LOG_ERROR, TAG, "Folder/file check: File /wlan.ini not found"); bRetval = false; } /* check if file exists: config.ini */ - if (stat("/sdcard/config/config.ini", &sb) != 0) { + if (stat("/sdcard/config/config.ini", &sb) != 0) + { LogFile.WriteToFile(ESP_LOG_ERROR, TAG, "Folder/file check: File /config/config.ini not found"); bRetval = false; } /* check if file exists: index.html */ - if ((stat("/sdcard/html/index.html", &sb) != 0) && (stat("/sdcard/html/index.html.gz", &sb) != 0)) { + if ((stat("/sdcard/html/index.html", &sb) != 0) && (stat("/sdcard/html/index.html.gz", &sb) != 0)) + { LogFile.WriteToFile(ESP_LOG_ERROR, TAG, "Folder/file check: File /html/index.html not found"); bRetval = false; } + /* check if file exists: overview.html */ + if ((stat("/sdcard/html/overview.html", &sb) != 0) && (stat("/sdcard/html/overview.html.gz", &sb) != 0)) + { + LogFile.WriteToFile(ESP_LOG_ERROR, TAG, "Folder/file check: File /html/overview.html not found"); + bRetval = false; + } + /* check if file exists: ota.html */ - if ((stat("/sdcard/html/ota_page.html", &sb) != 0) && (stat("/sdcard/html/ota_page.html.gz", &sb) != 0)) { + if ((stat("/sdcard/html/ota_page.html", &sb) != 0) && (stat("/sdcard/html/ota_page.html.gz", &sb) != 0)) + { LogFile.WriteToFile(ESP_LOG_ERROR, TAG, "Folder/file check: File /html/ota.html not found"); bRetval = false; } /* check if file exists: log.html */ - if ((stat("/sdcard/html/log.html", &sb) != 0) && (stat("/sdcard/html/log.html.gz", &sb) != 0)) { + if ((stat("/sdcard/html/log.html", &sb) != 0) && (stat("/sdcard/html/log.html.gz", &sb) != 0)) + { LogFile.WriteToFile(ESP_LOG_ERROR, TAG, "Folder/file check: File /html/log.html not found"); bRetval = false; } /* check if file exists: common.js */ - if ((stat("/sdcard/html/common.js", &sb) != 0) && (stat("/sdcard/html/common.js.gz", &sb) != 0)) { + if ((stat("/sdcard/html/common.js", &sb) != 0) && (stat("/sdcard/html/common.js.gz", &sb) != 0)) + { LogFile.WriteToFile(ESP_LOG_ERROR, TAG, "Folder/file check: File /html/common.js not found"); bRetval = false; } - /* check if file exists: version.txt */ - if (stat("/sdcard/html/version.txt", &sb) != 0) { - LogFile.WriteToFile(ESP_LOG_ERROR, TAG, "Folder/file check: File /html/version.txt not found"); + /* check if file exists: readconfigcommon.js */ + if ((stat("/sdcard/html/readconfigcommon.js", &sb) != 0) && (stat("/sdcard/html/readconfigcommon.js.gz", &sb) != 0)) + { + LogFile.WriteToFile(ESP_LOG_ERROR, TAG, "Folder/file check: File /html/readconfigcommon.js not found"); bRetval = false; } - if (bRetval) { + /* check if file exists: readconfigparam.js */ + if ((stat("/sdcard/html/readconfigparam.js", &sb) != 0) && (stat("/sdcard/html/readconfigparam.js.gz", &sb) != 0)) + { + LogFile.WriteToFile(ESP_LOG_ERROR, TAG, "Folder/file check: File /html/readconfigparam.js not found"); + bRetval = false; + } + + /* check if file exists: jquery-3.6.0.min.js */ + if ((stat("/sdcard/html/jquery-3.6.0.min.js", &sb) != 0) && (stat("/sdcard/html/jquery-3.6.0.min.js.gz", &sb) != 0)) + { + LogFile.WriteToFile(ESP_LOG_ERROR, TAG, "Folder/file check: File /html/jquery-3.6.0.min.js not found"); + bRetval = false; + } + + /* check if file exists: firework.js */ + if ((stat("/sdcard/html/firework.js", &sb) != 0) && (stat("/sdcard/html/firework.js.gz", &sb) != 0)) + { + LogFile.WriteToFile(ESP_LOG_ERROR, TAG, "Folder/file check: File /html/firework.js not found"); + bRetval = false; + } + + /* check if file exists: version.txt */ + if (stat("/sdcard/html/version.txt", &sb) != 0) + { + LogFile.WriteToFile(ESP_LOG_ERROR, TAG, "Folder/file check: File /html/version.txt not found"); + // bRetval = false; + } + + if (bRetval) + { LogFile.WriteToFile(ESP_LOG_INFO, TAG, "Folder/file presence check successful"); } - + return bRetval; } diff --git a/code/components/jomjol_image_proc/CImageBasis.h b/code/components/jomjol_image_proc/CImageBasis.h index 0f0165be..d50311c8 100644 --- a/code/components/jomjol_image_proc/CImageBasis.h +++ b/code/components/jomjol_image_proc/CImageBasis.h @@ -14,7 +14,7 @@ #include "../stb/stb_image.h" #include "../stb/stb_image_write.h" #include "../stb/deprecated/stb_image_resize.h" -// #include "../stb/stb_image_resize.h" +// #include "../stb/stb_image_resize2.h" #include "esp_heap_caps.h" diff --git a/code/components/jomjol_image_proc/make_stb.cpp b/code/components/jomjol_image_proc/make_stb.cpp index 5093db7f..c4a66782 100644 --- a/code/components/jomjol_image_proc/make_stb.cpp +++ b/code/components/jomjol_image_proc/make_stb.cpp @@ -25,4 +25,4 @@ #define STB_IMAGE_RESIZE_IMPLEMENTATION #include "../stb/deprecated/stb_image_resize.h" -// #include "../stb/stb_image_resize.h" +// #include "../stb/stb_image_resize2.h" diff --git a/code/components/jomjol_network/network_init.cpp b/code/components/jomjol_network/network_init.cpp index fa1263c3..08fb293d 100644 --- a/code/components/jomjol_network/network_init.cpp +++ b/code/components/jomjol_network/network_init.cpp @@ -56,7 +56,15 @@ esp_err_t init_network(void) // Read Network parameter and start it // ******************************************** - int iNetworkStatus = LoadNetworkFromFile(NETWORK_CONFIG_FILE); + int iNetworkStatus = -1; + if (file_exists(WLAN_CONFIG_FILE)) + { + iNetworkStatus = LoadNetworkFromFile(WLAN_CONFIG_FILE); + } + else + { + iNetworkStatus = LoadNetworkFromFile(NETWORK_CONFIG_FILE); + } // Network config available (0) or SSID/password not configured (-2) if (file_exists(CONFIG_FILE) && ((iNetworkStatus == 0) || (iNetworkStatus == -2))) @@ -191,7 +199,7 @@ esp_err_t init_network(void) return ESP_OK; } } - // network.ini not available (-1) and config.ini not available + // wlan.ini not available (-1) and config.ini not available else { network_config.connection_type = NETWORK_CONNECTION_WIFI_AP_SETUP; diff --git a/code/components/jomjol_network/read_network_config.cpp b/code/components/jomjol_network/read_network_config.cpp index 682c618a..125cf343 100644 --- a/code/components/jomjol_network/read_network_config.cpp +++ b/code/components/jomjol_network/read_network_config.cpp @@ -244,7 +244,6 @@ bool ChangeHostName(std::string filename, std::string _newhostname) filename = format_filename(filename); FILE *pFile = fopen(filename.c_str(), "r"); - if (pFile == NULL) { LogFile.WriteToFile(ESP_LOG_ERROR, TAG, "ChangeHostName: unable to open wlan.ini (read)"); @@ -338,7 +337,6 @@ bool ChangeRSSIThreshold(std::string filename, int _newrssithreshold) filename = format_filename(filename); FILE *pFile = fopen(filename.c_str(), "r"); - if (pFile == NULL) { LogFile.WriteToFile(ESP_LOG_ERROR, TAG, "ChangeRSSIThreshold: unable to open wlan.ini (read)"); @@ -435,7 +433,6 @@ esp_err_t GetAuthWebUIConfig(std::string filename) { filename = format_filename(filename); FILE *pFile = fopen(filename.c_str(), "r"); - if (pFile == NULL) { LogFile.WriteToFile(ESP_LOG_ERROR, TAG, "GetAuthWebUIConfig: unable to open wlan.ini (read)"); diff --git a/code/components/jomjol_network/read_network_config.h b/code/components/jomjol_network/read_network_config.h index 6702f4b0..bffcaaf5 100644 --- a/code/components/jomjol_network/read_network_config.h +++ b/code/components/jomjol_network/read_network_config.h @@ -16,7 +16,7 @@ struct network_config_t std::string eapid = ""; std::string username = ""; std::string password = ""; - std::string hostname = "watermeter"; // Default: watermeter + std::string hostname = "watermeter"; std::string ipaddress = ""; std::string gateway = ""; std::string netmask = ""; diff --git a/code/components/jomjol_network/server_remote.cpp b/code/components/jomjol_network/server_remote.cpp index 3c2e4237..c6774a35 100644 --- a/code/components/jomjol_network/server_remote.cpp +++ b/code/components/jomjol_network/server_remote.cpp @@ -42,7 +42,7 @@ void remote_send_http_response(httpd_req_t *req) message += "Please follow the below instructions.

"; httpd_resp_send_chunk(req, message.c_str(), strlen(message.c_str())); - is_wlan_ini = file_exists(NETWORK_CONFIG_FILE); + is_wlan_ini = (file_exists(WLAN_CONFIG_FILE) || file_exists(NETWORK_CONFIG_FILE)); if (!is_config_ini) { @@ -65,6 +65,7 @@ void remote_send_http_response(httpd_req_t *req) message += "document.getElementById(\"doUpdate\").disabled = true;}"; message += ""; httpd_resp_send_chunk(req, message.c_str(), strlen(message.c_str())); + return; } @@ -83,6 +84,7 @@ void remote_send_http_response(httpd_req_t *req) message += "api = \"/config?\"+\"ssid=\"+document.getElementById(\"ssid\").value+\"&pwd=\"+document.getElementById(\"password\").value;"; message += "fetch(api);await new Promise(resolve => setTimeout(resolve, 1000));location.reload();}"; httpd_resp_send_chunk(req, message.c_str(), strlen(message.c_str())); + return; } @@ -100,6 +102,7 @@ esp_err_t remote_test_handler(httpd_req_t *req) { remote_send_http_response(req); httpd_resp_send_chunk(req, NULL, 0); + return ESP_OK; } @@ -107,25 +110,25 @@ esp_err_t remote_reboot_handler(httpd_req_t *req) { LogFile.WriteToFile(ESP_LOG_INFO, TAG, "Trigger reboot due to firmware update."); doRebootOTA(); + return ESP_OK; } esp_err_t remote_config_ini_handler(httpd_req_t *req) { LogFile.WriteToFile(ESP_LOG_DEBUG, TAG, "config_ini_handler"); + char _query[400]; char _valuechar[100]; - std::string fn = "/sdcard/firmware/"; - std::string _task = ""; - std::string ssid = ""; - std::string pwd = ""; - std::string hn = ""; // hostname - std::string ip = ""; - std::string gw = ""; // gateway - std::string nm = ""; // netmask - std::string dns = ""; - std::string rssithreshold = ""; // rssi threshold for WIFI roaming - std::string text = ""; + + std::string _ssid = ""; + std::string _pwd = ""; + std::string _hostname = ""; + std::string _ip = ""; + std::string _gateway = ""; + std::string _netmask = ""; + std::string _dns = ""; + std::string _rssithreshold = ""; // rssi threshold for WIFI roaming if (httpd_req_get_url_query_str(req, _query, 400) == ESP_OK) { @@ -134,150 +137,150 @@ esp_err_t remote_config_ini_handler(httpd_req_t *req) if (httpd_query_key_value(_query, "ssid", _valuechar, 100) == ESP_OK) { ESP_LOGD(TAG, "ssid is found: %s", _valuechar); - ssid = url_decode(std::string(_valuechar)); + _ssid = url_decode(std::string(_valuechar)); } if (httpd_query_key_value(_query, "pwd", _valuechar, 100) == ESP_OK) { ESP_LOGD(TAG, "pwd is found: %s", _valuechar); - pwd = url_decode(std::string(_valuechar)); + _pwd = url_decode(std::string(_valuechar)); } if (httpd_query_key_value(_query, "ssid", _valuechar, 100) == ESP_OK) { ESP_LOGD(TAG, "ssid is found: %s", _valuechar); - ssid = url_decode(std::string(_valuechar)); + _ssid = url_decode(std::string(_valuechar)); } if (httpd_query_key_value(_query, "hn", _valuechar, 100) == ESP_OK) { ESP_LOGD(TAG, "hostname is found: %s", _valuechar); - hn = url_decode(std::string(_valuechar)); + _hostname = url_decode(std::string(_valuechar)); } if (httpd_query_key_value(_query, "ip", _valuechar, 100) == ESP_OK) { ESP_LOGD(TAG, "ip is found: %s", _valuechar); - ip = url_decode(std::string(_valuechar)); + _ip = url_decode(std::string(_valuechar)); } if (httpd_query_key_value(_query, "gw", _valuechar, 100) == ESP_OK) { ESP_LOGD(TAG, "gateway is found: %s", _valuechar); - gw = url_decode(std::string(_valuechar)); + _gateway = url_decode(std::string(_valuechar)); } if (httpd_query_key_value(_query, "nm", _valuechar, 100) == ESP_OK) { ESP_LOGD(TAG, "netmask is found: %s", _valuechar); - nm = url_decode(std::string(_valuechar)); + _netmask = url_decode(std::string(_valuechar)); } if (httpd_query_key_value(_query, "dns", _valuechar, 100) == ESP_OK) { ESP_LOGD(TAG, "dns is found: %s", _valuechar); - dns = url_decode(std::string(_valuechar)); + _dns = url_decode(std::string(_valuechar)); } if (httpd_query_key_value(_query, "rssithreshold", _valuechar, 100) == ESP_OK) { ESP_LOGD(TAG, "rssithreshold is found: %s", _valuechar); - rssithreshold = url_decode(std::string(_valuechar)); + _rssithreshold = url_decode(std::string(_valuechar)); } } - FILE *configfilehandle = fopen(NETWORK_CONFIG_FILE, "w"); + FILE *pFile = fopen(NETWORK_CONFIG_FILE, "w"); - text = ";++++++++++++++++++++++++++++++++++\n"; + std::string text = ";++++++++++++++++++++++++++++++++++\n"; text += "; AI on the edge - WLAN configuration\n"; text += "; ssid: Name of WLAN network (mandatory), e.g. \"WLAN-SSID\"\n"; text += "; password: Password of WLAN network (mandatory), e.g. \"PASSWORD\"\n\n"; - fputs(text.c_str(), configfilehandle); + fputs(text.c_str(), pFile); - if (ssid.length()) + if (_ssid.length()) { - ssid = "ssid = \"" + ssid + "\"\n"; + _ssid = "ssid = \"" + _ssid + "\"\n"; } else { - ssid = "ssid = \"\"\n"; + _ssid = "ssid = \"\"\n"; } - fputs(ssid.c_str(), configfilehandle); + fputs(_ssid.c_str(), pFile); - if (pwd.length()) + if (_pwd.length()) { - pwd = "password = \"" + pwd + "\"\n"; + _pwd = "password = \"" + _pwd + "\"\n"; } else { - pwd = "password = \"\"\n"; + _pwd = "password = \"\"\n"; } - fputs(pwd.c_str(), configfilehandle); + fputs(_pwd.c_str(), pFile); text = "\n;++++++++++++++++++++++++++++++++++\n"; text += "; Hostname: Name of device in network\n"; text += "; This parameter can be configured via WebUI configuration\n"; text += "; Default: \"watermeter\", if nothing is configured\n\n"; - fputs(text.c_str(), configfilehandle); + fputs(text.c_str(), pFile); - if (hn.length()) + if (_hostname.length()) { - hn = "hostname = \"" + hn + "\"\n"; + _hostname = "hostname = \"" + _hostname + "\"\n"; } else { - hn = ";hostname = \"watermeter\"\n"; + _hostname = ";hostname = \"watermeter\"\n"; } - fputs(hn.c_str(), configfilehandle); + fputs(_hostname.c_str(), pFile); text = "\n;++++++++++++++++++++++++++++++++++\n"; text += "; Fixed IP: If you like to use fixed IP instead of DHCP (default), the following\n"; text += "; parameters needs to be configured: ip, gateway, netmask are mandatory, dns optional\n\n"; - fputs(text.c_str(), configfilehandle); + fputs(text.c_str(), pFile); - if (ip.length()) + if (_ip.length()) { - ip = "ip = \"" + ip + "\"\n"; + _ip = "ip = \"" + _ip + "\"\n"; } else { - ip = ";ip = \"xxx.xxx.xxx.xxx\"\n"; + _ip = ";ip = \"xxx.xxx.xxx.xxx\"\n"; } - fputs(ip.c_str(), configfilehandle); + fputs(_ip.c_str(), pFile); - if (gw.length()) + if (_gateway.length()) { - gw = "gateway = \"" + gw + "\"\n"; + _gateway = "gateway = \"" + _gateway + "\"\n"; } else { - gw = ";gateway = \"xxx.xxx.xxx.xxx\"\n"; + _gateway = ";gateway = \"xxx.xxx.xxx.xxx\"\n"; } - fputs(gw.c_str(), configfilehandle); + fputs(_gateway.c_str(), pFile); - if (nm.length()) + if (_netmask.length()) { - nm = "netmask = \"" + nm + "\"\n"; + _netmask = "netmask = \"" + _netmask + "\"\n"; } else { - nm = ";netmask = \"xxx.xxx.xxx.xxx\"\n"; + _netmask = ";netmask = \"xxx.xxx.xxx.xxx\"\n"; } - fputs(nm.c_str(), configfilehandle); + fputs(_netmask.c_str(), pFile); text = "\n;++++++++++++++++++++++++++++++++++\n"; text += "; DNS server (optional, if no DNS is configured, gateway address will be used)\n\n"; - fputs(text.c_str(), configfilehandle); + fputs(text.c_str(), pFile); - if (dns.length()) + if (_dns.length()) { - dns = "dns = \"" + dns + "\"\n"; + _dns = "dns = \"" + _dns + "\"\n"; } else { - dns = ";dns = \"xxx.xxx.xxx.xxx\"\n"; + _dns = ";dns = \"xxx.xxx.xxx.xxx\"\n"; } - fputs(dns.c_str(), configfilehandle); + fputs(_dns.c_str(), pFile); text = "\n;++++++++++++++++++++++++++++++++++\n"; text += "; WIFI Roaming:\n"; @@ -288,20 +291,20 @@ esp_err_t remote_config_ini_handler(httpd_req_t *req) text += "; RSSI Threshold for client requested roaming query (RSSI < RSSIThreshold)\n"; text += "; Note: This parameter can be configured via WebUI configuration\n"; text += "; Default: 0 = Disable client requested roaming query\n\n"; - fputs(text.c_str(), configfilehandle); + fputs(text.c_str(), pFile); - if (rssithreshold.length()) + if (_rssithreshold.length()) { - rssithreshold = "RSSIThreshold = " + rssithreshold + "\n"; + _rssithreshold = "RSSIThreshold = " + _rssithreshold + "\n"; } else { - rssithreshold = "RSSIThreshold = 0\n"; + _rssithreshold = "RSSIThreshold = 0\n"; } - fputs(rssithreshold.c_str(), configfilehandle); + fputs(_rssithreshold.c_str(), pFile); - fflush(configfilehandle); - fclose(configfilehandle); + fflush(pFile); + fclose(pFile); std::string zw = "ota without parameter - should not be the case!"; httpd_resp_set_hdr(req, "Access-Control-Allow-Origin", "*"); @@ -325,7 +328,6 @@ esp_err_t remote_upload_post_handler(httpd_req_t *req) LogFile.WriteToFile(ESP_LOG_DEBUG, TAG, "remote_upload_post_handler"); char filepath[FILE_PATH_MAX]; - FILE *fd = NULL; const char *filename = get_path_from_uri(filepath, "/sdcard", req->uri + sizeof("/upload") - 1, sizeof(filepath)); if (!filename) @@ -338,8 +340,8 @@ esp_err_t remote_upload_post_handler(httpd_req_t *req) delete_file(std::string(filepath)); - fd = fopen(filepath, "w"); - if (!fd) + FILE *pFile = fopen(filepath, "w"); + if (!pFile) { ESP_LOGE(TAG, "Failed to create file: %s", filepath); httpd_resp_send_err(req, HTTPD_500_INTERNAL_SERVER_ERROR, "Failed to create file"); @@ -365,7 +367,7 @@ esp_err_t remote_upload_post_handler(httpd_req_t *req) continue; } - fclose(fd); + fclose(pFile); unlink(filepath); ESP_LOGE(TAG, "File reception failed!"); @@ -373,9 +375,9 @@ esp_err_t remote_upload_post_handler(httpd_req_t *req) return ESP_FAIL; } - if (received && (received != fwrite(buf, 1, received, fd))) + if (received && (received != fwrite(buf, 1, received, pFile))) { - fclose(fd); + fclose(pFile); unlink(filepath); ESP_LOGE(TAG, "File write failed!"); @@ -386,13 +388,13 @@ esp_err_t remote_upload_post_handler(httpd_req_t *req) remaining -= received; } - fclose(fd); + fclose(pFile); is_config_ini = true; - FILE *pfile = fopen("/sdcard/update.txt", "w"); - std::string _s_zw = "/sdcard" + std::string(filename); - fwrite(_s_zw.c_str(), strlen(_s_zw.c_str()), 1, pfile); - fclose(pfile); + pFile = fopen("/sdcard/update.txt", "w"); + std::string temp_string = "/sdcard" + std::string(filename); + fwrite(temp_string.c_str(), strlen(temp_string.c_str()), 1, pFile); + fclose(pFile); ESP_LOGI(TAG, "File reception complete"); httpd_resp_set_hdr(req, "Location", "/test"); @@ -424,6 +426,7 @@ httpd_handle_t start_remote_webserver(void) } ESP_LOGI(TAG, "Error starting ap server!"); + return NULL; } @@ -435,27 +438,27 @@ void stop_remote_webserver(httpd_handle_t server) httpd_handle_t remote_webserver_register_uri(httpd_handle_t server) { httpd_uri_t reboot_handle = { - .uri = "/reboot", // Match all URIs of type /path/to/file + .uri = "/reboot", .method = HTTP_GET, .handler = APPLY_BASIC_AUTH_FILTER(remote_reboot_handler), - .user_ctx = NULL // Pass server data as context + .user_ctx = NULL, }; httpd_register_uri_handler(server, &reboot_handle); httpd_uri_t config_ini_handle = { - .uri = "/config", // Match all URIs of type /path/to/file + .uri = "/config", .method = HTTP_GET, .handler = APPLY_BASIC_AUTH_FILTER(remote_config_ini_handler), - .user_ctx = NULL // Pass server data as context + .user_ctx = NULL, }; httpd_register_uri_handler(server, &config_ini_handle); /* URI handler for uploading files to server */ httpd_uri_t file_uploadAP = { - .uri = "/upload/*", // Match all URIs of type /upload/path/to/file + .uri = "/upload/*", .method = HTTP_POST, .handler = APPLY_BASIC_AUTH_FILTER(remote_upload_post_handler), - .user_ctx = NULL // Pass server data as context + .user_ctx = NULL, }; httpd_register_uri_handler(server, &file_uploadAP); @@ -463,7 +466,8 @@ httpd_handle_t remote_webserver_register_uri(httpd_handle_t server) .uri = "*", .method = HTTP_GET, .handler = APPLY_BASIC_AUTH_FILTER(remote_test_handler), - .user_ctx = NULL}; + .user_ctx = NULL, + }; httpd_register_uri_handler(server, &test_uri); return NULL; diff --git a/code/include/defines.h b/code/include/defines.h index 50146adc..52cd6598 100644 --- a/code/include/defines.h +++ b/code/include/defines.h @@ -69,7 +69,8 @@ //ClassFlowControll + Main + SoftAP - #define NETWORK_CONFIG_FILE "/sdcard/wlan.ini" + #define WLAN_CONFIG_FILE "/sdcard/wlan.ini" + #define NETWORK_CONFIG_FILE "/sdcard/network.ini" //main diff --git a/code/main/version.h b/code/main/version.h index abea7563..a62c067e 100644 --- a/code/main/version.h +++ b/code/main/version.h @@ -5,10 +5,10 @@ // into the library by the version.cmake script extern "C" { - extern const char* GIT_TAG; - extern const char* GIT_REV; - extern const char* GIT_BRANCH; - extern const char* BUILD_TIME; + extern const char *GIT_TAG; + extern const char *GIT_REV; + extern const char *GIT_BRANCH; + extern const char *BUILD_TIME; } #include @@ -17,34 +17,37 @@ extern "C" #include #include - -const char* build_time(void) +const char *build_time(void) { return BUILD_TIME; } -const char* libfive_git_version(void) +const char *libfive_git_version(void) { return GIT_TAG; } -const char* libfive_git_revision(void) +const char *libfive_git_revision(void) { return GIT_REV; } -const char* libfive_git_branch(void) +const char *libfive_git_branch(void) { return GIT_BRANCH; } - -std::string getFwVersion(void) { +std::string getFwVersion(void) +{ std::string buf; - if (std::string(GIT_TAG) == "") { // Tag not set, show branch + if (std::string(GIT_TAG) == "") + { + // Tag not set, show branch buf = "Development-Branch: " + std::string(GIT_BRANCH); } - else { // Tag is set, ignore branch + else + { + // Tag is set, ignore branch buf = "Release: " + std::string(GIT_TAG); } buf = buf + " (Commit: " + std::string(GIT_REV) + ")"; @@ -52,14 +55,16 @@ std::string getFwVersion(void) { return buf; } -std::string getHTMLversion(void){ - char buf[100]="?\0"; - FILE* pFile; +std::string getHTMLversion(void) +{ + char buf[100] = "?\0"; string fn = format_filename("/sdcard/html/version.txt"); - pFile = fopen(fn.c_str(), "r"); + FILE *pFile = fopen(fn.c_str(), "r"); if (pFile == NULL) + { return std::string(buf); + } fgets(buf, sizeof(buf), pFile); // Line 1: Version fclose(pFile); @@ -70,14 +75,16 @@ std::string getHTMLversion(void){ return value; } -std::string getHTMLcommit(void){ - char buf[100]="?\0"; - FILE* pFile; +std::string getHTMLcommit(void) +{ + char buf[100] = "?\0"; string fn = format_filename("/sdcard/html/version.txt"); - pFile = fopen(fn.c_str(), "r"); + FILE *pFile = fopen(fn.c_str(), "r"); if (pFile == NULL) + { return std::string(buf); + } fgets(buf, sizeof(buf), pFile); // Line 1: Version -> ignored fgets(buf, sizeof(buf), pFile); // Line 2: Commit @@ -89,4 +96,4 @@ std::string getHTMLcommit(void){ return value; } -#endif // _VERSION_H \ No newline at end of file +#endif // _VERSION_H diff --git a/param-docs/parameter-pages/PostProcessing/SkipErrorMessage.md b/param-docs/parameter-pages/PostProcessing/NUMBER.SkipErrorMessage.md similarity index 100% rename from param-docs/parameter-pages/PostProcessing/SkipErrorMessage.md rename to param-docs/parameter-pages/PostProcessing/NUMBER.SkipErrorMessage.md diff --git a/sd-card/config/config.ini b/sd-card/config/config.ini index 7400109a..9691d49f 100644 --- a/sd-card/config/config.ini +++ b/sd-card/config/config.ini @@ -67,7 +67,7 @@ main.ana4 155 328 92 92 false [PostProcessing] PreValueUse = true PreValueAgeStartup = 720 -SkipErrorMessage = false +main.SkipErrorMessage = false main.AllowNegativeRates = false main.DecimalShift = 0 main.AnalogToDigitTransitionStart = 9.8 diff --git a/sd-card/demo/config.ini b/sd-card/demo/config.ini index 70d869d5..8f2b73f1 100644 --- a/sd-card/demo/config.ini +++ b/sd-card/demo/config.ini @@ -61,7 +61,7 @@ main.ana1 452 199 120 120 false [PostProcessing] PreValueUse = true PreValueAgeStartup = 720 -SkipErrorMessage = false +main.SkipErrorMessage = false main.AllowNegativeRates = true main.DecimalShift = 0 main.AnalogToDigitTransitionStart = 9.8 diff --git a/sd-card/html/backup.html b/sd-card/html/backup.html index cc3c57c1..dd8966cf 100644 --- a/sd-card/html/backup.html +++ b/sd-card/html/backup.html @@ -25,6 +25,11 @@ } + + + + + @@ -36,21 +41,15 @@


Restore Configuration

Use the File Server to upload individual files.

- - - - - - - - - + + \ No newline at end of file diff --git a/sd-card/html/data.html b/sd-card/html/data.html index 09f9885b..88b70092 100644 --- a/sd-card/html/data.html +++ b/sd-card/html/data.html @@ -46,33 +46,36 @@ font-size: 16px; } - + + + + +

Data Viewer

Today's latest data

- - + +



Loading data file, please wait...
- - - + + \ No newline at end of file diff --git a/sd-card/html/data_export.html b/sd-card/html/data_export.html index 786b868f..d6c71125 100644 --- a/sd-card/html/data_export.html +++ b/sd-card/html/data_export.html @@ -24,6 +24,12 @@ font-size: 16px; } + + + + + + @@ -34,10 +40,6 @@

- - - - - + \ No newline at end of file diff --git a/sd-card/html/edit_alignment.html b/sd-card/html/edit_alignment.html index a71ad3d4..da842337 100644 --- a/sd-card/html/edit_alignment.html +++ b/sd-card/html/edit_alignment.html @@ -99,6 +99,10 @@ + + + + @@ -181,9 +185,6 @@
- - - + + + + + @@ -178,10 +183,6 @@ The following settings are only used for easier setup, they are not persi - - - - + + + + + @@ -53,17 +58,15 @@
- - - - - + \ No newline at end of file diff --git a/sd-card/html/edit_config_template.html b/sd-card/html/edit_config_template.html index 3dd40f8f..fb904e2f 100644 --- a/sd-card/html/edit_config_template.html +++ b/sd-card/html/edit_config_template.html @@ -212,6 +212,7 @@ + @@ -929,8 +930,15 @@ $TOOLTIP_PostProcessing_PreValueAgeStartup + + + The following parameters are configurable individually for each number sequence: + + + + - + Skip Messages on Error @@ -939,14 +947,7 @@ - $TOOLTIP_PostProcessing_SkipErrorMessage - - - - - The following parameters are configurable individually for each number sequence: - - + $TOOLTIP_PostProcessing_NUMBER.SkipErrorMessage @@ -2173,7 +2174,6 @@ + + + + @@ -195,10 +199,6 @@ - - - - + + + + @@ -390,12 +394,8 @@ Reference Image:
- - - - - - - - + + + + + + + + + + + + - - - @@ -198,10 +199,10 @@ - - + \ No newline at end of file diff --git a/sd-card/html/index.html b/sd-card/html/index.html index 4d37444a..c5eb122e 100644 --- a/sd-card/html/index.html +++ b/sd-card/html/index.html @@ -252,11 +252,8 @@ } function HA_send_discovery_visibility() { - loadConfig(domainname); - ParseConfig(); - - category = getConfigCategory(); param = getConfigParameters(); + category = getConfigCategory(); if (category["MQTT"]["enabled"] && param["MQTT"]["HomeassistantDiscovery"].value1 == "true") { document.getElementById("ManualControl").style.display=""; diff --git a/sd-card/html/info.html b/sd-card/html/info.html index 8d027eb1..347d5fce 100644 --- a/sd-card/html/info.html +++ b/sd-card/html/info.html @@ -29,6 +29,7 @@ table { + @@ -107,7 +108,6 @@ table { - @@ -240,18 +240,13 @@ table {
-

Copyright

Copyright © 2020 - 2024 by Jomjol and others. - - - + + \ No newline at end of file diff --git a/sd-card/html/log.html b/sd-card/html/log.html index d5ae138d..82e5dab8 100644 --- a/sd-card/html/log.html +++ b/sd-card/html/log.html @@ -40,33 +40,34 @@ font-size: 16px; } - + + + +
- - + +



Loading logfile, please wait...
-
- + - - + + \ No newline at end of file diff --git a/sd-card/html/ota_page.html b/sd-card/html/ota_page.html index 8dc89bee..39edb61c 100644 --- a/sd-card/html/ota_page.html +++ b/sd-card/html/ota_page.html @@ -29,6 +29,7 @@ + @@ -56,12 +57,8 @@

Status: Idle

- - - - + \ No newline at end of file diff --git a/sd-card/html/overview.html b/sd-card/html/overview.html index ba6436ed..d206fb1d 100644 --- a/sd-card/html/overview.html +++ b/sd-card/html/overview.html @@ -65,10 +65,14 @@ } + + + + + - @@ -130,11 +134,6 @@
Value
- - - - - - + \ No newline at end of file diff --git a/sd-card/html/prevalue_set.html b/sd-card/html/prevalue_set.html index 8dafc6f1..dda6dcc6 100644 --- a/sd-card/html/prevalue_set.html +++ b/sd-card/html/prevalue_set.html @@ -59,6 +59,14 @@ } + + + + + + + + @@ -129,20 +137,10 @@ - - - - - - - - - - - + + \ No newline at end of file diff --git a/sd-card/html/readconfigcommon.js b/sd-card/html/readconfigcommon.js index eed7f95b..ba4c5e83 100644 --- a/sd-card/html/readconfigcommon.js +++ b/sd-card/html/readconfigcommon.js @@ -109,7 +109,7 @@ function FileCopyOnServer(_source, _target, _domainname = "") { try { xhttp.open("GET", url, false); xhttp.send(); - } catch (error) {} + } catch (error) { console.log(error); } } function FileDeleteOnServer(_filename, _domainname = "") { @@ -128,7 +128,7 @@ function FileDeleteOnServer(_filename, _domainname = "") { var url = _domainname + "/delete" + _filename; xhttp.open("POST", url, false); xhttp.send(); - } catch (error) {} + } catch (error) { console.log(error); } return okay; } @@ -155,11 +155,63 @@ function FileSendContent(_content, _filename, _domainname = "") { upload_path = _domainname + "/upload" + _filename; xhttp.open("POST", upload_path, false); xhttp.send(_content); - } catch (error) {} + } catch (error) { console.log(error); } return okay; } +function CopyReferenceToImgTmp(_domainname) { + for (index = 0; index < 2; ++index) { + _filenamevon = REFERENCES[index]["name"]; + _filenamenach = _filenamevon.replace("/config/", "/img_tmp/"); + FileDeleteOnServer(_filenamenach, _domainname); + FileCopyOnServer(_filenamevon, _filenamenach, _domainname); + + _filenamevon = _filenamevon.replace(".jpg", "_org.jpg"); + _filenamenach = _filenamenach.replace(".jpg", "_org.jpg"); + FileDeleteOnServer(_filenamenach, _domainname); + FileCopyOnServer(_filenamevon, _filenamenach, _domainname); + } +} + +function UpdateConfigReferences(_domainname){ + for (var index = 0; index < 2; ++index) { + _filenamenach = REFERENCES[index]["name"]; + _filenamevon = _filenamenach.replace("/config/", "/img_tmp/"); + FileDeleteOnServer(_filenamenach, _domainname); + FileCopyOnServer(_filenamevon, _filenamenach, _domainname); + + _filenamenach = _filenamenach.replace(".jpg", "_org.jpg"); + _filenamevon = _filenamevon.replace(".jpg", "_org.jpg"); + FileDeleteOnServer(_filenamenach, _domainname); + FileCopyOnServer(_filenamevon, _filenamenach, _domainname); + } +} + +function UpdateConfigReference(_anzneueref, _domainname){ + var index = 0; + + if (_anzneueref == 1) { + index = 0; + } + + else if (_anzneueref == 2) { + index = 1; + } + + _filenamenach = REFERENCES[index]["name"]; + _filenamevon = _filenamenach.replace("/config/", "/img_tmp/"); + + FileDeleteOnServer(_filenamenach, _domainname); + FileCopyOnServer(_filenamevon, _filenamenach, _domainname); + + _filenamenach = _filenamenach.replace(".jpg", "_org.jpg"); + _filenamevon = _filenamevon.replace(".jpg", "_org.jpg"); + + FileDeleteOnServer(_filenamenach, _domainname); + FileCopyOnServer(_filenamevon, _filenamenach, _domainname); +} + function MakeTempRefImage(_filename, _enhance, _domainname){ var filename = _filename["name"].replace("/config/", "/img_tmp/"); @@ -174,7 +226,7 @@ function MakeTempRefImage(_filename, _enhance, _domainname){ try { xhttp.open("GET", url, false); xhttp.send(); - } catch (error){} + } catch (error){ console.log(error); } if (xhttp.responseText == "CutImage Done") { if (_enhance == true) { @@ -230,7 +282,7 @@ function decryptConfigPwOnSD(_domainname = getDomainname()) { try { xhttp.open("GET", url, false); xhttp.send(); - } catch (error) {} + } catch (error) { console.log(error); } if (xhttp.responseText == "decrypted") { return true; @@ -247,7 +299,7 @@ function decryptWifiPwOnSD(_domainname = getDomainname()) { try { xhttp.open("GET", url, false); xhttp.send(); - } catch (error) {} + } catch (error) { console.log(error); } if (xhttp.responseText == "decrypted") { return true; diff --git a/sd-card/html/readconfigparam.js b/sd-card/html/readconfigparam.js index 6ebf9d39..b48d61ab 100644 --- a/sd-card/html/readconfigparam.js +++ b/sd-card/html/readconfigparam.js @@ -1,10 +1,24 @@ var config_gesamt = ""; -var config_split = []; +var config_gesamt_temp = ""; + +var config_split = ""; +var config_split_temp = ""; + var param = []; -var category; -var ref = new Array(2); +var param_temp = []; + +var namenumberslist = ""; +var datalist = ""; +var tflitelist = ""; + +var category = []; +var category_temp = []; + var NUMBERS = new Array(0); +var NUMBERS_temp = new Array(0); + var REFERENCES = new Array(0); +var REFERENCES_temp = new Array(0); var domainname_for_testing = ""; @@ -31,6 +45,10 @@ function getConfig() { return config_gesamt; } +function getConfigCategory() { + return category; +} + function loadConfig(_domainname) { config_gesamt = ""; @@ -48,22 +66,7 @@ function loadConfig(_domainname) { try { xhttp.open("GET", url, false); xhttp.send(); - } catch (error) {} - - return true; -} - -function loadConfig1(_domainname) { - var xhttp = new XMLHttpRequest(); - - try { - url = _domainname + '/fileserver/config/config.ini'; - xhttp.open("GET", url, false); - xhttp.send(); - config_gesamt = xhttp.responseText; - } catch (error) {} - - return true; + } catch (error) { console.log(error); } } function SaveConfigToServer(_domainname){ @@ -86,7 +89,7 @@ function SaveConfigToServer(_domainname){ function getNUMBERSList() { _domainname = getDomainname(); - var namenumberslist = ""; + namenumberslist = ""; var xhttp = new XMLHttpRequest(); @@ -103,7 +106,7 @@ function getNUMBERSList() { url = _domainname + '/editflow?task=namenumbers'; xhttp.open("GET", url, false); xhttp.send(); - } catch (error) {} + } catch (error) { console.log(error); } namenumberslist = namenumberslist.split("\t"); @@ -129,7 +132,7 @@ function getDATAList() { url = _domainname + '/editflow?task=data'; xhttp.open("GET", url, false); xhttp.send(); - } catch (error) {} + } catch (error) { console.log(error); } datalist = datalist.split("\t"); datalist.pop(); @@ -139,7 +142,8 @@ function getDATAList() { } function getTFLITEList() { - _domainname = getDomainname(); + _domainname = getDomainname(); + tflitelist = ""; var xhttp = new XMLHttpRequest(); @@ -157,7 +161,7 @@ function getTFLITEList() { url = _domainname + '/editflow?task=tflite'; xhttp.open("GET", url, false); xhttp.send(); - } catch (error) {} + } catch (error) { console.log(error); } tflitelist = tflitelist.split("\t"); tflitelist.sort(); @@ -231,7 +235,7 @@ function ParseConfig() { category[catname]["enabled"] = false; category[catname]["found"] = false; param[catname] = new Object(); - ParamAddValue(param, catname, "Model"); + ParamAddValue(param, catname, "Model", 1, false, "/config/dig-cont_0712_s3_q.tflite"); ParamAddValue(param, catname, "CNNGoodThreshold", 1, false, "0.5"); ParamAddValue(param, catname, "ROIImagesLocation", 1, false, "/log/digit"); ParamAddValue(param, catname, "ROIImagesRetention", 1, false, "3"); @@ -241,7 +245,7 @@ function ParseConfig() { category[catname]["enabled"] = false; category[catname]["found"] = false; param[catname] = new Object(); - ParamAddValue(param, catname, "Model"); + ParamAddValue(param, catname, "Model", 1, false, "/config/ana-cont_1300_s2.tflite"); ParamAddValue(param, catname, "ROIImagesLocation", 1, false, "/log/analog"); ParamAddValue(param, catname, "ROIImagesRetention", 1, false, "3"); @@ -253,7 +257,7 @@ function ParseConfig() { // ParamAddValue(param, catname, "PreValueUse", 1, true, "true"); ParamAddValue(param, catname, "PreValueUse", 1, false, "true"); ParamAddValue(param, catname, "PreValueAgeStartup", 1, false, "720"); - ParamAddValue(param, catname, "SkipErrorMessage", 1, false, "false"); + ParamAddValue(param, catname, "SkipErrorMessage", 1, true, "false"); ParamAddValue(param, catname, "AllowNegativeRates", 1, true, "false"); ParamAddValue(param, catname, "DecimalShift", 1, true, "0"); ParamAddValue(param, catname, "AnalogToDigitTransitionStart", 1, true, "9.2"); @@ -378,12 +382,12 @@ function ParseConfig() { while (aktline < config_split.length){ for (var cat in category) { - zw = cat.toUpperCase(); - zw1 = "[" + zw + "]"; - zw2 = ";[" + zw + "]"; + var cat_temp = cat.toUpperCase(); + var cat_aktive = "[" + cat_temp + "]"; + var cat_inaktive = ";[" + cat_temp + "]"; - if ((config_split[aktline].trim().toUpperCase() == zw1) || (config_split[aktline].trim().toUpperCase() == zw2)) { - if (config_split[aktline].trim().toUpperCase() == zw1) { + if ((config_split[aktline].trim().toUpperCase() == cat_aktive) || (config_split[aktline].trim().toUpperCase() == cat_inaktive)) { + if (config_split[aktline].trim().toUpperCase() == cat_aktive) { category[cat]["enabled"] = true; } @@ -396,43 +400,6 @@ function ParseConfig() { aktline++; } - - // Make the downward compatiblity with DataLogging - if (category["DataLogging"]["found"] == false) { - category["DataLogging"]["found"] = true; - category["DataLogging"]["enabled"] = true; - - param["DataLogging"]["DataLogActive"]["found"] = true; - param["DataLogging"]["DataLogActive"]["enabled"] = true; - param["DataLogging"]["DataLogActive"]["value1"] = "true"; - - param["DataLogging"]["DataFilesRetention"]["found"] = true; - param["DataLogging"]["DataFilesRetention"]["enabled"] = true; - param["DataLogging"]["DataFilesRetention"]["value1"] = "3"; - } - - if (category["DataLogging"]["enabled"] == false) { - category["DataLogging"]["enabled"] = true - } - - if (param["DataLogging"]["DataLogActive"]["enabled"] == false && param["DataLogging"]["DataLogActive"]["value1"] == "") { - param["DataLogging"]["DataLogActive"]["found"] = true; - param["DataLogging"]["DataLogActive"]["enabled"] = true; - param["DataLogging"]["DataLogActive"]["value1"] = "true"; - } - - if (param["DataLogging"]["DataFilesRetention"]["enabled"] == false && param["DataLogging"]["DataFilesRetention"]["value1"] == "") { - param["DataLogging"]["DataFilesRetention"]["found"] = true; - param["DataLogging"]["DataFilesRetention"]["enabled"] = true; - param["DataLogging"]["DataFilesRetention"]["value1"] = "3"; - } - - // Downward compatibility: Create RSSIThreshold if not available - if (param["System"]["RSSIThreshold"]["found"] == false) { - param["System"]["RSSIThreshold"]["found"] = true; - param["System"]["RSSIThreshold"]["enabled"] = false; - param["System"]["RSSIThreshold"]["value1"] = "0"; - } } function ParamAddValue(param, _cat, _param, _anzParam = 1, _isNUMBER = false, _defaultValue = "", _checkRegExList = null) { @@ -444,6 +411,19 @@ function ParamAddValue(param, _cat, _param, _anzParam = 1, _isNUMBER = false, _d param[_cat][_param]["defaultValue"] = _defaultValue; param[_cat][_param]["Numbers"] = _isNUMBER; param[_cat][_param].checkRegExList = _checkRegExList; + + if (_isNUMBER) { + for (var _num in NUMBERS) { + for (var j = 1; j <= param[_cat][_param]["anzParam"]; ++j) { + NUMBERS[_num][_cat][_param]["value"+j] = _defaultValue; + } + } + } + else { + for (var j = 1; j <= param[_cat][_param]["anzParam"]; ++j) { + param[_cat][_param]["value"+j] = _defaultValue; + } + } }; function ParseConfigParamAll(_aktline, _catname) { @@ -503,25 +483,28 @@ function ParamExtractValueAll(_param, _linesplit, _catname, _aktline, _iscom) { if (_AktPara.toUpperCase() == paramname.toUpperCase()) { while (_linesplit.length <= _param[_catname][paramname]["anzParam"]) { - _linesplit.push(""); + // line contains no value, so the default value is loaded + _linesplit.push(_param[_catname][paramname]["defaultValue"]); } _param[_catname][paramname]["found"] = true; _param[_catname][paramname]["enabled"] = !_iscom; _param[_catname][paramname]["line"] = _aktline; - if (_param[_catname][paramname]["Numbers"] == true) { // möglicher Multiusage - abc = getNUMBERS(_linesplit[0]); - abc[_catname][paramname] = new Object; - abc[_catname][paramname]["found"] = true; - abc[_catname][paramname]["enabled"] = !_iscom; + if (_param[_catname][paramname]["Numbers"] == true) { + // möglicher Multiusage + var _numbers = getNUMBERS(_linesplit[0]); + _numbers[_catname][paramname] = new Object; + _numbers[_catname][paramname]["found"] = true; + _numbers[_catname][paramname]["enabled"] = !_iscom; for (var j = 1; j <= _param[_catname][paramname]["anzParam"]; ++j) { - abc[_catname][paramname]["value"+j] = _linesplit[j]; + _numbers[_catname][paramname]["value"+j] = _linesplit[j]; } - if (abc["name"] == "default") { - for (_num in NUMBERS) { // wert mit Default belegen + if (_numbers["name"] == "default") { + for (var _num in NUMBERS) { + // Assign value to default if (NUMBERS[_num][_catname][paramname]["found"] == false) { NUMBERS[_num][_catname][paramname]["found"] = true; NUMBERS[_num][_catname][paramname]["enabled"] = !_iscom; @@ -534,11 +517,7 @@ function ParamExtractValueAll(_param, _linesplit, _catname, _aktline, _iscom) { } } } - else { - _param[_catname][paramname]["found"] = true; - _param[_catname][paramname]["enabled"] = !_iscom; - _param[_catname][paramname]["line"] = _aktline; - + else { for (var j = 1; j <= _param[_catname][paramname]["anzParam"]; ++j) { _param[_catname][paramname]["value"+j] = _linesplit[j]; } @@ -547,184 +526,9 @@ function ParamExtractValueAll(_param, _linesplit, _catname, _aktline, _iscom) { } } -function getCamConfig() { - ParseConfig(); - - param["System"]["Tooltip"]["enabled"] = true; - param["Alignment"]["InitialRotate"]["enabled"] = true; - - param["TakeImage"]["WaitBeforeTakingPicture"]["enabled"] = true; - param["TakeImage"]["CamGainceiling"]["enabled"] = true; // Image gain (GAINCEILING_x2, x4, x8, x16, x32, x64 or x128) - param["TakeImage"]["CamQuality"]["enabled"] = true; // 0 - 63 - param["TakeImage"]["CamBrightness"]["enabled"] = true; // (-2 to 2) - set brightness - param["TakeImage"]["CamContrast"]["enabled"] = true; //-2 - 2 - param["TakeImage"]["CamSaturation"]["enabled"] = true; //-2 - 2 - param["TakeImage"]["CamSharpness"]["enabled"] = true; //-2 - 2 - param["TakeImage"]["CamAutoSharpness"]["enabled"] = true; //(1 or 0) - param["TakeImage"]["CamSpecialEffect"]["enabled"] = true; // 0 - 6 - param["TakeImage"]["CamWbMode"]["enabled"] = true; // 0 to 4 - if awb_gain enabled (0 - Auto, 1 - Sunny, 2 - Cloudy, 3 - Office, 4 - Home) - param["TakeImage"]["CamAwb"]["enabled"] = true; // white balance enable (0 or 1) - param["TakeImage"]["CamAwbGain"]["enabled"] = true; // Auto White Balance enable (0 or 1) - param["TakeImage"]["CamAec"]["enabled"] = true; // auto exposure off (1 or 0) - param["TakeImage"]["CamAec2"]["enabled"] = true; // automatic exposure sensor (0 or 1) - param["TakeImage"]["CamAeLevel"]["enabled"] = true; // auto exposure levels (-2 to 2) - param["TakeImage"]["CamAecValue"]["enabled"] = true; // set exposure manually (0-1200) - param["TakeImage"]["CamAgc"]["enabled"] = true; // auto gain off (1 or 0) - param["TakeImage"]["CamAgcGain"]["enabled"] = true; // set gain manually (0 - 30) - param["TakeImage"]["CamBpc"]["enabled"] = true; // black pixel correction - param["TakeImage"]["CamWpc"]["enabled"] = true; // white pixel correction - param["TakeImage"]["CamRawGma"]["enabled"] = true; // (1 or 0) - param["TakeImage"]["CamLenc"]["enabled"] = true; // lens correction (1 or 0) - param["TakeImage"]["CamHmirror"]["enabled"] = true; // (0 or 1) flip horizontally - param["TakeImage"]["CamVflip"]["enabled"] = true; // Invert image (0 or 1) - param["TakeImage"]["CamDcw"]["enabled"] = true; // downsize enable (1 or 0) - param["TakeImage"]["CamDenoise"]["enabled"] = true; // The OV2640 does not support it, OV3660 and OV5640 (0 to 8) - param["TakeImage"]["CamZoom"]["enabled"] = true; - param["TakeImage"]["CamZoomOffsetX"]["enabled"] = true; - param["TakeImage"]["CamZoomOffsetY"]["enabled"] = true; - param["TakeImage"]["CamZoomSize"]["enabled"] = true; - param["TakeImage"]["LEDIntensity"]["enabled"] = true; - - if (!param["System"]["Tooltip"]["found"]) { - param["System"]["Tooltip"]["found"] = true; - param["System"]["Tooltip"].value1 = 'true'; - } - - if (!param["Alignment"]["InitialRotate"]["found"]) { - param["Alignment"]["InitialRotate"]["found"] = true; - param["Alignment"]["InitialRotate"].value1 = 'false'; - } - - if (!param["TakeImage"]["WaitBeforeTakingPicture"]["found"]) { - param["TakeImage"]["WaitBeforeTakingPicture"]["found"] = true; - param["TakeImage"]["WaitBeforeTakingPicture"].value1 = '5'; - } - if (!param["TakeImage"]["CamGainceiling"]["found"]) { - param["TakeImage"]["CamGainceiling"]["found"] = true; - // param["TakeImage"]["CamGainceiling"].value1 = '2'; - param["TakeImage"]["CamGainceiling"].value1 = 'x8'; - } - if (!param["TakeImage"]["CamQuality"]["found"]) { - param["TakeImage"]["CamQuality"]["found"] = true; - param["TakeImage"]["CamQuality"].value1 = '10'; - } - if (!param["TakeImage"]["CamBrightness"]["found"]) { - param["TakeImage"]["CamBrightness"]["found"] = true; - param["TakeImage"]["CamBrightness"].value1 = '0'; - } - if (!param["TakeImage"]["CamContrast"]["found"]) { - param["TakeImage"]["CamContrast"]["found"] = true; - param["TakeImage"]["CamContrast"].value1 = '0'; - } - if (!param["TakeImage"]["CamSaturation"]["found"]) { - param["TakeImage"]["CamSaturation"]["found"] = true; - param["TakeImage"]["CamSaturation"].value1 = '0'; - } - if (!param["TakeImage"]["CamSharpness"]["found"]) { - param["TakeImage"]["CamSharpness"]["found"] = true; - param["TakeImage"]["CamSharpness"].value1 = '0'; - } - if (!param["TakeImage"]["CamAutoSharpness"]["found"]) { - param["TakeImage"]["CamAutoSharpness"]["found"] = true; - param["TakeImage"]["CamAutoSharpness"].value1 = 'false'; - } - if (!param["TakeImage"]["CamSpecialEffect"]["found"]) { - param["TakeImage"]["CamSpecialEffect"]["found"] = true; - param["TakeImage"]["CamSpecialEffect"].value1 = 'no_effect'; - } - if (!param["TakeImage"]["CamWbMode"]["found"]) { - param["TakeImage"]["CamWbMode"]["found"] = true; - param["TakeImage"]["CamWbMode"].value1 = 'auto'; - } - if (!param["TakeImage"]["CamAwb"]["found"]) { - param["TakeImage"]["CamAwb"]["found"] = true; - param["TakeImage"]["CamAwb"].value1 = 'true'; - } - if (!param["TakeImage"]["CamAwbGain"]["found"]) { - param["TakeImage"]["CamAwbGain"]["found"] = true; - param["TakeImage"]["CamAwbGain"].value1 = 'true'; - } - if (!param["TakeImage"]["CamAec"]["found"]) { - param["TakeImage"]["CamAec"]["found"] = true; - param["TakeImage"]["CamAec"].value1 = 'true'; - } - if (!param["TakeImage"]["CamAec2"]["found"]) { - param["TakeImage"]["CamAec2"]["found"] = true; - param["TakeImage"]["CamAec2"].value1 = 'true'; - } - if (!param["TakeImage"]["CamAeLevel"]["found"]) { - param["TakeImage"]["CamAeLevel"]["found"] = true; - param["TakeImage"]["CamAeLevel"].value1 = '2'; - } - if (!param["TakeImage"]["CamAecValue"]["found"]) { - param["TakeImage"]["CamAecValue"]["found"] = true; - param["TakeImage"]["CamAecValue"].value1 = '600'; - } - if (!param["TakeImage"]["CamAgc"]["found"]) { - param["TakeImage"]["CamAgc"]["found"] = true; - param["TakeImage"]["CamAgc"].value1 = 'true'; - } - if (!param["TakeImage"]["CamAgcGain"]["found"]) { - param["TakeImage"]["CamAgcGain"]["found"] = true; - param["TakeImage"]["CamAgcGain"].value1 = '8'; - } - if (!param["TakeImage"]["CamBpc"]["found"]) { - param["TakeImage"]["CamBpc"]["found"] = true; - param["TakeImage"]["CamBpc"].value1 = 'true'; - } - if (!param["TakeImage"]["CamWpc"]["found"]) { - param["TakeImage"]["CamWpc"]["found"] = true; - param["TakeImage"]["CamWpc"].value1 = 'true'; - } - if (!param["TakeImage"]["CamRawGma"]["found"]) { - param["TakeImage"]["CamRawGma"]["found"] = true; - param["TakeImage"]["CamRawGma"].value1 = 'true'; - } - if (!param["TakeImage"]["CamLenc"]["found"]) { - param["TakeImage"]["CamLenc"]["found"] = true; - param["TakeImage"]["CamLenc"].value1 = 'true'; - } - if (!param["TakeImage"]["CamHmirror"]["found"]) { - param["TakeImage"]["CamHmirror"]["found"] = true; - param["TakeImage"]["CamHmirror"].value1 = 'false'; - } - if (!param["TakeImage"]["CamVflip"]["found"]) { - param["TakeImage"]["CamVflip"]["found"] = true; - param["TakeImage"]["CamVflip"].value1 = 'false'; - } - if (!param["TakeImage"]["CamDcw"]["found"]) { - param["TakeImage"]["CamDcw"]["found"] = true; - param["TakeImage"]["CamDcw"].value1 = 'true'; - } - if (!param["TakeImage"]["CamDenoise"]["found"]) { - param["TakeImage"]["CamDenoise"]["found"] = true; - param["TakeImage"]["CamDenoise"].value1 = '0'; - } - if (!param["TakeImage"]["CamZoom"]["found"]) { - param["TakeImage"]["CamZoom"]["found"] = true; - param["TakeImage"]["CamZoom"].value1 = 'false'; - } - if (!param["TakeImage"]["CamZoomOffsetX"]["found"]) { - param["TakeImage"]["CamZoomOffsetX"]["found"] = true; - param["TakeImage"]["CamZoomOffsetX"].value1 = '0'; - } - if (!param["TakeImage"]["CamZoomOffsetY"]["found"]) { - param["TakeImage"]["CamZoomOffsetY"]["found"] = true; - param["TakeImage"]["CamZoomOffsetY"].value1 = '0'; - } - if (!param["TakeImage"]["CamZoomSize"]["found"]) { - param["TakeImage"]["CamZoomSize"]["found"] = true; - param["TakeImage"]["CamZoomSize"].value1 = '0'; - } - if (!param["TakeImage"]["LEDIntensity"]["found"]) { - param["TakeImage"]["LEDIntensity"]["found"] = true; - param["TakeImage"]["LEDIntensity"].value1 = '50'; - } - - return param; -} - function getConfigParameters() { + loadConfig(getDomainname()); + ParseConfig(getDomainname()); return param; } @@ -739,48 +543,54 @@ function WriteConfigININew() { config_split = new Array(0); for (var cat in param) { - text = "[" + cat + "]"; + var text_cat = "[" + cat + "]"; if (!category[cat]["enabled"]) { - text = ";" + text; + text_cat = ";" + text_cat; } - config_split.push(text); + config_split.push(text_cat); for (var name in param[cat]) { if (param[cat][name]["Numbers"]) { for (_num in NUMBERS) { - text = NUMBERS[_num]["name"] + "." + name; + var text_numbers = NUMBERS[_num]["name"] + "." + name; - var text = text + " =" + text_numbers = text_numbers + " =" for (var j = 1; j <= param[cat][name]["anzParam"]; ++j) { if (!(typeof NUMBERS[_num][cat][name]["value"+j] == 'undefined')) { - text = text + " " + NUMBERS[_num][cat][name]["value"+j]; + text_numbers = text_numbers + " " + NUMBERS[_num][cat][name]["value"+j]; + } + else { + text_numbers = text_numbers + " " + NUMBERS[_num][cat][name]["defaultValue"]; } } - if (!NUMBERS[_num][cat][name]["enabled"]) { - text = ";" + text; + if ((!category[cat]["enabled"]) || (!NUMBERS[_num][cat][name]["enabled"])) { + text_numbers = ";" + text_numbers; } - config_split.push(text); + config_split.push(text_numbers); } } else { - var text = name + " =" + var text_name = name + " =" for (var j = 1; j <= param[cat][name]["anzParam"]; ++j) { if (!(typeof param[cat][name]["value"+j] == 'undefined')) { - text = text + " " + param[cat][name]["value"+j]; + text_name = text_name + " " + param[cat][name]["value"+j]; + } + else { + text_name = text_name + " " + param[cat][name]["defaultValue"]; } } - if (!param[cat][name]["enabled"]) { - text = ";" + text; + if ((!category[cat]["enabled"]) || (!param[cat][name]["enabled"])) { + text_name = ";" + text_name; } - config_split.push(text); + config_split.push(text_name); } } @@ -788,13 +598,13 @@ function WriteConfigININew() { for (var _roi in NUMBERS) { if (NUMBERS[_roi]["digit"].length > 0) { for (var _roiddet in NUMBERS[_roi]["digit"]) { - text = NUMBERS[_roi]["name"] + "." + NUMBERS[_roi]["digit"][_roiddet]["name"]; - text = text + " " + NUMBERS[_roi]["digit"][_roiddet]["x"]; - text = text + " " + NUMBERS[_roi]["digit"][_roiddet]["y"]; - text = text + " " + NUMBERS[_roi]["digit"][_roiddet]["dx"]; - text = text + " " + NUMBERS[_roi]["digit"][_roiddet]["dy"]; - text = text + " " + NUMBERS[_roi]["digit"][_roiddet]["CCW"]; - config_split.push(text); + var text_digital = NUMBERS[_roi]["name"] + "." + NUMBERS[_roi]["digit"][_roiddet]["name"]; + text_digital = text_digital + " " + NUMBERS[_roi]["digit"][_roiddet]["x"]; + text_digital = text_digital + " " + NUMBERS[_roi]["digit"][_roiddet]["y"]; + text_digital = text_digital + " " + NUMBERS[_roi]["digit"][_roiddet]["dx"]; + text_digital = text_digital + " " + NUMBERS[_roi]["digit"][_roiddet]["dy"]; + text_digital = text_digital + " " + NUMBERS[_roi]["digit"][_roiddet]["CCW"]; + config_split.push(text_digital); } } } @@ -804,13 +614,13 @@ function WriteConfigININew() { for (var _roi in NUMBERS) { if (NUMBERS[_roi]["analog"].length > 0) { for (var _roiddet in NUMBERS[_roi]["analog"]) { - text = NUMBERS[_roi]["name"] + "." + NUMBERS[_roi]["analog"][_roiddet]["name"]; - text = text + " " + NUMBERS[_roi]["analog"][_roiddet]["x"]; - text = text + " " + NUMBERS[_roi]["analog"][_roiddet]["y"]; - text = text + " " + NUMBERS[_roi]["analog"][_roiddet]["dx"]; - text = text + " " + NUMBERS[_roi]["analog"][_roiddet]["dy"]; - text = text + " " + NUMBERS[_roi]["analog"][_roiddet]["CCW"]; - config_split.push(text); + var text_analog = NUMBERS[_roi]["name"] + "." + NUMBERS[_roi]["analog"][_roiddet]["name"]; + text_analog = text_analog + " " + NUMBERS[_roi]["analog"][_roiddet]["x"]; + text_analog = text_analog + " " + NUMBERS[_roi]["analog"][_roiddet]["y"]; + text_analog = text_analog + " " + NUMBERS[_roi]["analog"][_roiddet]["dx"]; + text_analog = text_analog + " " + NUMBERS[_roi]["analog"][_roiddet]["dy"]; + text_analog = text_analog + " " + NUMBERS[_roi]["analog"][_roiddet]["CCW"]; + config_split.push(text_analog); } } } @@ -818,10 +628,10 @@ function WriteConfigININew() { if (cat == "Alignment") { for (var _roi in REFERENCES) { - text = REFERENCES[_roi]["name"]; - text = text + " " + REFERENCES[_roi]["x"]; - text = text + " " + REFERENCES[_roi]["y"]; - config_split.push(text); + var text_alignment = REFERENCES[_roi]["name"]; + text_alignment = text_alignment + " " + REFERENCES[_roi]["x"]; + text_alignment = text_alignment + " " + REFERENCES[_roi]["y"]; + config_split.push(text_alignment); } } @@ -838,33 +648,6 @@ function isCommented(input) { } return [isComment, input]; -} - -function SaveConfigToServer(_domainname){ - // leere Zeilen am Ende löschen - var zw = config_split.length - 1; - - while (config_split[zw] == "") { - config_split.pop(); - } - - var config_gesamt = ""; - - for (var i = 0; i < config_split.length; ++i) - { - config_gesamt = config_gesamt + config_split[i] + "\n"; - } - - FileDeleteOnServer("/config/config.ini", _domainname); - FileSendContent(config_gesamt, "/config/config.ini", _domainname); -} - -function getConfig() { - return config_gesamt; -} - -function getConfigCategory() { - return category; } function ExtractROIs(_aktline, _type){ @@ -903,8 +686,9 @@ function getNUMBERS(_name, _type, _create = true) { } } - if (!_create) { // nicht gefunden und soll auch nicht erzeugt werden, ggf. geht eine NULL zurück - return _ret; + if (!_create) { + // nicht gefunden und soll auch nicht erzeugt werden, ggf. geht eine NULL zurück + return _ret; } if (_ret == -1) { @@ -931,7 +715,8 @@ function getNUMBERS(_name, _type, _create = true) { NUMBERS.push(_ret); } - if (typeof _type == 'undefined') { // muss schon existieren !!! - also erst nach Digits / Analog aufrufen + if (typeof _type == 'undefined') { + // muss schon existieren !!! - also erst nach Digits / Analog aufrufen return _ret; } @@ -942,66 +727,6 @@ function getNUMBERS(_name, _type, _create = true) { return neuroi; } -function CopyReferenceToImgTmp(_domainname) { - for (index = 0; index < 2; ++index) { - _filenamevon = REFERENCES[index]["name"]; - _filenamenach = _filenamevon.replace("/config/", "/img_tmp/"); - FileDeleteOnServer(_filenamenach, _domainname); - FileCopyOnServer(_filenamevon, _filenamenach, _domainname); - - _filenamevon = _filenamevon.replace(".jpg", "_org.jpg"); - _filenamenach = _filenamenach.replace(".jpg", "_org.jpg"); - FileDeleteOnServer(_filenamenach, _domainname); - FileCopyOnServer(_filenamevon, _filenamenach, _domainname); - } -} - -function GetReferencesInfo(){ - return REFERENCES; -} - -function UpdateConfigReferences(_domainname){ - for (var index = 0; index < 2; ++index) { - _filenamenach = REFERENCES[index]["name"]; - _filenamevon = _filenamenach.replace("/config/", "/img_tmp/"); - FileDeleteOnServer(_filenamenach, _domainname); - FileCopyOnServer(_filenamevon, _filenamenach, _domainname); - - _filenamenach = _filenamenach.replace(".jpg", "_org.jpg"); - _filenamevon = _filenamevon.replace(".jpg", "_org.jpg"); - FileDeleteOnServer(_filenamenach, _domainname); - FileCopyOnServer(_filenamevon, _filenamenach, _domainname); - } -} - -function UpdateConfigReference(_anzneueref, _domainname){ - var index = 0; - - if (_anzneueref == 1) { - index = 0; - } - - else if (_anzneueref == 2) { - index = 1; - } - - _filenamenach = REFERENCES[index]["name"]; - _filenamevon = _filenamenach.replace("/config/", "/img_tmp/"); - - FileDeleteOnServer(_filenamenach, _domainname); - FileCopyOnServer(_filenamevon, _filenamenach, _domainname); - - _filenamenach = _filenamenach.replace(".jpg", "_org.jpg"); - _filenamevon = _filenamevon.replace(".jpg", "_org.jpg"); - - FileDeleteOnServer(_filenamenach, _domainname); - FileCopyOnServer(_filenamevon, _filenamenach, _domainname); -} - -function getNUMBERInfo(){ - return NUMBERS; -} - function RenameNUMBER(_alt, _neu){ if ((_neu.indexOf(".") >= 0) || (_neu.indexOf(",") >= 0) || (_neu.indexOf(" ") >= 0) || (_neu.indexOf("\"") >= 0)) { return "Number sequence name must not contain , . \" or a space"; @@ -1096,6 +821,34 @@ function CreateNUMBER(_numbernew){ return ""; } +function DeleteNUMBER(_delte) { + if (NUMBERS.length == 1) { + return "The last number cannot be deleted" + } + + index = -1; + + for (i = 0; i < NUMBERS.length; ++i) { + if (NUMBERS[i]["name"] == _delte) { + index = i; + } + } + + if (index > -1) { + NUMBERS.splice(index, 1); + } + + return ""; +} + +function GetReferencesInfo(){ + return REFERENCES; +} + +function getNUMBERInfo(){ + return NUMBERS; +} + function getROIInfo(_typeROI, _number){ index = -1; @@ -1151,26 +904,6 @@ function RenameROI(_number, _type, _alt, _neu){ return ""; } -function DeleteNUMBER(_delte) { - if (NUMBERS.length == 1) { - return "The last number cannot be deleted" - } - - index = -1; - - for (i = 0; i < NUMBERS.length; ++i) { - if (NUMBERS[i]["name"] == _delte) { - index = i; - } - } - - if (index > -1) { - NUMBERS.splice(index, 1); - } - - return ""; -} - function CreateROI(_number, _type, _pos, _roinew, _x, _y, _dx, _dy, _CCW){ _indexnumber = -1; @@ -1208,4 +941,4 @@ function CreateROI(_number, _type, _pos, _roinew, _x, _y, _dx, _dy, _CCW){ NUMBERS[_indexnumber][_type].splice(_pos+1, 0, _ret); return ""; -} +} \ No newline at end of file diff --git a/sd-card/html/reboot_page.html b/sd-card/html/reboot_page.html index 1fe1790c..867acde1 100644 --- a/sd-card/html/reboot_page.html +++ b/sd-card/html/reboot_page.html @@ -18,6 +18,7 @@ p {font-size: 1em;} + @@ -32,9 +33,9 @@ p {font-size: 1em;} - + + + - @@ -96,7 +100,6 @@ body, html {
-
@@ -106,8 +109,6 @@ body, html { - - - - + \ No newline at end of file From 277218774093878f1997f37543886a247e6fe39d Mon Sep 17 00:00:00 2001 From: SybexXx <587201+SybexX@users.noreply.github.com> Date: Tue, 20 Jan 2026 23:55:51 +0100 Subject: [PATCH 2/2] Update camera bus frequency to 16 MHz Changed camera module bus communications frequency from 20 MHz to 16 MHz to reduce visual artifacts. --- code/components/jomjol_controlcamera/ClassControllCamera.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/code/components/jomjol_controlcamera/ClassControllCamera.cpp b/code/components/jomjol_controlcamera/ClassControllCamera.cpp index 4d469997..c892b968 100644 --- a/code/components/jomjol_controlcamera/ClassControllCamera.cpp +++ b/code/components/jomjol_controlcamera/ClassControllCamera.cpp @@ -55,7 +55,7 @@ std::vector demoFiles; // Originally: config.xclk_freq_mhz = 20000000, but this lead to visual artifacts on many modules. // See https://github.com/espressif/esp32-camera/issues/150#issuecomment-726473652 et al. #if !defined(XCLK_FREQ_MHZ) -int xclk = 20; +int xclk = 16; #else int xclk = XCLK_FREQ_MHZ; #endif