Add parameter to disable write data log (#1382)

This commit is contained in:
Slider0007
2022-11-20 17:44:42 +01:00
committed by GitHub
parent 60e9a427a5
commit 66be09c98e
8 changed files with 184 additions and 77 deletions

View File

@@ -203,6 +203,9 @@ ClassFlow* ClassFlowControll::CreateClassFlow(std::string _type)
if (toUpper(_type).compare("[AUTOTIMER]") == 0) if (toUpper(_type).compare("[AUTOTIMER]") == 0)
cfc = this; cfc = this;
if (toUpper(_type).compare("[DATALOGGING]") == 0)
cfc = this;
if (toUpper(_type).compare("[DEBUG]") == 0) if (toUpper(_type).compare("[DEBUG]") == 0)
cfc = this; cfc = this;
@@ -446,7 +449,8 @@ bool ClassFlowControll::ReadParameter(FILE* pfile, string& aktparamgraph)
return false; return false;
if ((toUpper(aktparamgraph).compare("[AUTOTIMER]") != 0) && (toUpper(aktparamgraph).compare("[DEBUG]") != 0) && (toUpper(aktparamgraph).compare("[SYSTEM]") != 0)) // Paragraph passt nicht zu MakeImage if ((toUpper(aktparamgraph).compare("[AUTOTIMER]") != 0) && (toUpper(aktparamgraph).compare("[DEBUG]") != 0) &&
(toUpper(aktparamgraph).compare("[SYSTEM]") != 0 && (toUpper(aktparamgraph).compare("[DATALOGGING]") != 0))) // Paragraph passt nicht zu MakeImage
return false; return false;
while (this->getNextLine(pfile, &aktparamgraph) && !this->isNewParagraph(aktparamgraph)) while (this->getNextLine(pfile, &aktparamgraph) && !this->isNewParagraph(aktparamgraph))
@@ -459,10 +463,28 @@ bool ClassFlowControll::ReadParameter(FILE* pfile, string& aktparamgraph)
AutoStart = true; AutoStart = true;
} }
} }
if ((toUpper(zerlegt[0]) == "INTERVALL") && (zerlegt.size() > 1)) if ((toUpper(zerlegt[0]) == "INTERVALL") && (zerlegt.size() > 1))
{ {
AutoIntervall = std::stof(zerlegt[1]); AutoIntervall = std::stof(zerlegt[1]);
} }
if ((toUpper(zerlegt[0]) == "DATALOGACTIVE") && (zerlegt.size() > 1))
{
if (toUpper(zerlegt[1]) == "TRUE")
{
LogFile.SetDataLogToSD(true);
}
else {
LogFile.SetDataLogToSD(false);
}
}
if ((toUpper(zerlegt[0]) == "DATALOGRETENTIONINDAYS") && (zerlegt.size() > 1))
{
LogFile.SetDataLogRetention(std::stoi(zerlegt[1]));
}
if ((toUpper(zerlegt[0]) == "LOGFILE") && (zerlegt.size() > 1)) if ((toUpper(zerlegt[0]) == "LOGFILE") && (zerlegt.size() > 1))
{ {
/* matches esp_log_level_t */ /* matches esp_log_level_t */
@@ -485,7 +507,7 @@ bool ClassFlowControll::ReadParameter(FILE* pfile, string& aktparamgraph)
} }
if ((toUpper(zerlegt[0]) == "LOGFILERETENTIONINDAYS") && (zerlegt.size() > 1)) if ((toUpper(zerlegt[0]) == "LOGFILERETENTIONINDAYS") && (zerlegt.size() > 1))
{ {
LogFile.SetRetention(std::stoi(zerlegt[1])); LogFile.SetLogFileRetention(std::stoi(zerlegt[1]));
} }
if ((toUpper(zerlegt[0]) == "TIMEZONE") && (zerlegt.size() > 1)) if ((toUpper(zerlegt[0]) == "TIMEZONE") && (zerlegt.size() > 1))

View File

