mirror of
https://github.com/jomjol/AI-on-the-edge-device.git
synced 2025-12-08 20:46:52 +03:00
Add parameter to disable write data log (#1382)
This commit is contained in:
@@ -203,6 +203,9 @@ ClassFlow* ClassFlowControll::CreateClassFlow(std::string _type)
|
||||
if (toUpper(_type).compare("[AUTOTIMER]") == 0)
|
||||
cfc = this;
|
||||
|
||||
if (toUpper(_type).compare("[DATALOGGING]") == 0)
|
||||
cfc = this;
|
||||
|
||||
if (toUpper(_type).compare("[DEBUG]") == 0)
|
||||
cfc = this;
|
||||
|
||||
@@ -446,7 +449,8 @@ bool ClassFlowControll::ReadParameter(FILE* pfile, string& aktparamgraph)
|
||||
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;
|
||||
|
||||
while (this->getNextLine(pfile, &aktparamgraph) && !this->isNewParagraph(aktparamgraph))
|
||||
@@ -459,10 +463,28 @@ bool ClassFlowControll::ReadParameter(FILE* pfile, string& aktparamgraph)
|
||||
AutoStart = true;
|
||||
}
|
||||
}
|
||||
|
||||
if ((toUpper(zerlegt[0]) == "INTERVALL") && (zerlegt.size() > 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))
|
||||
{
|
||||
/* matches esp_log_level_t */
|
||||
@@ -485,7 +507,7 @@ bool ClassFlowControll::ReadParameter(FILE* pfile, string& aktparamgraph)
|
||||
}
|
||||
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))
|
||||
|
||||
@@ -869,6 +869,10 @@ bool ClassFlowPostProcessing::doFlow(string zwtime)
|
||||
|
||||
void ClassFlowPostProcessing::WriteDataLog(int _index)
|
||||
{
|
||||
if (!LogFile.GetDataLogToSD()){
|
||||
return;
|
||||
}
|
||||
|
||||
string analog = "";
|
||||
string digital = "";
|
||||
string timezw = "";
|
||||
|
||||
@@ -80,11 +80,6 @@ void ClassLogFile::WriteToData(std::string _timestamp, std::string _name, std::s
|
||||
FILE* pFile;
|
||||
std::string zwtime;
|
||||
|
||||
// TODO add separate parameter to disable write of data.
|
||||
/*if (!doLogFile){
|
||||
return;
|
||||
}*/
|
||||
|
||||
ESP_LOGD(TAG, "Datalogfile: %s", logpath.c_str());
|
||||
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_DEBUG, TAG, "Test");
|
||||
*/
|
||||
};
|
||||
}
|
||||
|
||||
void ClassLogFile::SetRetention(unsigned short _retentionInDays){
|
||||
retentionInDays = _retentionInDays;
|
||||
};
|
||||
void ClassLogFile::SetLogFileRetention(unsigned short _LogFileRetentionInDays){
|
||||
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)
|
||||
{
|
||||
@@ -283,23 +290,24 @@ std::string ClassLogFile::GetCurrentFileName()
|
||||
return logpath;
|
||||
}
|
||||
|
||||
void ClassLogFile::RemoveOld()
|
||||
void ClassLogFile::RemoveOldLogFile()
|
||||
{
|
||||
if (retentionInDays == 0) {
|
||||
if (logFileRetentionInDays == 0) {
|
||||
return;
|
||||
}
|
||||
|
||||
ESP_LOGI(TAG, "Remove old log files");
|
||||
|
||||
time_t rawtime;
|
||||
struct tm* timeinfo;
|
||||
char cmpfilename[30];
|
||||
|
||||
time(&rawtime);
|
||||
rawtime = addDays(rawtime, -retentionInDays + 1);
|
||||
rawtime = addDays(rawtime, -logFileRetentionInDays + 1);
|
||||
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);
|
||||
//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);
|
||||
}
|
||||
|
||||
|
||||
////////////////////// data /////////////////////////////////////////
|
||||
ESP_LOGI(TAG, "remove old data files");
|
||||
void ClassLogFile::RemoveOldDataLog()
|
||||
{
|
||||
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);
|
||||
//ESP_LOGD(TAG, "data file name to compare: %s", cmpfilename);
|
||||
|
||||
dir = opendir(dataroot.c_str());
|
||||
DIR *dir = opendir(dataroot.c_str());
|
||||
if (!dir) {
|
||||
ESP_LOGE(TAG, "Failed to stat dir : %s", dataroot.c_str());
|
||||
return;
|
||||
}
|
||||
|
||||
deleted = 0;
|
||||
notDeleted = 0;
|
||||
struct dirent *entry;
|
||||
int deleted = 0;
|
||||
int notDeleted = 0;
|
||||
while ((entry = readdir(dir)) != NULL) {
|
||||
if (entry->d_type == DT_REG) {
|
||||
//ESP_LOGD(TAG, "Compare data file : %s to %s", entry->d_name, cmpfilename);
|
||||
@@ -367,6 +392,7 @@ void ClassLogFile::RemoveOld()
|
||||
closedir(dir);
|
||||
}
|
||||
|
||||
|
||||
void ClassLogFile::CreateLogDirectories()
|
||||
{
|
||||
MakeDir("/sdcard/log");
|
||||
@@ -384,6 +410,8 @@ ClassLogFile::ClassLogFile(std::string _logroot, std::string _logfile, std::stri
|
||||
logfile = _logfile;
|
||||
datafile = _datafile;
|
||||
dataroot = _logdatapath;
|
||||
retentionInDays = 10;
|
||||
logFileRetentionInDays = 3;
|
||||
dataLogRetentionInDays = 3;
|
||||
doDataLogToSD = true;
|
||||
loglevel = ESP_LOG_INFO;
|
||||
}
|
||||
|
||||
@@ -10,7 +10,9 @@ private:
|
||||
std::string logfile;
|
||||
std::string dataroot;
|
||||
std::string datafile;
|
||||
unsigned short retentionInDays;
|
||||
unsigned short logFileRetentionInDays;
|
||||
unsigned short dataLogRetentionInDays;
|
||||
bool doDataLogToSD;
|
||||
esp_log_level_t loglevel;
|
||||
public:
|
||||
ClassLogFile(std::string _logpath, std::string _logfile, std::string _logdatapath, std::string _datafile);
|
||||
@@ -20,7 +22,10 @@ public:
|
||||
void WriteHeapInfo(std::string _id);
|
||||
|
||||
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);
|
||||
@@ -28,7 +33,8 @@ public:
|
||||
void WriteToDedicatedFile(std::string _fn, esp_log_level_t level, std::string message, bool _time = true);
|
||||
|
||||
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 _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);
|
||||
|
||||
@@ -747,7 +747,8 @@ void task_autodoFlow(void *pvParameter)
|
||||
#ifdef DEBUG_DETAIL_ON
|
||||
ESP_LOGD(TAG, "Remove older log files");
|
||||
#endif
|
||||
LogFile.RemoveOld();
|
||||
LogFile.RemoveOldLogFile();
|
||||
LogFile.RemoveOldDataLog();
|
||||
}
|
||||
|
||||
LogFile.WriteToFile(ESP_LOG_INFO, TAG, "task_autodoFlow - round #" + std::to_string(countRounds) + " done");
|
||||
|
||||
@@ -84,6 +84,10 @@ LEDColor = 150 150 150
|
||||
AutoStart = true
|
||||
Intervall = 5
|
||||
|
||||
[DataLogging]
|
||||
DataLogActive = true
|
||||
DataLogRetentionInDays = 3
|
||||
|
||||
[Debug]
|
||||
Logfile = 1
|
||||
LogfileRetentionInDays = 3
|
||||
|
||||
@@ -9,9 +9,8 @@
|
||||
h1 {font-size: 2em;}
|
||||
h2 {font-size: 1.5em; margin-block-start: 0.0em; margin-block-end: 0.2em;}
|
||||
h3 {font-size: 1.2em;}
|
||||
h4 {
|
||||
margin-bottom: 0;
|
||||
}
|
||||
h4 {font-size: 1em; margin-bottom: 0;}
|
||||
h5 {font-size: 0.83em; margin-top: 0.2em; margin-bottom: 0;}
|
||||
|
||||
p {font-size: 1em;}
|
||||
|
||||
@@ -626,9 +625,11 @@ textarea {
|
||||
</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td colspan="3" style="padding-left: 20px;"><h4>Homeassistant Discovery (using MQTT)</h4>
|
||||
<span style="font-size: 80%;">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://<IP>/mqtt_publish_discovery</a></span></td>
|
||||
<td class="indent1" colspan="3">
|
||||
<h4>Homeassistant Discovery (using MQTT)</h4>
|
||||
<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://<IP>/mqtt_publish_discovery</a></h5>
|
||||
</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td class="indent1">
|
||||
@@ -675,8 +676,7 @@ textarea {
|
||||
<td colspan="3" style="padding-left: 20px;">
|
||||
<h4>
|
||||
<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>
|
||||
</h4>
|
||||
<label for=Category_InfluxDB_enabled>InfluxDB</h4><h5>Only InfluxDB v1.x is supported, v2.x has a changed interface</h5></label>
|
||||
</td>
|
||||
</tr>
|
||||
<tr>
|
||||
@@ -740,41 +740,12 @@ textarea {
|
||||
</td>
|
||||
</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>
|
||||
<td colspan="3" style="padding-left: 20px;">
|
||||
<h4><input type="checkbox" id="Category_GPIO_enabled" value="1" onclick='UpdateAfterCategoryCheck()' unchecked >
|
||||
<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>
|
||||
</td>
|
||||
</tr>
|
||||
@@ -1272,13 +1243,71 @@ textarea {
|
||||
</tr>
|
||||
<!------------- 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>
|
||||
<td colspan="3" style="padding-left: 20px;"><h4>Debug</h4></td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td class="indent1">
|
||||
<input type="checkbox" id="Debug_Logfile_enabled" value="1" onclick = 'InvertEnableItem("Debug", "Logfile")' unchecked >
|
||||
<label for=Debug_Logfile_enabled><class id="Debug_Logfile_text" style="color:black;">Logfile Log Level</class></label>
|
||||
<class id="Debug_Logfile_text" style="color:black;">Logfile Log Level</class>
|
||||
</td>
|
||||
<td>
|
||||
<select id="Debug_Logfile_value1">
|
||||
@@ -1294,8 +1323,7 @@ textarea {
|
||||
</tr>
|
||||
<tr>
|
||||
<td class="indent1">
|
||||
<input type="checkbox" id="Debug_LogfileRetentionInDays_enabled" value="1" onclick = 'InvertEnableItem("Debug", "LogfileRetentionInDays")' unchecked >
|
||||
<label for=Debug_LogfileRetentionInDays_enabled><class id="Debug_LogfileRetentionInDays_text" style="color:black;">LogfileRetentionInDays</class></label>
|
||||
<class id="Debug_LogfileRetentionInDays_text" style="color:black;">LogfileRetentionInDays</class>
|
||||
</td>
|
||||
<td>
|
||||
<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", "Intervall", false);
|
||||
|
||||
WriteParameter(param, category, "Debug", "Logfile", true);
|
||||
WriteParameter(param, category, "Debug", "LogfileRetentionInDays", true);
|
||||
WriteParameter(param, category, "DataLogging", "DataLogActive", false);
|
||||
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", "Hostname", true);
|
||||
@@ -1909,8 +1940,11 @@ function ReadParameterAll()
|
||||
ReadParameter(param, "AutoTimer", "AutoStart", false);
|
||||
ReadParameter(param, "AutoTimer", "Intervall", false);
|
||||
|
||||
ReadParameter(param, "Debug", "Logfile", true);
|
||||
ReadParameter(param, "Debug", "LogfileRetentionInDays", true);
|
||||
ReadParameter(param, "DataLogging", "DataLogActive", false);
|
||||
ReadParameter(param, "DataLogging", "DataLogRetentionInDays", false);
|
||||
|
||||
ReadParameter(param, "Debug", "Logfile", false);
|
||||
ReadParameter(param, "Debug", "LogfileRetentionInDays", false);
|
||||
|
||||
ReadParameter(param, "System", "TimeZone", true);
|
||||
ReadParameter(param, "System", "Hostname", true);
|
||||
|
||||
@@ -231,6 +231,14 @@ function ParseConfig() {
|
||||
ParamAddValue(param, catname, "AutoStart");
|
||||
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";
|
||||
category[catname] = new Object();
|
||||
category[catname]["enabled"] = false;
|
||||
|
||||
Reference in New Issue
Block a user