Explorar el Código

Implement direct data logging

jomjol hace 3 años
padre
commit
3743ac18f5

+ 5 - 0
Changelog.md

@@ -8,6 +8,11 @@
 -   Added PreValue to `/json` ([#1154](https://github.com/jomjol/AI-on-the-edge-device/issues/1154))
 -   Show graph of values direct in the user interface (thanks to [@rdmueller](https://github.com/rdmueller))
 -   SD card info into the "Info" Menue (thanks to [@Slider007]( https://github.com/Slider0007))
+-   Added a logging of the values in a text table in `/log/data` - each measurement is one line
+    -   Format: tabulator separated
+    -   Content: time, raw-value, return-value, pre-value, error-text, cnn-digital, cnn-analog
+    -   ATTENTION: format not fully fixed yet!
+
 
 ### Changed
 

+ 3 - 4
code/components/jomjol_helper/Helper.cpp

@@ -230,10 +230,9 @@ void FindReplace(std::string& line, std::string& oldString, std::string& newStri
 
 void MakeDir(std::string _what)
 {
-//	chdir(_where.c_str());
-
-	if (mkdir(_what.c_str(), S_IRWXU|S_IRWXG|S_IROTH))
-		ESP_LOGD(TAG, "Problem with MakeDir: %s", _what.c_str());
+int mk_ret = mkdir(_what.c_str(), 0775);
+if (mk_ret)
+	ESP_LOGD(TAG, "error with mkdir %s ret %d", _what.c_str(), mk_ret);
 }
 
 

+ 12 - 6
code/components/jomjol_logfile/ClassLogFile.cpp

@@ -95,7 +95,7 @@ void ClassLogFile::WriteToData(std::string _ReturnRawValue, std::string _ReturnV
 
         strftime(buffer, 80, "%Y-%m-%dT%H:%M:%S", timeinfo);
 
-        zwtime = std::string(buffer) + ":\t";
+        zwtime = std::string(buffer) + "\t";
         fputs(zwtime.c_str(), pFile);
         fputs(_ReturnRawValue.c_str(), pFile);
         fputs("\t", pFile);
@@ -104,11 +104,8 @@ void ClassLogFile::WriteToData(std::string _ReturnRawValue, std::string _ReturnV
         fputs(_ReturnPreValue.c_str(), pFile);
         fputs("\t", pFile);
         fputs(_ErrorMessageText.c_str(), pFile);
-        fputs("\t", pFile);
         fputs(_digital.c_str(), pFile);
-        fputs("\t", pFile);
         fputs(_analog.c_str(), pFile);
-        fputs("\t", pFile);
         fputs("\n", pFile);
 
         fclose(pFile);    
@@ -284,6 +281,17 @@ void ClassLogFile::RemoveOld()
     closedir(dir);
 }
 
+void ClassLogFile::CreateLogDirectories()
+{
+    MakeDir("/sdcard/log");
+    MakeDir("/sdcard/log/data");
+    MakeDir("/sdcard/log/analog");
+    MakeDir("/sdcard/log/digit");
+    MakeDir("/sdcard/log/message");
+    MakeDir("/sdcard/log/source");
+}
+
+
 ClassLogFile::ClassLogFile(std::string _logroot, std::string _logfile, std::string _logdatapath, std::string _datafile)
 {
     logroot = _logroot;
@@ -294,6 +302,4 @@ ClassLogFile::ClassLogFile(std::string _logroot, std::string _logfile, std::stri
     retentionInDays = 10;
     loglevel = 0;
     MakeDir("/sdcard/log/data");
-    MakeDir("/sdcard/test");
-    MakeDir("/test");
 }

+ 2 - 0
code/components/jomjol_logfile/ClassLogFile.h

@@ -24,6 +24,8 @@ public:
     void SwitchOnOff(bool _doLogFile);
     void SetRetention(unsigned short _retentionInDays);
 
+    void CreateLogDirectories();
+
     void WriteToFile(std::string info, bool _time = true);
     void WriteToDedicatedFile(std::string _fn, std::string info, bool _time = true);
     void RemoveOld();

+ 12 - 1
code/main/main.cpp

@@ -111,9 +111,9 @@ bool Init_NVS_SDCard()
         }
         return false;
     }
+
     sdmmc_card_print_info(stdout, card);
     SaveSDCardInfo(card);
-
     return true;
 }
 
@@ -167,6 +167,17 @@ extern "C" void app_main(void)
 
     CheckOTAUpdate();
 
+    LogFile.CreateLogDirectories();
+/*
+    int mk_ret = mkdir("/sdcard/new_fd_mkdir", 0775);
+    ESP_LOGI(TAGMAIN, "mkdir ret %d", mk_ret);
+    mk_ret = mkdir("/sdcard/new_fd_mkdir/test", 0775);
+    ESP_LOGI(TAGMAIN, "mkdir ret %d", mk_ret);
+    MakeDir("/sdcard/test2");
+    MakeDir("/sdcard/test2/intern");
+*/
+
+
     char *ssid = NULL, *passwd = NULL, *hostname = NULL, *ip = NULL, *gateway = NULL, *netmask = NULL, *dns = NULL;
     LoadWlanFromFile("/sdcard/wlan.ini", ssid, passwd, hostname, ip, gateway, netmask, dns);