@@ -869,6 +869,10 @@ bool ClassFlowPostProcessing::doFlow(string zwtime)
void ClassFlowPostProcessing::WriteDataLog(int _index) void ClassFlowPostProcessing::WriteDataLog(int _index)
{ {
if (!LogFile.GetDataLogToSD()){
return;
}
string analog = ""; string analog = "";
string digital = ""; string digital = "";
string timezw = ""; string timezw = "";

View File

@@ -80,11 +80,6 @@ void ClassLogFile::WriteToData(std::string _timestamp, std::string _name, std::s
FILE* pFile; FILE* pFile;
std::string zwtime; std::string zwtime;
// TODO add separate parameter to disable write of data.
/*if (!doLogFile){
return;
}*/
ESP_LOGD(TAG, "Datalogfile: %s", logpath.c_str()); ESP_LOGD(TAG, "Datalogfile: %s", logpath.c_str());
pFile = fopen(logpath.c_str(), "a+"); pFile = fopen(logpath.c_str(), "a+");
@@ -208,11 +203,23 @@ void ClassLogFile::setLogLevel(esp_log_level_t _logLevel){
LogFile.WriteToFile(ESP_LOG_INFO, TAG, "Test"); LogFile.WriteToFile(ESP_LOG_INFO, TAG, "Test");
LogFile.WriteToFile(ESP_LOG_DEBUG, TAG, "Test"); LogFile.WriteToFile(ESP_LOG_DEBUG, TAG, "Test");
*/ */
}; }
void ClassLogFile::SetRetention(unsigned short _retentionInDays){ void ClassLogFile::SetLogFileRetention(unsigned short _LogFileRetentionInDays){
retentionInDays = _retentionInDays; logFileRetentionInDays = _LogFileRetentionInDays;
}; }
void ClassLogFile::SetDataLogRetention(unsigned short _DataLogRetentionInDays){
dataLogRetentionInDays = _DataLogRetentionInDays;
}
void ClassLogFile::SetDataLogToSD(bool _doDataLogToSD){
doDataLogToSD = _doDataLogToSD;
}
bool ClassLogFile::GetDataLogToSD(){
return doDataLogToSD;
}
void ClassLogFile::WriteToFile(esp_log_level_t level, std::string tag, std::string message, bool _time) void ClassLogFile::WriteToFile(esp_log_level_t level, std::string tag, std::string message, bool _time)
{ {
@@ -283,23 +290,24 @@ std::string ClassLogFile::GetCurrentFileName()
return logpath; return logpath;
} }
void ClassLogFile::RemoveOld() void ClassLogFile::RemoveOldLogFile()
{ {
if (retentionInDays == 0) { if (logFileRetentionInDays == 0) {
return; return;
} }
ESP_LOGI(TAG, "Remove old log files");
time_t rawtime; time_t rawtime;
struct tm* timeinfo; struct tm* timeinfo;
char cmpfilename[30]; char cmpfilename[30];
time(&rawtime); time(&rawtime);
rawtime = addDays(rawtime, -retentionInDays + 1); rawtime = addDays(rawtime, -logFileRetentionInDays + 1);
timeinfo = localtime(&rawtime); timeinfo = localtime(&rawtime);
//ESP_LOGD(TAG, "logfileRetentionInDays: %d", retentionInDays); //ESP_LOGD(TAG, "logFileRetentionInDays: %d", logFileRetentionInDays);
////////////////////// message /////////////////////////////////////////
ESP_LOGI(TAG, "remove old log files");
strftime(cmpfilename, 30, logfile.c_str(), timeinfo); strftime(cmpfilename, 30, logfile.c_str(), timeinfo);
//ESP_LOGD(TAG, "log file name to compare: %s", cmpfilename); //ESP_LOGD(TAG, "log file name to compare: %s", cmpfilename);
@@ -329,23 +337,40 @@ void ClassLogFile::RemoveOld()
} }
} }
} }
ESP_LOGI(TAG, "data files deleted: %d | files not deleted (incl. leer.txt): %d", deleted, notDeleted); ESP_LOGI(TAG, "log files deleted: %d | files not deleted (incl. leer.txt): %d", deleted, notDeleted);
closedir(dir); closedir(dir);
}
////////////////////// data ///////////////////////////////////////// void ClassLogFile::RemoveOldDataLog()
ESP_LOGI(TAG, "remove old data files"); {
if (dataLogRetentionInDays == 0 || !doDataLogToSD) {
return;
}
ESP_LOGI(TAG, "Remove old data files");
time_t rawtime;
struct tm* timeinfo;
char cmpfilename[30];
time(&rawtime);
rawtime = addDays(rawtime, -dataLogRetentionInDays + 1);
timeinfo = localtime(&rawtime);
//ESP_LOGD(TAG, "dataLogRetentionInDays: %d", dataLogRetentionInDays);
strftime(cmpfilename, 30, datafile.c_str(), timeinfo); strftime(cmpfilename, 30, datafile.c_str(), timeinfo);
//ESP_LOGD(TAG, "data file name to compare: %s", cmpfilename); //ESP_LOGD(TAG, "data file name to compare: %s", cmpfilename);
dir = opendir(dataroot.c_str()); DIR *dir = opendir(dataroot.c_str());
if (!dir) { if (!dir) {
ESP_LOGE(TAG, "Failed to stat dir : %s", dataroot.c_str()); ESP_LOGE(TAG, "Failed to stat dir : %s", dataroot.c_str());
return; return;
} }
deleted = 0; struct dirent *entry;
notDeleted = 0; int deleted = 0;
int notDeleted = 0;
while ((entry = readdir(dir)) != NULL) { while ((entry = readdir(dir)) != NULL) {
if (entry->d_type == DT_REG) { if (entry->d_type == DT_REG) {
//ESP_LOGD(TAG, "Compare data file : %s to %s", entry->d_name, cmpfilename); //ESP_LOGD(TAG, "Compare data file : %s to %s", entry->d_name, cmpfilename);
@@ -367,6 +392,7 @@ void ClassLogFile::RemoveOld()
closedir(dir); closedir(dir);
} }
void ClassLogFile::CreateLogDirectories() void ClassLogFile::CreateLogDirectories()
{ {
MakeDir("/sdcard/log"); MakeDir("/sdcard/log");
@@ -384,6 +410,8 @@ ClassLogFile::ClassLogFile(std::string _logroot, std::string _logfile, std::stri
logfile = _logfile; logfile = _logfile;
datafile = _datafile; datafile = _datafile;
dataroot = _logdatapath; dataroot = _logdatapath;
retentionInDays = 10; logFileRetentionInDays = 3;
dataLogRetentionInDays = 3;
doDataLogToSD = true;
loglevel = ESP_LOG_INFO; loglevel = ESP_LOG_INFO;
} }

View File

@@ -10,7 +10,9 @@ private:
std::string logfile; std::string logfile;
std::string dataroot; std::string dataroot;
std::string datafile; std::string datafile;
unsigned short retentionInDays; unsigned short logFileRetentionInDays;
unsigned short dataLogRetentionInDays;
bool doDataLogToSD;
esp_log_level_t loglevel; esp_log_level_t loglevel;
public: public:
ClassLogFile(std::string _logpath, std::string _logfile, std::string _logdatapath, std::string _datafile); ClassLogFile(std::string _logpath, std::string _logfile, std::string _logdatapath, std::string _datafile);
@@ -20,7 +22,10 @@ public:
void WriteHeapInfo(std::string _id); void WriteHeapInfo(std::string _id);
void setLogLevel(esp_log_level_t _logLevel); void setLogLevel(esp_log_level_t _logLevel);
void SetRetention(unsigned short _retentionInDays); void SetLogFileRetention(unsigned short _LogFileRetentionInDays);
void SetDataLogRetention(unsigned short _DataLogRetentionInDays);
void SetDataLogToSD(bool _doDataLogToSD);
bool GetDataLogToSD();
void WriteToFile(esp_log_level_t level, std::string tag, std::string message, bool _time); void WriteToFile(esp_log_level_t level, std::string tag, std::string message, bool _time);
void WriteToFile(esp_log_level_t level, std::string tag, std::string message); void WriteToFile(esp_log_level_t level, std::string tag, std::string message);
@@ -28,7 +33,8 @@ public:
void WriteToDedicatedFile(std::string _fn, esp_log_level_t level, std::string message, bool _time = true); void WriteToDedicatedFile(std::string _fn, esp_log_level_t level, std::string message, bool _time = true);
void CreateLogDirectories(); void CreateLogDirectories();
void RemoveOld(); void RemoveOldLogFile();
void RemoveOldDataLog();
// void WriteToData(std::string _ReturnRawValue, std::string _ReturnValue, std::string _ReturnPreValue, std::string _ErrorMessageText, std::string _digital, std::string _analog); // void WriteToData(std::string _ReturnRawValue, std::string _ReturnValue, std::string _ReturnPreValue, std::string _ErrorMessageText, std::string _digital, std::string _analog);
void WriteToData(std::string _timestamp, std::string _name, std::string _ReturnRawValue, std::string _ReturnValue, std::string _ReturnPreValue, std::string _ReturnRateValue, std::string _ReturnChangeAbsolute, std::string _ErrorMessageText, std::string _digital, std::string _analog); void WriteToData(std::string _timestamp, std::string _name, std::string _ReturnRawValue, std::string _ReturnValue, std::string _ReturnPreValue, std::string _ReturnRateValue, std::string _ReturnChangeAbsolute, std::string _ErrorMessageText, std::string _digital, std::string _analog);

View File

@@ -747,7 +747,8 @@ void task_autodoFlow(void *pvParameter)
#ifdef DEBUG_DETAIL_ON #ifdef DEBUG_DETAIL_ON
ESP_LOGD(TAG, "Remove older log files"); ESP_LOGD(TAG, "Remove older log files");
#endif #endif
LogFile.RemoveOld(); LogFile.RemoveOldLogFile();
LogFile.RemoveOldDataLog();
} }
LogFile.WriteToFile(ESP_LOG_INFO, TAG, "task_autodoFlow - round #" + std::to_string(countRounds) + " done"); LogFile.WriteToFile(ESP_LOG_INFO, TAG, "task_autodoFlow - round #" + std::to_string(countRounds) + " done");

View File

@@ -84,6 +84,10 @@ LEDColor = 150 150 150
AutoStart = true AutoStart = true
Intervall = 5 Intervall = 5
[DataLogging]
DataLogActive = true
DataLogRetentionInDays = 3
[Debug] [Debug]
Logfile = 1 Logfile = 1
LogfileRetentionInDays = 3 LogfileRetentionInDays = 3

View File

@@ -9,9 +9,8 @@
h1 {font-size: 2em;} h1 {font-size: 2em;}
h2 {font-size: 1.5em; margin-block-start: 0.0em; margin-block-end: 0.2em;} h2 {font-size: 1.5em; margin-block-start: 0.0em; margin-block-end: 0.2em;}
h3 {font-size: 1.2em;} h3 {font-size: 1.2em;}
h4 { h4 {font-size: 1em; margin-bottom: 0;}
margin-bottom: 0; h5 {font-size: 0.83em; margin-top: 0.2em; margin-bottom: 0;}
}
p {font-size: 1em;} p {font-size: 1em;}
@@ -626,9 +625,11 @@ textarea {
</td> </td>
</tr> </tr>
<tr> <tr>
<td colspan="3" style="padding-left: 20px;"><h4>Homeassistant Discovery (using MQTT)</h4> <td class="indent1" colspan="3">
<span style="font-size: 80%;">The discovery topics and the static topics (IP, MAC, Hostname, Interval, ...) only get sent on startup. <h4>Homeassistant Discovery (using MQTT)</h4>
To send them again, you can call the following URL: <a href=mqtt_publish_discovery target="_blank">http://&lt;IP&gt;/mqtt_publish_discovery</a></span></td> <h5>The discovery topics and the static topics (IP, MAC, Hostname, Interval, ...) only get sent on startup.
To send them again, you can call the following URL: <a href=mqtt_publish_discovery target="_blank">http://&lt;IP&gt;/mqtt_publish_discovery</a></h5>
</td>
</tr> </tr>
<tr> <tr>
<td class="indent1"> <td class="indent1">
@@ -675,8 +676,7 @@ textarea {
<td colspan="3" style="padding-left: 20px;"> <td colspan="3" style="padding-left: 20px;">
<h4> <h4>
<input type="checkbox" id="Category_InfluxDB_enabled" value="1" onclick = 'UpdateAfterCategoryCheck()' unchecked > <input type="checkbox" id="Category_InfluxDB_enabled" value="1" onclick = 'UpdateAfterCategoryCheck()' unchecked >
<label for=Category_InfluxDB_enabled>InfluxDB (Remark: only InfluxDB v1.x is supported, v2.x has a changed interface)</label> <label for=Category_InfluxDB_enabled>InfluxDB</h4><h5>Only InfluxDB v1.x is supported, v2.x has a changed interface</h5></label>
</h4>
</td> </td>
</tr> </tr>
<tr> <tr>
@@ -740,41 +740,12 @@ textarea {
</td> </td>
</tr> </tr>
<tr>
<td colspan="3" style="padding-left: 20px;"><h4>AutoTimer</h4></td>
</tr>
<tr class="expert" id="ex13">
<td class="indent1">
<class id="AutoTimer_AutoStart_text" style="color:black;">AutoStart</class>
</td>
<td>
<select id="AutoTimer_AutoStart_value1">
<option value="true" selected>true</option>
<option value="false" >false</option>
</select>
</td>
<td style="font-size: 80%;">
Start the image recognition immediatly after power up. false is basically for debugging.
</td>
</tr>
<tr>
<td class="indent1">
<class id="AutoTimer_Intervall_text" style="color:black;">Interval</class>
</td>
<td>
<input type="number" id="AutoTimer_Intervall_value1" size="13" min="3" step="any">
</td>
<td style="font-size: 80%;">
Interval in which the number(s) are read (in minutes). If a run takes longer than this interval, the next run gets postponed until the current run completes.
</td>
</tr>
<tr> <tr>
<td colspan="3" style="padding-left: 20px;"> <td colspan="3" style="padding-left: 20px;">
<h4><input type="checkbox" id="Category_GPIO_enabled" value="1" onclick='UpdateAfterCategoryCheck()' unchecked > <h4><input type="checkbox" id="Category_GPIO_enabled" value="1" onclick='UpdateAfterCategoryCheck()' unchecked >
<label for=Category_GPIO_enabled>GPIO Settings <label for=Category_GPIO_enabled>GPIO Settings
<span class="GPIO_Item" > - Enabling GPIO handler, disable by default integrated flash light.<br>Please enable it with GPIO4 (internal flash LED) settings or GPIO12 (external LED).</span></label> <span class="GPIO_Item">
<h5>Enabling GPIO handler, disable by default integrated flash light.<br>Please enable it with GPIO4 (internal flash LED) settings or GPIO12 (external LED).</span></label>
</h4> </h4>
</td> </td>
</tr> </tr>
@@ -1272,13 +1243,71 @@ textarea {
</tr> </tr>
<!------------- GPIO13 end ------------------> <!------------- GPIO13 end ------------------>
<tr>
<td colspan="3" style="padding-left: 20px;"><h4>AutoTimer</h4></td>
</tr>
<tr class="expert" id="ex13">
<td class="indent1">
<class id="AutoTimer_AutoStart_text" style="color:black;">AutoStart</class>
</td>
<td>
<select id="AutoTimer_AutoStart_value1">
<option value="true" selected>true</option>
<option value="false" >false</option>
</select>
</td>
<td style="font-size: 80%;">
Start the image recognition immediatly after power up. false is basically for debugging.
</td>
</tr>
<tr>
<td class="indent1">
<class id="AutoTimer_Intervall_text" style="color:black;">Interval</class>
</td>
<td>
<input type="number" id="AutoTimer_Intervall_value1" size="13" min="3" step="any">
</td>
<td style="font-size: 80%;">
Interval in which the number(s) are read (in minutes). If a run takes longer than this interval, the next run gets postponed until the current run completes.
</td>
</tr>
<tr>
<td colspan="3" style="padding-left: 20px;"><h4>DataLogging</h4></td>
</tr>
<tr>
<td class="indent1">
<class id="DataLogging_DataLogActive_text" style="color:black;">DataLogActive</class>
</td>
<td>
<select id="DataLogging_DataLogActive_value1">
<option value="true" selected>true</option>
<option value="false" >false</option>
</select>
</td>
<td class="description">
Activate data log to SD card
</td>
</tr>
<tr>
<td class="indent1">
<class id="DataLogging_DataLogRetentionInDays_text" style="color:black;">DataLogRetentionInDays</class>
</td>
<td>
<input type="number" id="DataLogging_DataLogRetentionInDays_value1" size="13" min="0" step="1">
</td>
<td class="description">
Time to keep the data files (in days - "0" = forever)
</td>
</tr>
<tr> <tr>
<td colspan="3" style="padding-left: 20px;"><h4>Debug</h4></td> <td colspan="3" style="padding-left: 20px;"><h4>Debug</h4></td>
</tr> </tr>
<tr> <tr>
<td class="indent1"> <td class="indent1">
<input type="checkbox" id="Debug_Logfile_enabled" value="1" onclick = 'InvertEnableItem("Debug", "Logfile")' unchecked > <class id="Debug_Logfile_text" style="color:black;">Logfile Log Level</class>
<label for=Debug_Logfile_enabled><class id="Debug_Logfile_text" style="color:black;">Logfile Log Level</class></label>
</td> </td>
<td> <td>
<select id="Debug_Logfile_value1"> <select id="Debug_Logfile_value1">
@@ -1294,8 +1323,7 @@ textarea {
</tr> </tr>
<tr> <tr>
<td class="indent1"> <td class="indent1">
<input type="checkbox" id="Debug_LogfileRetentionInDays_enabled" value="1" onclick = 'InvertEnableItem("Debug", "LogfileRetentionInDays")' unchecked > <class id="Debug_LogfileRetentionInDays_text" style="color:black;">LogfileRetentionInDays</class>
<label for=Debug_LogfileRetentionInDays_enabled><class id="Debug_LogfileRetentionInDays_text" style="color:black;">LogfileRetentionInDays</class></label>
</td> </td>
<td> <td>
<input type="number" id="Debug_LogfileRetentionInDays_value1" size="13" min="0" step="1"> <input type="number" id="Debug_LogfileRetentionInDays_value1" size="13" min="0" step="1">
@@ -1784,8 +1812,11 @@ function UpdateInput() {
WriteParameter(param, category, "AutoTimer", "AutoStart", false); WriteParameter(param, category, "AutoTimer", "AutoStart", false);
WriteParameter(param, category, "AutoTimer", "Intervall", false); WriteParameter(param, category, "AutoTimer", "Intervall", false);
WriteParameter(param, category, "Debug", "Logfile", true); WriteParameter(param, category, "DataLogging", "DataLogActive", false);
WriteParameter(param, category, "Debug", "LogfileRetentionInDays", true); WriteParameter(param, category, "DataLogging", "DataLogRetentionInDays", false);
WriteParameter(param, category, "Debug", "Logfile", false);
WriteParameter(param, category, "Debug", "LogfileRetentionInDays", false);
WriteParameter(param, category, "System", "TimeZone", true); WriteParameter(param, category, "System", "TimeZone", true);
WriteParameter(param, category, "System", "Hostname", true); WriteParameter(param, category, "System", "Hostname", true);
@@ -1909,8 +1940,11 @@ function ReadParameterAll()
ReadParameter(param, "AutoTimer", "AutoStart", false); ReadParameter(param, "AutoTimer", "AutoStart", false);
ReadParameter(param, "AutoTimer", "Intervall", false); ReadParameter(param, "AutoTimer", "Intervall", false);
ReadParameter(param, "Debug", "Logfile", true); ReadParameter(param, "DataLogging", "DataLogActive", false);
ReadParameter(param, "Debug", "LogfileRetentionInDays", true); ReadParameter(param, "DataLogging", "DataLogRetentionInDays", false);
ReadParameter(param, "Debug", "Logfile", false);
ReadParameter(param, "Debug", "LogfileRetentionInDays", false);
ReadParameter(param, "System", "TimeZone", true); ReadParameter(param, "System", "TimeZone", true);
ReadParameter(param, "System", "Hostname", true); ReadParameter(param, "System", "Hostname", true);

View File

@@ -231,6 +231,14 @@ function ParseConfig() {
ParamAddValue(param, catname, "AutoStart"); ParamAddValue(param, catname, "AutoStart");
ParamAddValue(param, catname, "Intervall"); ParamAddValue(param, catname, "Intervall");
var catname = "DataLogging";
category[catname] = new Object();
category[catname]["enabled"] = false;
category[catname]["found"] = false;
param[catname] = new Object();
ParamAddValue(param, catname, "DataLogActive");
ParamAddValue(param, catname, "DataLogRetentionInDays");
var catname = "Debug"; var catname = "Debug";
category[catname] = new Object(); category[catname] = new Object();
category[catname]["enabled"] = false; category[catname]["enabled"] = false;