diff --git a/code/components/jomjol_flowcontroll/ClassFlowCNNGeneral.cpp b/code/components/jomjol_flowcontroll/ClassFlowCNNGeneral.cpp index e996f2a8..2b1a15b1 100644 --- a/code/components/jomjol_flowcontroll/ClassFlowCNNGeneral.cpp +++ b/code/components/jomjol_flowcontroll/ClassFlowCNNGeneral.cpp @@ -27,6 +27,7 @@ ClassFlowCNNGeneral::ClassFlowCNNGeneral(ClassFlowAlignment *_flowalign, t_CNNTy CNNType = AutoDetect; CNNType = _cnntype; flowpostalignment = _flowalign; + logfileRetentionInDays = 5; } string ClassFlowCNNGeneral::getReadout(int _analog = 0, bool _extendedResolution, int prev, float _vorgaengerAnalog, float analogDigitalTransitionStart) diff --git a/code/components/jomjol_flowcontroll/ClassFlowImage.cpp b/code/components/jomjol_flowcontroll/ClassFlowImage.cpp index b701790d..0410d694 100644 --- a/code/components/jomjol_flowcontroll/ClassFlowImage.cpp +++ b/code/components/jomjol_flowcontroll/ClassFlowImage.cpp @@ -23,7 +23,7 @@ ClassFlowImage::ClassFlowImage(const char* logTag) this->logTag = logTag; isLogImage = false; disabled = false; - + this->logfileRetentionInDays = 5; } ClassFlowImage::ClassFlowImage(std::vector * lfc, const char* logTag) : ClassFlow(lfc) @@ -31,6 +31,7 @@ ClassFlowImage::ClassFlowImage(std::vector * lfc, const char* logTag this->logTag = logTag; isLogImage = false; disabled = false; + this->logfileRetentionInDays = 5; } ClassFlowImage::ClassFlowImage(std::vector * lfc, ClassFlow *_prev, const char* logTag) : ClassFlow(lfc, _prev) @@ -38,6 +39,7 @@ ClassFlowImage::ClassFlowImage(std::vector * lfc, ClassFlow *_prev, this->logTag = logTag; isLogImage = false; disabled = false; + this->logfileRetentionInDays = 5; } @@ -91,7 +93,7 @@ void ClassFlowImage::RemoveOldLogs() if (!isLogImage) return; - ESP_LOGI(logTag, "remove old log images"); + ESP_LOGI(TAG, "remove old images"); if (logfileRetentionInDays == 0) { return; } @@ -101,16 +103,17 @@ void ClassFlowImage::RemoveOldLogs() char cmpfilename[30]; time(&rawtime); - rawtime = addDays(rawtime, -logfileRetentionInDays); + rawtime = addDays(rawtime, -logfileRetentionInDays + 1); timeinfo = localtime(&rawtime); + //ESP_LOGD(TAG, "ImagefileRetentionInDays: %d", logfileRetentionInDays); strftime(cmpfilename, 30, LOGFILE_TIME_FORMAT, timeinfo); - //ESP_LOGE(TAG, "log file name to compare: %s", cmpfilename); + //ESP_LOGD(TAG, "file name to compare: %s", cmpfilename); string folderName = string(cmpfilename).LOGFILE_TIME_FORMAT_DATE_EXTR; DIR *dir = opendir(LogImageLocation.c_str()); if (!dir) { - ESP_LOGI(logTag, "Failed to stat dir : %s", LogImageLocation.c_str()); + ESP_LOGE(TAG, "Failed to stat dir : %s", LogImageLocation.c_str()); return; } @@ -120,8 +123,8 @@ void ClassFlowImage::RemoveOldLogs() while ((entry = readdir(dir)) != NULL) { string folderPath = LogImageLocation + "/" + entry->d_name; if (entry->d_type == DT_DIR) { - //ESP_LOGI(logTag, "Compare %s %s", entry->d_name, folderName.c_str()); - if ((strlen(entry->d_name) == folderName.length()) && (strcmp(entry->d_name, folderName.c_str()) == 0)) { + //ESP_LOGD(TAG, "Compare %s to %s", entry->d_name, folderName.c_str()); + if ((strlen(entry->d_name) == folderName.length()) && (strcmp(entry->d_name, folderName.c_str()) < 0)) { removeFolder(folderPath.c_str(), logTag); deleted++; } else { @@ -129,7 +132,7 @@ void ClassFlowImage::RemoveOldLogs() } } } - LogFile.WriteToFile(ESP_LOG_DEBUG, TAG, "Image folder deleted: " + std::to_string(deleted) + ". Image folder not deleted: " + std::to_string(notDeleted)); + ESP_LOGI(TAG, "Image folder deleted: %d | Image folder not deleted: %d", deleted, notDeleted); closedir(dir); } diff --git a/code/components/jomjol_flowcontroll/ClassFlowMakeImage.cpp b/code/components/jomjol_flowcontroll/ClassFlowMakeImage.cpp index 0d577304..9cae2205 100644 --- a/code/components/jomjol_flowcontroll/ClassFlowMakeImage.cpp +++ b/code/components/jomjol_flowcontroll/ClassFlowMakeImage.cpp @@ -57,6 +57,8 @@ void ClassFlowMakeImage::SetInitialParameter(void) ClassFlowMakeImage::ClassFlowMakeImage(std::vector* lfc) : ClassFlowImage(lfc, TAG) { + LogImageLocation = "/log/source"; + logfileRetentionInDays = 5; SetInitialParameter(); } @@ -104,6 +106,10 @@ bool ClassFlowMakeImage::ReadParameter(FILE* pfile, string& aktparamgraph) waitbeforepicture = stoi(zerlegt[1]); } + if ((toUpper(zerlegt[0]) == "LOGFILERETENTIONINDAYS") && (zerlegt.size() > 1)) + { + this->logfileRetentionInDays = std::stoi(zerlegt[1]); + } if ((toUpper(zerlegt[0]) == "BRIGHTNESS") && (zerlegt.size() > 1)) { diff --git a/code/components/jomjol_helper/Helper.cpp b/code/components/jomjol_helper/Helper.cpp index d06b819a..b7a2499e 100644 --- a/code/components/jomjol_helper/Helper.cpp +++ b/code/components/jomjol_helper/Helper.cpp @@ -90,7 +90,7 @@ string getSDCardPartitionSize(){ f_getfree("0:", (DWORD *)&fre_clust, &fs); tot_sect = ((fs->n_fatent - 2) * fs->csize) /1024 /(1024/SDCardCsd.sector_size); //corrected by SD Card sector size (usually 512 bytes) and convert to MB - printf("%d MB total drive space (Sector size [bytes]: %d)\n", (int)tot_sect, (int)fs->csize*512); + //ESP_LOGD(TAG, "%d MB total drive space (Sector size [bytes]: %d)", (int)tot_sect, (int)fs->ssize); return std::to_string(tot_sect); } @@ -103,7 +103,7 @@ string getSDCardFreePartitionSpace(){ f_getfree("0:", (DWORD *)&fre_clust, &fs); fre_sect = (fre_clust * fs->csize) / 1024 /(1024/SDCardCsd.sector_size); //corrected by SD Card sector size (usually 512 bytes) and convert to MB - printf("%d MB free drive space (Sector size [bytes]: %d)\n", (int)fre_sect, (int)fs->ssize); + //ESP_LOGD(TAG, "%d MB free drive space (Sector size [bytes]: %d)", (int)fre_sect, (int)fs->ssize); return std::to_string(fre_sect); } @@ -116,7 +116,7 @@ string getSDCardPartitionAllocationSize(){ f_getfree("0:", (DWORD *)&fre_clust, &fs); allocation_size = fs->ssize; - printf("SD Card Partition Allocation Size (bytes): %d)\n", allocation_size); + //ESP_LOGD(TAG, "SD Card Partition Allocation Size: %d bytes", allocation_size); return std::to_string(allocation_size); } @@ -129,28 +129,28 @@ void SaveSDCardInfo(sdmmc_card_t* card) { string getSDCardManufacturer(){ string SDCardManufacturer = SDCardParseManufacturerIDs(SDCardCid.mfg_id); - printf("SD Card Manufactuer: %s\n", SDCardManufacturer.c_str()); + //ESP_LOGD(TAG, "SD Card Manufacturer: %s", SDCardManufacturer.c_str()); return (SDCardManufacturer + " (ID: " + std::to_string(SDCardCid.mfg_id) + ")"); } string getSDCardName(){ char *SDCardName = SDCardCid.name; - printf("SD Card Name: %s\n", SDCardName); + //ESP_LOGD(TAG, "SD Card Name: %s", SDCardName); return std::string(SDCardName); } string getSDCardCapacity(){ int SDCardCapacity = SDCardCsd.capacity / (1024/SDCardCsd.sector_size) / 1024; // total sectors * sector size --> Byte to MB (1024*1024) - printf("SD Card Capacity: %s\n", std::to_string(SDCardCapacity).c_str()); + //ESP_LOGD(TAG, "SD Card Capacity: %s", std::to_string(SDCardCapacity).c_str()); return std::to_string(SDCardCapacity); } string getSDCardSectorSize(){ int SDCardSectorSize = SDCardCsd.sector_size; - printf("SD Card Sector Size: %s\n", std::to_string(SDCardSectorSize).c_str()); + //ESP_LOGD(TAG, "SD Card Sector Size: %s bytes", std::to_string(SDCardSectorSize).c_str()); return std::to_string(SDCardSectorSize); } @@ -500,11 +500,11 @@ time_t addDays(time_t startTime, int days) { } int removeFolder(const char* folderPath, const char* logTag) { - ESP_LOGI(logTag, "Delete folder %s", folderPath); + //ESP_LOGD(logTag, "Delete content in path %s", folderPath); DIR *dir = opendir(folderPath); if (!dir) { - ESP_LOGI(logTag, "Failed to stat dir : %s", folderPath); + ESP_LOGE(logTag, "Failed to stat dir : %s", folderPath); return -1; } @@ -513,6 +513,7 @@ int removeFolder(const char* folderPath, const char* logTag) { while ((entry = readdir(dir)) != NULL) { std::string path = string(folderPath) + "/" + entry->d_name; if (entry->d_type == DT_REG) { + //ESP_LOGD(logTag, "Delete file %s", path.c_str()); if (unlink(path.c_str()) == 0) { deleted ++; } else { @@ -525,9 +526,9 @@ int removeFolder(const char* folderPath, const char* logTag) { closedir(dir); if (rmdir(folderPath) != 0) { - ESP_LOGE(logTag, "can't delete file : %s", folderPath); + ESP_LOGE(logTag, "can't delete folder : %s", folderPath); } - ESP_LOGI(logTag, "%d older log files in folder %s deleted.", deleted, folderPath); + ESP_LOGD(logTag, "%d files in folder %s deleted.", deleted, folderPath); return deleted; } diff --git a/code/components/jomjol_logfile/ClassLogFile.cpp b/code/components/jomjol_logfile/ClassLogFile.cpp index dfaa5ebe..62ab0673 100644 --- a/code/components/jomjol_logfile/ClassLogFile.cpp +++ b/code/components/jomjol_logfile/ClassLogFile.cpp @@ -294,17 +294,18 @@ void ClassLogFile::RemoveOld() char cmpfilename[30]; time(&rawtime); - rawtime = addDays(rawtime, -retentionInDays); + rawtime = addDays(rawtime, -retentionInDays + 1); timeinfo = localtime(&rawtime); - + //ESP_LOGD(TAG, "logfileRetentionInDays: %d", retentionInDays); ////////////////////// message ///////////////////////////////////////// + ESP_LOGI(TAG, "remove old log files"); strftime(cmpfilename, 30, logfile.c_str(), timeinfo); - //ESP_LOGE(TAG, "log file name to compare: %s", cmpfilename); + //ESP_LOGD(TAG, "log file name to compare: %s", cmpfilename); DIR *dir = opendir(logroot.c_str()); if (!dir) { - ESP_LOGI(TAG, "Failed to stat dir : %s", logroot.c_str()); + ESP_LOGE(TAG, "Failed to stat dir : %s", logroot.c_str()); return; } @@ -313,31 +314,33 @@ void ClassLogFile::RemoveOld() int notDeleted = 0; while ((entry = readdir(dir)) != NULL) { if (entry->d_type == DT_REG) { - //ESP_LOGI(TAG, "list log file : %s %s", entry->d_name, cmpfilename); - if ((strlen(entry->d_name) == strlen(cmpfilename)) && (strcmp(entry->d_name, cmpfilename) == 0)) { - ESP_LOGI(TAG, "delete log file : %s", entry->d_name); + //ESP_LOGD(TAG, "compare log file : %s to %s", entry->d_name, cmpfilename); + if ((strlen(entry->d_name) == strlen(cmpfilename)) && (strcmp(entry->d_name, cmpfilename) < 0)) { + //ESP_LOGD(TAG, "delete log file : %s", entry->d_name); std::string filepath = logroot + "/" + entry->d_name; if (unlink(filepath.c_str()) == 0) { deleted ++; } else { ESP_LOGE(TAG, "can't delete file : %s", entry->d_name); + notDeleted ++; } } else { notDeleted ++; } } } - LogFile.WriteToFile(ESP_LOG_DEBUG, TAG, "logfiles deleted: " + std::to_string(deleted) + " files not deleted (incl. leer.txt): " + std::to_string(notDeleted)); + ESP_LOGI(TAG, "data files deleted: %d | files not deleted (incl. leer.txt): %d", deleted, notDeleted); closedir(dir); ////////////////////// data ///////////////////////////////////////// + ESP_LOGI(TAG, "remove old data files"); strftime(cmpfilename, 30, datafile.c_str(), timeinfo); - //ESP_LOGE(TAG, "log file name to compare: %s", cmpfilename); + //ESP_LOGD(TAG, "data file name to compare: %s", cmpfilename); dir = opendir(dataroot.c_str()); if (!dir) { - ESP_LOGI(TAG, "Failed to stat dir : %s", dataroot.c_str()); + ESP_LOGE(TAG, "Failed to stat dir : %s", dataroot.c_str()); return; } @@ -345,21 +348,22 @@ void ClassLogFile::RemoveOld() notDeleted = 0; while ((entry = readdir(dir)) != NULL) { if (entry->d_type == DT_REG) { - //ESP_LOGI(TAG, "list log file : %s %s", entry->d_name, cmpfilename); + //ESP_LOGD(TAG, "Compare data file : %s to %s", entry->d_name, cmpfilename); if ((strlen(entry->d_name) == strlen(cmpfilename)) && (strcmp(entry->d_name, cmpfilename) < 0)) { - ESP_LOGI(TAG, "delete data file : %s", entry->d_name); - std::string filepath = logroot + "/" + entry->d_name; + //ESP_LOGD(TAG, "delete data file : %s", entry->d_name); + std::string filepath = dataroot + "/" + entry->d_name; if (unlink(filepath.c_str()) == 0) { deleted ++; } else { ESP_LOGE(TAG, "can't delete file : %s", entry->d_name); + notDeleted ++; } } else { notDeleted ++; } } } - ESP_LOGI(TAG, "%d older log files deleted. %d current log files not deleted.", deleted, notDeleted); + ESP_LOGI(TAG, "data files deleted: %d | files not deleted (incl. leer.txt): %d", deleted, notDeleted); closedir(dir); } @@ -382,5 +386,4 @@ ClassLogFile::ClassLogFile(std::string _logroot, std::string _logfile, std::stri dataroot = _logdatapath; retentionInDays = 10; loglevel = ESP_LOG_INFO; - MakeDir("/sdcard/log/data"); } diff --git a/code/components/jomjol_wlan/connect_wlan.cpp b/code/components/jomjol_wlan/connect_wlan.cpp index 81c6823c..0478892c 100644 --- a/code/components/jomjol_wlan/connect_wlan.cpp +++ b/code/components/jomjol_wlan/connect_wlan.cpp @@ -231,7 +231,7 @@ void wifi_init_sta(const char *_ssid, const char *_password, const char *_hostna ESP_LOGE(TAG,"failed to set hostname:%d",ret); } else { - ESP_LOGE(TAG,"Set Hostname to:%s", _hostname); + ESP_LOGI(TAG,"Set Hostname to:%s", _hostname); } }