From f9dfc06e1b3d9cb32f3fcaea0a2d22ef674a36ee Mon Sep 17 00:00:00 2001 From: CaCO3 Date: Tue, 21 Feb 2023 23:12:39 +0100 Subject: [PATCH] Migrated parameters, see https://github.com/jomjol/AI-on-the-edge-device/pull/2023 --- .../ClassFlowAlignment.cpp | 8 +- .../ClassFlowCNNGeneral.cpp | 10 +- .../jomjol_flowcontroll/ClassFlowControll.cpp | 46 +-- .../jomjol_flowcontroll/ClassFlowControll.h | 10 +- .../jomjol_flowcontroll/ClassFlowImage.cpp | 20 +- .../jomjol_flowcontroll/ClassFlowImage.h | 4 +- .../jomjol_flowcontroll/ClassFlowMQTT.cpp | 12 +- .../jomjol_flowcontroll/ClassFlowMQTT.h | 4 +- .../ClassFlowMakeImage.cpp | 255 --------------- .../jomjol_flowcontroll/ClassFlowMakeImage.h | 55 ---- .../ClassFlowPostProcessing.cpp | 12 +- .../ClassFlowPostProcessing.h | 4 +- .../ClassFlowTakeImage.cpp | 255 +++++++++++++++ .../jomjol_flowcontroll/ClassFlowTakeImage.h | 55 ++++ .../components/jomjol_mqtt/interface_mqtt.cpp | 11 +- code/components/jomjol_mqtt/interface_mqtt.h | 4 +- code/components/jomjol_mqtt/server_mqtt.cpp | 6 +- code/components/jomjol_mqtt/server_mqtt.h | 4 +- .../jomjol_tfliteclass/server_tflite.cpp | 14 +- code/components/jomjol_wlan/connect_wlan.cpp | 6 +- code/components/jomjol_wlan/connect_wlan.h | 4 +- code/components/jomjol_wlan/read_wlanini.cpp | 20 +- code/components/jomjol_wlan/read_wlanini.h | 4 +- code/include/defines.h | 5 +- code/main/main.cpp | 265 +++++++++++++++- code/main/softAP.cpp | 6 +- .../test_flow_postrocess_helper.cpp | 6 +- .../test_flow_postrocess_helper.h | 2 +- sd-card/config/config.ini | 37 ++- sd-card/html/edit_config_param.html | 298 ++++++++++-------- sd-card/html/edit_reference.html | 112 +++---- sd-card/html/readconfigparam.js | 59 ++-- 32 files changed, 943 insertions(+), 670 deletions(-) create mode 100644 code/components/jomjol_flowcontroll/ClassFlowTakeImage.cpp create mode 100644 code/components/jomjol_flowcontroll/ClassFlowTakeImage.h diff --git a/code/components/jomjol_flowcontroll/ClassFlowAlignment.cpp b/code/components/jomjol_flowcontroll/ClassFlowAlignment.cpp index 1b686176d..2514d5f9f 100644 --- a/code/components/jomjol_flowcontroll/ClassFlowAlignment.cpp +++ b/code/components/jomjol_flowcontroll/ClassFlowAlignment.cpp @@ -1,5 +1,5 @@ #include "ClassFlowAlignment.h" -#include "ClassFlowMakeImage.h" +#include "ClassFlowTakeImage.h" #include "ClassFlow.h" #include "server_tflite.h" @@ -46,9 +46,9 @@ ClassFlowAlignment::ClassFlowAlignment(std::vector* lfc) for (int i = 0; i < ListFlowControll->size(); ++i) { - if (((*ListFlowControll)[i])->name().compare("ClassFlowMakeImage") == 0) + if (((*ListFlowControll)[i])->name().compare("ClassFlowTakeImage") == 0) { - ImageBasis = ((ClassFlowMakeImage*) (*ListFlowControll)[i])->rawImage; + ImageBasis = ((ClassFlowTakeImage*) (*ListFlowControll)[i])->rawImage; } } @@ -74,7 +74,7 @@ bool ClassFlowAlignment::ReadParameter(FILE* pfile, string& aktparamgraph) if (!this->GetNextParagraph(pfile, aktparamgraph)) return false; - if (aktparamgraph.compare("[Alignment]") != 0) //Paragraph does not fit MakeImage + if (aktparamgraph.compare("[Alignment]") != 0) //Paragraph does not fit Alignment return false; while (this->getNextLine(pfile, &aktparamgraph) && !this->isNewParagraph(aktparamgraph)) diff --git a/code/components/jomjol_flowcontroll/ClassFlowCNNGeneral.cpp b/code/components/jomjol_flowcontroll/ClassFlowCNNGeneral.cpp index f06c4fcac..ed071fa92 100644 --- a/code/components/jomjol_flowcontroll/ClassFlowCNNGeneral.cpp +++ b/code/components/jomjol_flowcontroll/ClassFlowCNNGeneral.cpp @@ -34,7 +34,7 @@ ClassFlowCNNGeneral::ClassFlowCNNGeneral(ClassFlowAlignment *_flowalign, t_CNNTy CNNType = AutoDetect; CNNType = _cnntype; flowpostalignment = _flowalign; - logfileRetentionInDays = 5; + imagesRetention = 5; } @@ -324,9 +324,9 @@ bool ClassFlowCNNGeneral::ReadParameter(FILE* pfile, string& aktparamgraph) while (this->getNextLine(pfile, &aktparamgraph) && !this->isNewParagraph(aktparamgraph)) { splitted = ZerlegeZeile(aktparamgraph); - if ((toUpper(splitted[0]) == "LOGIMAGELOCATION") && (splitted.size() > 1)) + if ((toUpper(splitted[0]) == "ROIIMAGESLOCATION") && (splitted.size() > 1)) { - this->LogImageLocation = "/sdcard" + splitted[1]; + this->imagesLocation = "/sdcard" + splitted[1]; this->isLogImage = true; } if ((toUpper(splitted[0]) == "LOGIMAGESELECT") && (splitted.size() > 1)) @@ -335,9 +335,9 @@ bool ClassFlowCNNGeneral::ReadParameter(FILE* pfile, string& aktparamgraph) isLogImageSelect = true; } - if ((toUpper(splitted[0]) == "LOGFILERETENTIONINDAYS") && (splitted.size() > 1)) + if ((toUpper(splitted[0]) == "ROIIMAGESRETENTION") && (splitted.size() > 1)) { - this->logfileRetentionInDays = std::stoi(splitted[1]); + this->imagesRetention = std::stoi(splitted[1]); } if ((toUpper(splitted[0]) == "MODEL") && (splitted.size() > 1)) diff --git a/code/components/jomjol_flowcontroll/ClassFlowControll.cpp b/code/components/jomjol_flowcontroll/ClassFlowControll.cpp index 667ab683b..94d3d9cba 100644 --- a/code/components/jomjol_flowcontroll/ClassFlowControll.cpp +++ b/code/components/jomjol_flowcontroll/ClassFlowControll.cpp @@ -38,8 +38,8 @@ std::string ClassFlowControll::doSingleStep(std::string _stepname, std::string _ ESP_LOGD(TAG, "Step %s start", _stepname.c_str()); - if ((_stepname.compare("[MakeImage]") == 0) || (_stepname.compare(";[MakeImage]") == 0)){ - _classname = "ClassFlowMakeImage"; + if ((_stepname.compare("[TakeImage]") == 0) || (_stepname.compare(";[TakeImage]") == 0)){ + _classname = "ClassFlowTakeImage"; } if ((_stepname.compare("[Alignment]") == 0) || (_stepname.compare(";[Alignment]") == 0)){ _classname = "ClassFlowAlignment"; @@ -64,7 +64,7 @@ std::string ClassFlowControll::doSingleStep(std::string _stepname, std::string _ for (int i = 0; i < FlowControll.size(); ++i) if (FlowControll[i]->name().compare(_classname) == 0){ - if (!(FlowControll[i]->name().compare("ClassFlowMakeImage") == 0)) // if it is a MakeImage, the image does not need to be included, this happens automatically with the html query. + if (!(FlowControll[i]->name().compare("ClassFlowTakeImage") == 0)) // if it is a TakeImage, the image does not need to be included, this happens automatically with the html query. FlowControll[i]->doFlow(""); result = FlowControll[i]->getHTMLSingleStep(_host); } @@ -77,7 +77,7 @@ std::string ClassFlowControll::doSingleStep(std::string _stepname, std::string _ std::string ClassFlowControll::TranslateAktstatus(std::string _input) { - if (_input.compare("ClassFlowMakeImage") == 0) + if (_input.compare("ClassFlowTakeImage") == 0) return ("Take Image"); if (_input.compare("ClassFlowAlignment") == 0) return ("Aligning"); @@ -171,7 +171,7 @@ bool ClassFlowControll::StartMQTTService() { /* Start the MQTT service */ for (int i = 0; i < FlowControll.size(); ++i) { if (FlowControll[i]->name().compare("ClassFlowMQTT") == 0) { - return ((ClassFlowMQTT*) (FlowControll[i]))->Start(AutoIntervall); + return ((ClassFlowMQTT*) (FlowControll[i]))->Start(AutoInterval); } } return false; @@ -183,7 +183,7 @@ void ClassFlowControll::SetInitialParameter(void) { AutoStart = false; SetupModeActive = false; - AutoIntervall = 10; // Minutes + AutoInterval = 10; // Minutes flowdigit = NULL; flowanalog = NULL; flowpostprocessing = NULL; @@ -193,9 +193,9 @@ void ClassFlowControll::SetInitialParameter(void) } -bool ClassFlowControll::isAutoStart(long &_intervall) +bool ClassFlowControll::isAutoStart(long &_interval) { - _intervall = AutoIntervall * 60 * 1000; // AutoInterval: minutes -> ms + _interval = AutoInterval * 60 * 1000; // AutoInterval: minutes -> ms return AutoStart; } @@ -206,10 +206,10 @@ ClassFlow* ClassFlowControll::CreateClassFlow(std::string _type) _type = trim(_type); - if (toUpper(_type).compare("[MAKEIMAGE]") == 0) + if (toUpper(_type).compare("[TAKEIMAGE]") == 0) { - cfc = new ClassFlowMakeImage(&FlowControll); - flowmakeimage = (ClassFlowMakeImage*) cfc; + cfc = new ClassFlowTakeImage(&FlowControll); + flowtakeimage = (ClassFlowTakeImage*) cfc; } if (toUpper(_type).compare("[ALIGNMENT]") == 0) { @@ -322,13 +322,13 @@ void ClassFlowControll::setActStatus(std::string _aktstatus) } -void ClassFlowControll::doFlowMakeImageOnly(string time) +void ClassFlowControll::doFlowTakeImageOnly(string time) { std::string zw_time; for (int i = 0; i < FlowControll.size(); ++i) { - if (FlowControll[i]->name() == "ClassFlowMakeImage") { + if (FlowControll[i]->name() == "ClassFlowTakeImage") { zw_time = getCurrentTimeString("%H:%M:%S"); std::string flowStatus = TranslateAktstatus(FlowControll[i]->name()); aktstatus = flowStatus + " (" + zw_time + ")"; @@ -527,7 +527,7 @@ bool ClassFlowControll::ReadParameter(FILE* pfile, string& aktparamgraph) 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 + (toUpper(aktparamgraph).compare("[SYSTEM]") != 0 && (toUpper(aktparamgraph).compare("[DATALOGGING]") != 0))) // Paragraph passt nicht zu Debug oder DataLogging return false; while (this->getNextLine(pfile, &aktparamgraph) && !this->isNewParagraph(aktparamgraph)) @@ -541,9 +541,9 @@ bool ClassFlowControll::ReadParameter(FILE* pfile, string& aktparamgraph) } } - if ((toUpper(splitted[0]) == "INTERVALL") && (splitted.size() > 1)) + if ((toUpper(splitted[0]) == "INTERVAL") && (splitted.size() > 1)) { - AutoIntervall = std::stof(splitted[1]); + AutoInterval = std::stof(splitted[1]); } if ((toUpper(splitted[0]) == "DATALOGACTIVE") && (splitted.size() > 1)) @@ -557,12 +557,12 @@ bool ClassFlowControll::ReadParameter(FILE* pfile, string& aktparamgraph) } } - if ((toUpper(splitted[0]) == "DATALOGRETENTIONINDAYS") && (splitted.size() > 1)) + if ((toUpper(splitted[0]) == "DATAFILESRETENTION") && (splitted.size() > 1)) { LogFile.SetDataLogRetention(std::stoi(splitted[1])); } - if ((toUpper(splitted[0]) == "LOGFILE") && (splitted.size() > 1)) + if ((toUpper(splitted[0]) == "LOGLEVEL") && (splitted.size() > 1)) { /* matches esp_log_level_t */ if ((toUpper(splitted[1]) == "TRUE") || (toUpper(splitted[1]) == "2")) @@ -582,20 +582,20 @@ bool ClassFlowControll::ReadParameter(FILE* pfile, string& aktparamgraph) LogFile.setLogLevel(ESP_LOG_DEBUG); } } - if ((toUpper(splitted[0]) == "LOGFILERETENTIONINDAYS") && (splitted.size() > 1)) + if ((toUpper(splitted[0]) == "LOGFILESRETENTION") && (splitted.size() > 1)) { LogFile.SetLogFileRetention(std::stoi(splitted[1])); } /* TimeServer and TimeZone got already read from the config, see setupTime () */ - if ((toUpper(splitted[0]) == "RSSITHREASHOLD") && (splitted.size() > 1)) + if ((toUpper(splitted[0]) == "RSSITHRESHOLD") && (splitted.size() > 1)) { - if (ChangeRSSIThreashold(WLAN_CONFIG_FILE, atoi(splitted[1].c_str()))) + if (ChangeRSSIThreshold(WLAN_CONFIG_FILE, atoi(splitted[1].c_str()))) { // reboot necessary so that the new wlan.ini is also used !!! fclose(pfile); - LogFile.WriteToFile(ESP_LOG_ERROR, TAG, "Rebooting to activate new RSSITHREASHOLD ..."); + LogFile.WriteToFile(ESP_LOG_ERROR, TAG, "Rebooting to activate new RSSITHRESHOLD ..."); esp_restart(); hard_restart(); doReboot(); @@ -660,7 +660,7 @@ int ClassFlowControll::CleanTempFolder() { esp_err_t ClassFlowControll::SendRawJPG(httpd_req_t *req) { - return flowmakeimage != NULL ? flowmakeimage->SendRawJPG(req) : ESP_FAIL; + return flowtakeimage != NULL ? flowtakeimage->SendRawJPG(req) : ESP_FAIL; } diff --git a/code/components/jomjol_flowcontroll/ClassFlowControll.h b/code/components/jomjol_flowcontroll/ClassFlowControll.h index fdcad3110..e42cf0947 100644 --- a/code/components/jomjol_flowcontroll/ClassFlowControll.h +++ b/code/components/jomjol_flowcontroll/ClassFlowControll.h @@ -6,7 +6,7 @@ #include #include "ClassFlow.h" -#include "ClassFlowMakeImage.h" +#include "ClassFlowTakeImage.h" #include "ClassFlowAlignment.h" #include "ClassFlowCNNGeneral.h" #include "ClassFlowPostProcessing.h" @@ -29,11 +29,11 @@ class ClassFlowControll : ClassFlowCNNGeneral* flowanalog; ClassFlowCNNGeneral* flowdigit; // ClassFlowDigit* flowdigit; - ClassFlowMakeImage* flowmakeimage; + ClassFlowTakeImage* flowtakeimage; ClassFlow* CreateClassFlow(std::string _type); bool AutoStart; - float AutoIntervall; + float AutoInterval; bool SetupModeActive; void SetInitialParameter(void); std::string aktstatus; @@ -42,7 +42,7 @@ class ClassFlowControll : public: void InitFlow(std::string config); bool doFlow(string time); - void doFlowMakeImageOnly(string time); + void doFlowTakeImageOnly(string time); bool getStatusSetupModus(){return SetupModeActive;}; string getReadout(bool _rawvalue, bool _noerror); string getReadoutAll(int _type); @@ -68,7 +68,7 @@ class ClassFlowControll : std::string doSingleStep(std::string _stepname, std::string _host); - bool isAutoStart(long &_intervall); + bool isAutoStart(long &_interval); std::string* getActStatus(); void setActStatus(std::string _aktstatus); diff --git a/code/components/jomjol_flowcontroll/ClassFlowImage.cpp b/code/components/jomjol_flowcontroll/ClassFlowImage.cpp index ec892075d..29a3f6b2d 100644 --- a/code/components/jomjol_flowcontroll/ClassFlowImage.cpp +++ b/code/components/jomjol_flowcontroll/ClassFlowImage.cpp @@ -24,7 +24,7 @@ ClassFlowImage::ClassFlowImage(const char* logTag) this->logTag = logTag; isLogImage = false; disabled = false; - this->logfileRetentionInDays = 5; + this->imagesRetention = 5; } ClassFlowImage::ClassFlowImage(std::vector * lfc, const char* logTag) : ClassFlow(lfc) @@ -32,7 +32,7 @@ ClassFlowImage::ClassFlowImage(std::vector * lfc, const char* logTag this->logTag = logTag; isLogImage = false; disabled = false; - this->logfileRetentionInDays = 5; + this->imagesRetention = 5; } ClassFlowImage::ClassFlowImage(std::vector * lfc, ClassFlow *_prev, const char* logTag) : ClassFlow(lfc, _prev) @@ -40,7 +40,7 @@ ClassFlowImage::ClassFlowImage(std::vector * lfc, ClassFlow *_prev, this->logTag = logTag; isLogImage = false; disabled = false; - this->logfileRetentionInDays = 5; + this->imagesRetention = 5; } @@ -48,7 +48,7 @@ string ClassFlowImage::CreateLogFolder(string time) { if (!isLogImage) return ""; - string logPath = LogImageLocation + "/" + 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) { LogFile.WriteToFile(ESP_LOG_ERROR, TAG, "Can't create log folder for analog images. Path " + logPath); @@ -95,7 +95,7 @@ void ClassFlowImage::RemoveOldLogs() return; ESP_LOGD(TAG, "remove old images"); - if (logfileRetentionInDays == 0) { + if (imagesRetention == 0) { return; } @@ -104,17 +104,17 @@ void ClassFlowImage::RemoveOldLogs() char cmpfilename[30]; time(&rawtime); - rawtime = addDays(rawtime, -logfileRetentionInDays + 1); + rawtime = addDays(rawtime, -1 * imagesRetention + 1); timeinfo = localtime(&rawtime); - //ESP_LOGD(TAG, "ImagefileRetentionInDays: %d", logfileRetentionInDays); + //ESP_LOGD(TAG, "ImagefileRetentionInDays: %d", imagesRetention); strftime(cmpfilename, 30, LOGFILE_TIME_FORMAT, timeinfo); //ESP_LOGD(TAG, "file name to compare: %s", cmpfilename); string folderName = string(cmpfilename).LOGFILE_TIME_FORMAT_DATE_EXTR; - DIR *dir = opendir(LogImageLocation.c_str()); + DIR *dir = opendir(imagesLocation.c_str()); if (!dir) { - ESP_LOGE(TAG, "Failed to stat dir: %s", LogImageLocation.c_str()); + ESP_LOGE(TAG, "Failed to stat dir: %s", imagesLocation.c_str()); return; } @@ -122,7 +122,7 @@ void ClassFlowImage::RemoveOldLogs() int deleted = 0; int notDeleted = 0; while ((entry = readdir(dir)) != NULL) { - string folderPath = LogImageLocation + "/" + entry->d_name; + string folderPath = imagesLocation + "/" + entry->d_name; if (entry->d_type == DT_DIR) { //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)) { diff --git a/code/components/jomjol_flowcontroll/ClassFlowImage.h b/code/components/jomjol_flowcontroll/ClassFlowImage.h index 19cb916d5..5d41a18bf 100644 --- a/code/components/jomjol_flowcontroll/ClassFlowImage.h +++ b/code/components/jomjol_flowcontroll/ClassFlowImage.h @@ -10,9 +10,9 @@ using namespace std; class ClassFlowImage : public ClassFlow { protected: - string LogImageLocation; + string imagesLocation; bool isLogImage; - unsigned short logfileRetentionInDays; + unsigned short imagesRetention; const char* logTag; string CreateLogFolder(string time); diff --git a/code/components/jomjol_flowcontroll/ClassFlowMQTT.cpp b/code/components/jomjol_flowcontroll/ClassFlowMQTT.cpp index a62d8b96b..cb5d53f5f 100644 --- a/code/components/jomjol_flowcontroll/ClassFlowMQTT.cpp +++ b/code/components/jomjol_flowcontroll/ClassFlowMQTT.cpp @@ -42,7 +42,7 @@ void ClassFlowMQTT::SetInitialParameter(void) flowpostprocessing = NULL; user = ""; password = ""; - SetRetainFlag = 0; + SetRetainFlag = false; previousElement = NULL; ListFlowControll = NULL; disabled = false; @@ -95,7 +95,7 @@ bool ClassFlowMQTT::ReadParameter(FILE* pfile, string& aktparamgraph) if (!this->GetNextParagraph(pfile, aktparamgraph)) return false; - if (toUpper(aktparamgraph).compare("[MQTT]") != 0) // Paragraph does not fit MakeImage + if (toUpper(aktparamgraph).compare("[MQTT]") != 0) // Paragraph does not fit MQTT return false; while (this->getNextLine(pfile, &aktparamgraph) && !this->isNewParagraph(aktparamgraph)) @@ -113,10 +113,10 @@ bool ClassFlowMQTT::ReadParameter(FILE* pfile, string& aktparamgraph) { this->uri = splitted[1]; } - if ((toUpper(splitted[0]) == "SETRETAINFLAG") && (splitted.size() > 1)) + if ((toUpper(splitted[0]) == "RETAINMESSAGES") && (splitted.size() > 1)) { if (toUpper(splitted[1]) == "TRUE") { - SetRetainFlag = 1; + SetRetainFlag = true; setMqtt_Server_Retain(SetRetainFlag); } } @@ -184,9 +184,9 @@ string ClassFlowMQTT::GetMQTTMainTopic() } -bool ClassFlowMQTT::Start(float AutoIntervall) +bool ClassFlowMQTT::Start(float AutoInterval) { - roundInterval = AutoIntervall; // Minutes + roundInterval = AutoInterval; // Minutes keepAlive = roundInterval * 60 * 2.5; // Seconds, make sure it is greater thatn 2 rounds! std::stringstream stream; diff --git a/code/components/jomjol_flowcontroll/ClassFlowMQTT.h b/code/components/jomjol_flowcontroll/ClassFlowMQTT.h index 75ed49c5f..3bf924998 100644 --- a/code/components/jomjol_flowcontroll/ClassFlowMQTT.h +++ b/code/components/jomjol_flowcontroll/ClassFlowMQTT.h @@ -19,7 +19,7 @@ class ClassFlowMQTT : std::string OldValue; ClassFlowPostProcessing* flowpostprocessing; std::string user, password; - int SetRetainFlag; + bool SetRetainFlag; int keepAlive; // Seconds float roundInterval; // Minutes @@ -32,7 +32,7 @@ class ClassFlowMQTT : ClassFlowMQTT(std::vector* lfc, ClassFlow *_prev); string GetMQTTMainTopic(); - bool Start(float AutoIntervall); + bool Start(float AutoInterval); bool ReadParameter(FILE* pfile, string& aktparamgraph); bool doFlow(string time); diff --git a/code/components/jomjol_flowcontroll/ClassFlowMakeImage.cpp b/code/components/jomjol_flowcontroll/ClassFlowMakeImage.cpp index dfd67d162..e69de29bb 100644 --- a/code/components/jomjol_flowcontroll/ClassFlowMakeImage.cpp +++ b/code/components/jomjol_flowcontroll/ClassFlowMakeImage.cpp @@ -1,255 +0,0 @@ -#include "ClassFlowMakeImage.h" -#include "Helper.h" -#include "ClassLogFile.h" - -#include "CImageBasis.h" -#include "ClassControllCamera.h" - -#include "esp_wifi.h" -#include "esp_log.h" -#include "../../include/defines.h" - -#include - -// #define DEBUG_DETAIL_ON - -// #define WIFITURNOFF - -static const char* TAG = "flow_make_image"; - -esp_err_t ClassFlowMakeImage::camera_capture(){ - string nm = namerawimage; - Camera.CaptureToFile(nm); - time(&TimeImageTaken); - localtime(&TimeImageTaken); - - return ESP_OK; -} - -void ClassFlowMakeImage::takePictureWithFlash(int flash_duration) -{ - // in case the image is flipped, it must be reset here // - rawImage->width = image_width; - rawImage->height = image_height; - ///////////////////////////////////////////////////////////////////////////////////// - ESP_LOGD(TAG, "flash_duration: %d", flash_duration); - Camera.CaptureToBasisImage(rawImage, flash_duration); - time(&TimeImageTaken); - localtime(&TimeImageTaken); - - if (SaveAllFiles) rawImage->SaveToFile(namerawimage); -} - -void ClassFlowMakeImage::SetInitialParameter(void) -{ - waitbeforepicture = 5; - isImageSize = false; - ImageQuality = -1; - TimeImageTaken = 0; - ImageQuality = 5; - rawImage = NULL; - ImageSize = FRAMESIZE_VGA; - SaveAllFiles = false; - disabled = false; - FixedExposure = false; - namerawimage = "/sdcard/img_tmp/raw.jpg"; -} - - -ClassFlowMakeImage::ClassFlowMakeImage(std::vector* lfc) : ClassFlowImage(lfc, TAG) -{ - LogImageLocation = "/log/source"; - logfileRetentionInDays = 5; - SetInitialParameter(); -} - - -bool ClassFlowMakeImage::ReadParameter(FILE* pfile, string& aktparamgraph) -{ - std::vector splitted; - - aktparamgraph = trim(aktparamgraph); - int _brightness = -100; - int _contrast = -100; - int _saturation = -100; - - if (aktparamgraph.size() == 0) - if (!this->GetNextParagraph(pfile, aktparamgraph)) - return false; - - if (aktparamgraph.compare("[MakeImage]") != 0) // Paragraph does not fit MakeImage - return false; - - while (this->getNextLine(pfile, &aktparamgraph) && !this->isNewParagraph(aktparamgraph)) - { - splitted = ZerlegeZeile(aktparamgraph); - if ((splitted[0] == "LogImageLocation") && (splitted.size() > 1)) - { - LogImageLocation = "/sdcard" + splitted[1]; - isLogImage = true; - } - if ((splitted[0] == "ImageQuality") && (splitted.size() > 1)) - ImageQuality = std::stod(splitted[1]); - - if ((splitted[0] == "ImageSize") && (splitted.size() > 1)) - { - ImageSize = Camera.TextToFramesize(splitted[1].c_str()); - isImageSize = true; - } - - if ((toUpper(splitted[0]) == "SAVEALLFILES") && (splitted.size() > 1)) - { - if (toUpper(splitted[1]) == "TRUE") - SaveAllFiles = true; - } - - if ((toUpper(splitted[0]) == "WAITBEFORETAKINGPICTURE") && (splitted.size() > 1)) - { - waitbeforepicture = stoi(splitted[1]); - } - - if ((toUpper(splitted[0]) == "LOGFILERETENTIONINDAYS") && (splitted.size() > 1)) - { - this->logfileRetentionInDays = std::stoi(splitted[1]); - } - - if ((toUpper(splitted[0]) == "BRIGHTNESS") && (splitted.size() > 1)) - { - _brightness = stoi(splitted[1]); - } - - if ((toUpper(splitted[0]) == "CONTRAST") && (splitted.size() > 1)) - { - _contrast = stoi(splitted[1]); - } - - if ((toUpper(splitted[0]) == "SATURATION") && (splitted.size() > 1)) - { - _saturation = stoi(splitted[1]); - } - - if ((toUpper(splitted[0]) == "FIXEDEXPOSURE") && (splitted.size() > 1)) - { - if (toUpper(splitted[1]) == "TRUE") - FixedExposure = true; - } - - if ((toUpper(splitted[0]) == "LEDINTENSITY") && (splitted.size() > 1)) - { - float ledintensity = stof(splitted[1]); - ledintensity = min((float) 100, ledintensity); - ledintensity = max((float) 0, ledintensity); - Camera.SetLEDIntensity(ledintensity); - } - - if ((toUpper(splitted[0]) == "DEMO") && (splitted.size() > 1)) - { - if (toUpper(splitted[1]) == "TRUE") - Camera.useDemoMode(); - } - } - - Camera.SetBrightnessContrastSaturation(_brightness, _contrast, _saturation); - Camera.SetQualitySize(ImageQuality, ImageSize); - - image_width = Camera.image_width; - image_height = Camera.image_height; - rawImage = new CImageBasis(); - rawImage->CreateEmptyImage(image_width, image_height, 3); - - waitbeforepicture_store = waitbeforepicture; - if (FixedExposure && (waitbeforepicture > 0)) - { -// ESP_LOGD(TAG, "Fixed Exposure enabled!"); - int flash_duration = (int) (waitbeforepicture * 1000); - Camera.EnableAutoExposure(flash_duration); - waitbeforepicture = 0.2; -// flash_duration = (int) (waitbeforepicture * 1000); -// takePictureWithFlash(flash_duration); -// rawImage->SaveToFile("/sdcard/init2.jpg"); - } - - return true; -} - - -string ClassFlowMakeImage::getHTMLSingleStep(string host) -{ - string result; - result = "Raw Image:
\n\n"; - return result; -} - - -bool ClassFlowMakeImage::doFlow(string zwtime) -{ - string logPath = CreateLogFolder(zwtime); - - int flash_duration = (int) (waitbeforepicture * 1000); - - #ifdef DEBUG_DETAIL_ON - LogFile.WriteHeapInfo("ClassFlowMakeImage::doFlow - Before takePictureWithFlash"); - #endif - - - #ifdef WIFITURNOFF - esp_wifi_stop(); // to save power usage and - #endif - - takePictureWithFlash(flash_duration); - - #ifdef WIFITURNOFF - esp_wifi_start(); - #endif - - - #ifdef DEBUG_DETAIL_ON - LogFile.WriteHeapInfo("ClassFlowMakeImage::doFlow - After takePictureWithFlash"); - #endif - - LogImage(logPath, "raw", NULL, NULL, zwtime, rawImage); - - RemoveOldLogs(); - - #ifdef DEBUG_DETAIL_ON - LogFile.WriteHeapInfo("ClassFlowMakeImage::doFlow - After RemoveOldLogs"); - #endif - - return true; -} - - -esp_err_t ClassFlowMakeImage::SendRawJPG(httpd_req_t *req) -{ - int flash_duration = (int) (waitbeforepicture * 1000); - time(&TimeImageTaken); - localtime(&TimeImageTaken); - - return Camera.CaptureToHTTP(req, flash_duration); -} - - -ImageData* ClassFlowMakeImage::SendRawImage() -{ - CImageBasis *zw = new CImageBasis(rawImage); - ImageData *id; - int flash_duration = (int) (waitbeforepicture * 1000); - Camera.CaptureToBasisImage(zw, flash_duration); - time(&TimeImageTaken); - localtime(&TimeImageTaken); - - id = zw->writeToMemoryAsJPG(); - delete zw; - return id; -} - -time_t ClassFlowMakeImage::getTimeImageTaken() -{ - return TimeImageTaken; -} - -ClassFlowMakeImage::~ClassFlowMakeImage(void) -{ - delete rawImage; -} - diff --git a/code/components/jomjol_flowcontroll/ClassFlowMakeImage.h b/code/components/jomjol_flowcontroll/ClassFlowMakeImage.h index d15433993..e69de29bb 100644 --- a/code/components/jomjol_flowcontroll/ClassFlowMakeImage.h +++ b/code/components/jomjol_flowcontroll/ClassFlowMakeImage.h @@ -1,55 +0,0 @@ -#pragma once - -#ifndef CLASSFFLOWMAKEIMAGE_H -#define CLASSFFLOWMAKEIMAGE_H - -#include "ClassFlowImage.h" -#include "ClassControllCamera.h" -#include "../../include/defines.h" - -#include - -class ClassFlowMakeImage : - public ClassFlowImage -{ -protected: - float waitbeforepicture; - float waitbeforepicture_store; - framesize_t ImageSize; - bool isImageSize; - int ImageQuality; - time_t TimeImageTaken; - string namerawimage; - int image_height, image_width; - bool SaveAllFiles; - bool FixedExposure; - - - - void CopyFile(string input, string output); - - esp_err_t camera_capture(); - void takePictureWithFlash(int flash_duration); - - - void SetInitialParameter(void); - -public: - CImageBasis *rawImage; - - ClassFlowMakeImage(std::vector* lfc); - - bool ReadParameter(FILE* pfile, string& aktparamgraph); - bool doFlow(string time); - string getHTMLSingleStep(string host); - time_t getTimeImageTaken(); - string name(){return "ClassFlowMakeImage";}; - - ImageData* SendRawImage(); - esp_err_t SendRawJPG(httpd_req_t *req); - - ~ClassFlowMakeImage(void); -}; - - -#endif //CLASSFFLOWMAKEIMAGE_H \ No newline at end of file diff --git a/code/components/jomjol_flowcontroll/ClassFlowPostProcessing.cpp b/code/components/jomjol_flowcontroll/ClassFlowPostProcessing.cpp index a8645c2fc..22e4ff72d 100644 --- a/code/components/jomjol_flowcontroll/ClassFlowPostProcessing.cpp +++ b/code/components/jomjol_flowcontroll/ClassFlowPostProcessing.cpp @@ -1,6 +1,6 @@ #include "ClassFlowPostProcessing.h" #include "Helper.h" -#include "ClassFlowMakeImage.h" +#include "ClassFlowTakeImage.h" #include "ClassLogFile.h" #include @@ -285,7 +285,7 @@ ClassFlowPostProcessing::ClassFlowPostProcessing(std::vector* lfc, C ListFlowControll = NULL; FilePreValue = FormatFileName("/sdcard/config/prevalue.ini"); ListFlowControll = lfc; - flowMakeImage = NULL; + flowTakeImage = NULL; UpdatePreValueINI = false; IgnoreLeadingNaN = false; flowAnalog = _analog; @@ -293,9 +293,9 @@ ClassFlowPostProcessing::ClassFlowPostProcessing(std::vector* lfc, C for (int i = 0; i < ListFlowControll->size(); ++i) { - if (((*ListFlowControll)[i])->name().compare("ClassFlowMakeImage") == 0) + if (((*ListFlowControll)[i])->name().compare("ClassFlowTakeImage") == 0) { - flowMakeImage = (ClassFlowMakeImage*) (*ListFlowControll)[i]; + flowTakeImage = (ClassFlowTakeImage*) (*ListFlowControll)[i]; } } } @@ -503,7 +503,7 @@ bool ClassFlowPostProcessing::ReadParameter(FILE* pfile, string& aktparamgraph) return false; - if (aktparamgraph.compare("[PostProcessing]") != 0) // Paragraph does not fit MakeImage + if (aktparamgraph.compare("[PostProcessing]") != 0) // Paragraph does not fit PostProcessing return false; InitNUMBERS(); @@ -715,7 +715,7 @@ bool ClassFlowPostProcessing::doFlow(string zwtime) // Update decimal point, as the decimal places can also change when changing from CNNType Auto --> xyz: - imagetime = flowMakeImage->getTimeImageTaken(); + imagetime = flowTakeImage->getTimeImageTaken(); if (imagetime == 0) time(&imagetime); diff --git a/code/components/jomjol_flowcontroll/ClassFlowPostProcessing.h b/code/components/jomjol_flowcontroll/ClassFlowPostProcessing.h index b2fbc4b8b..0cc97a33e 100644 --- a/code/components/jomjol_flowcontroll/ClassFlowPostProcessing.h +++ b/code/components/jomjol_flowcontroll/ClassFlowPostProcessing.h @@ -4,7 +4,7 @@ #define CLASSFFLOWPOSTPROCESSING_H #include "ClassFlow.h" -#include "ClassFlowMakeImage.h" +#include "ClassFlowTakeImage.h" #include "ClassFlowCNNGeneral.h" #include "ClassFlowDefineTypes.h" @@ -29,7 +29,7 @@ class ClassFlowPostProcessing : string FilePreValue; - ClassFlowMakeImage *flowMakeImage; + ClassFlowTakeImage *flowTakeImage; bool LoadPreValue(void); string ShiftDecimal(string in, int _decShift); diff --git a/code/components/jomjol_flowcontroll/ClassFlowTakeImage.cpp b/code/components/jomjol_flowcontroll/ClassFlowTakeImage.cpp new file mode 100644 index 000000000..5c19fb0bd --- /dev/null +++ b/code/components/jomjol_flowcontroll/ClassFlowTakeImage.cpp @@ -0,0 +1,255 @@ +#include "ClassFlowTakeImage.h" +#include "Helper.h" +#include "ClassLogFile.h" + +#include "CImageBasis.h" +#include "ClassControllCamera.h" + +#include "esp_wifi.h" +#include "esp_log.h" +#include "../../include/defines.h" + +#include + +// #define DEBUG_DETAIL_ON + +// #define WIFITURNOFF + +static const char* TAG = "flow_make_image"; + +esp_err_t ClassFlowTakeImage::camera_capture(){ + string nm = namerawimage; + Camera.CaptureToFile(nm); + time(&TimeImageTaken); + localtime(&TimeImageTaken); + + return ESP_OK; +} + +void ClassFlowTakeImage::takePictureWithFlash(int flash_duration) +{ + // in case the image is flipped, it must be reset here // + rawImage->width = image_width; + rawImage->height = image_height; + ///////////////////////////////////////////////////////////////////////////////////// + ESP_LOGD(TAG, "flash_duration: %d", flash_duration); + Camera.CaptureToBasisImage(rawImage, flash_duration); + time(&TimeImageTaken); + localtime(&TimeImageTaken); + + if (SaveAllFiles) rawImage->SaveToFile(namerawimage); +} + +void ClassFlowTakeImage::SetInitialParameter(void) +{ + waitbeforepicture = 5; + isImageSize = false; + ImageQuality = -1; + TimeImageTaken = 0; + ImageQuality = 5; + rawImage = NULL; + ImageSize = FRAMESIZE_VGA; + SaveAllFiles = false; + disabled = false; + FixedExposure = false; + namerawimage = "/sdcard/img_tmp/raw.jpg"; +} + + +ClassFlowTakeImage::ClassFlowTakeImage(std::vector* lfc) : ClassFlowImage(lfc, TAG) +{ + imagesLocation = "/log/source"; + imagesRetention = 5; + SetInitialParameter(); +} + + +bool ClassFlowTakeImage::ReadParameter(FILE* pfile, string& aktparamgraph) +{ + std::vector splitted; + + aktparamgraph = trim(aktparamgraph); + int _brightness = -100; + int _contrast = -100; + int _saturation = -100; + + if (aktparamgraph.size() == 0) + if (!this->GetNextParagraph(pfile, aktparamgraph)) + return false; + + if (aktparamgraph.compare("[TakeImage]") != 0) // Paragraph does not fit TakeImage + return false; + + while (this->getNextLine(pfile, &aktparamgraph) && !this->isNewParagraph(aktparamgraph)) + { + splitted = ZerlegeZeile(aktparamgraph); + if ((toUpper(splitted[0]) == "RAWIMAGESLOCATION") && (splitted.size() > 1)) + { + imagesLocation = "/sdcard" + splitted[1]; + isLogImage = true; + } + if ((toUpper(splitted[0]) == "IMAGEQUALITY") && (splitted.size() > 1)) + ImageQuality = std::stod(splitted[1]); + + if ((toUpper(splitted[0]) == "IMAGESIZE") && (splitted.size() > 1)) + { + ImageSize = Camera.TextToFramesize(splitted[1].c_str()); + isImageSize = true; + } + + if ((toUpper(splitted[0]) == "SAVEALLFILES") && (splitted.size() > 1)) + { + if (toUpper(splitted[1]) == "TRUE") + SaveAllFiles = true; + } + + if ((toUpper(splitted[0]) == "WAITBEFORETAKINGPICTURE") && (splitted.size() > 1)) + { + waitbeforepicture = stoi(splitted[1]); + } + + if ((toUpper(splitted[0]) == "RAWIMAGESRETENTION") && (splitted.size() > 1)) + { + this->imagesRetention = std::stoi(splitted[1]); + } + + if ((toUpper(splitted[0]) == "BRIGHTNESS") && (splitted.size() > 1)) + { + _brightness = stoi(splitted[1]); + } + + if ((toUpper(splitted[0]) == "CONTRAST") && (splitted.size() > 1)) + { + _contrast = stoi(splitted[1]); + } + + if ((toUpper(splitted[0]) == "SATURATION") && (splitted.size() > 1)) + { + _saturation = stoi(splitted[1]); + } + + if ((toUpper(splitted[0]) == "FIXEDEXPOSURE") && (splitted.size() > 1)) + { + if (toUpper(splitted[1]) == "TRUE") + FixedExposure = true; + } + + if ((toUpper(splitted[0]) == "LEDINTENSITY") && (splitted.size() > 1)) + { + float ledintensity = stof(splitted[1]); + ledintensity = min((float) 100, ledintensity); + ledintensity = max((float) 0, ledintensity); + Camera.SetLEDIntensity(ledintensity); + } + + if ((toUpper(splitted[0]) == "DEMO") && (splitted.size() > 1)) + { + if (toUpper(splitted[1]) == "TRUE") + Camera.useDemoMode(); + } + } + + Camera.SetBrightnessContrastSaturation(_brightness, _contrast, _saturation); + Camera.SetQualitySize(ImageQuality, ImageSize); + + image_width = Camera.image_width; + image_height = Camera.image_height; + rawImage = new CImageBasis(); + rawImage->CreateEmptyImage(image_width, image_height, 3); + + waitbeforepicture_store = waitbeforepicture; + if (FixedExposure && (waitbeforepicture > 0)) + { +// ESP_LOGD(TAG, "Fixed Exposure enabled!"); + int flash_duration = (int) (waitbeforepicture * 1000); + Camera.EnableAutoExposure(flash_duration); + waitbeforepicture = 0.2; +// flash_duration = (int) (waitbeforepicture * 1000); +// takePictureWithFlash(flash_duration); +// rawImage->SaveToFile("/sdcard/init2.jpg"); + } + + return true; +} + + +string ClassFlowTakeImage::getHTMLSingleStep(string host) +{ + string result; + result = "Raw Image:
\n\n"; + return result; +} + + +bool ClassFlowTakeImage::doFlow(string zwtime) +{ + string logPath = CreateLogFolder(zwtime); + + int flash_duration = (int) (waitbeforepicture * 1000); + + #ifdef DEBUG_DETAIL_ON + LogFile.WriteHeapInfo("ClassFlowTakeImage::doFlow - Before takePictureWithFlash"); + #endif + + + #ifdef WIFITURNOFF + esp_wifi_stop(); // to save power usage and + #endif + + takePictureWithFlash(flash_duration); + + #ifdef WIFITURNOFF + esp_wifi_start(); + #endif + + + #ifdef DEBUG_DETAIL_ON + LogFile.WriteHeapInfo("ClassFlowTakeImage::doFlow - After takePictureWithFlash"); + #endif + + LogImage(logPath, "raw", NULL, NULL, zwtime, rawImage); + + RemoveOldLogs(); + + #ifdef DEBUG_DETAIL_ON + LogFile.WriteHeapInfo("ClassFlowTakeImage::doFlow - After RemoveOldLogs"); + #endif + + return true; +} + + +esp_err_t ClassFlowTakeImage::SendRawJPG(httpd_req_t *req) +{ + int flash_duration = (int) (waitbeforepicture * 1000); + time(&TimeImageTaken); + localtime(&TimeImageTaken); + + return Camera.CaptureToHTTP(req, flash_duration); +} + + +ImageData* ClassFlowTakeImage::SendRawImage() +{ + CImageBasis *zw = new CImageBasis(rawImage); + ImageData *id; + int flash_duration = (int) (waitbeforepicture * 1000); + Camera.CaptureToBasisImage(zw, flash_duration); + time(&TimeImageTaken); + localtime(&TimeImageTaken); + + id = zw->writeToMemoryAsJPG(); + delete zw; + return id; +} + +time_t ClassFlowTakeImage::getTimeImageTaken() +{ + return TimeImageTaken; +} + +ClassFlowTakeImage::~ClassFlowTakeImage(void) +{ + delete rawImage; +} + diff --git a/code/components/jomjol_flowcontroll/ClassFlowTakeImage.h b/code/components/jomjol_flowcontroll/ClassFlowTakeImage.h new file mode 100644 index 000000000..2b62e6296 --- /dev/null +++ b/code/components/jomjol_flowcontroll/ClassFlowTakeImage.h @@ -0,0 +1,55 @@ +#pragma once + +#ifndef CLASSFFLOWTAKEIMAGE_H +#define CLASSFFLOWTAKEIMAGE_H + +#include "ClassFlowImage.h" +#include "ClassControllCamera.h" +#include "../../include/defines.h" + +#include + +class ClassFlowTakeImage : + public ClassFlowImage +{ +protected: + float waitbeforepicture; + float waitbeforepicture_store; + framesize_t ImageSize; + bool isImageSize; + int ImageQuality; + time_t TimeImageTaken; + string namerawimage; + int image_height, image_width; + bool SaveAllFiles; + bool FixedExposure; + + + + void CopyFile(string input, string output); + + esp_err_t camera_capture(); + void takePictureWithFlash(int flash_duration); + + + void SetInitialParameter(void); + +public: + CImageBasis *rawImage; + + ClassFlowTakeImage(std::vector* lfc); + + bool ReadParameter(FILE* pfile, string& aktparamgraph); + bool doFlow(string time); + string getHTMLSingleStep(string host); + time_t getTimeImageTaken(); + string name(){return "ClassFlowTakeImage";}; + + ImageData* SendRawImage(); + esp_err_t SendRawJPG(httpd_req_t *req); + + ~ClassFlowTakeImage(void); +}; + + +#endif //CLASSFFLOWTAKEIMAGE_H \ No newline at end of file diff --git a/code/components/jomjol_mqtt/interface_mqtt.cpp b/code/components/jomjol_mqtt/interface_mqtt.cpp index 4c381843f..0118b8735 100644 --- a/code/components/jomjol_mqtt/interface_mqtt.cpp +++ b/code/components/jomjol_mqtt/interface_mqtt.cpp @@ -25,11 +25,12 @@ bool mqtt_connected = false; esp_mqtt_client_handle_t client = NULL; std::string uri, client_id, lwt_topic, lwt_connected, lwt_disconnected, user, password, maintopic; -int keepalive, SetRetainFlag; -void (*callbackOnConnected)(std::string, int) = NULL; +int keepalive; +bool SetRetainFlag; +void (*callbackOnConnected)(std::string, bool) = NULL; -bool MQTTPublish(std::string _key, std::string _content, int retained_flag) +bool MQTTPublish(std::string _key, std::string _content, bool retained_flag) { if (!mqtt_enabled) { // MQTT sevice not started / configured (MQTT_Init not called before) return false; @@ -153,7 +154,7 @@ static void mqtt_event_handler(void *handler_args, esp_event_base_t base, int32_ bool MQTT_Configure(std::string _mqttURI, std::string _clientid, std::string _user, std::string _password, std::string _maintopic, std::string _lwt, std::string _lwt_connected, std::string _lwt_disconnected, - int _keepalive, int _SetRetainFlag, void *_callbackOnConnected) { + int _keepalive, bool _SetRetainFlag, void *_callbackOnConnected) { if ((_mqttURI.length() == 0) || (_maintopic.length() == 0) || (_clientid.length() == 0)) { LogFile.WriteToFile(ESP_LOG_ERROR, TAG, "Init aborted! Config error (URI, MainTopic or ClientID missing)"); @@ -168,7 +169,7 @@ bool MQTT_Configure(std::string _mqttURI, std::string _clientid, std::string _us keepalive = _keepalive; SetRetainFlag = _SetRetainFlag; maintopic = _maintopic; - callbackOnConnected = ( void (*)(std::string, int) )(_callbackOnConnected); + callbackOnConnected = ( void (*)(std::string, bool) )(_callbackOnConnected); if (_user.length() && _password.length()){ user = _user; diff --git a/code/components/jomjol_mqtt/interface_mqtt.h b/code/components/jomjol_mqtt/interface_mqtt.h index 25dfc46cb..7d3a56834 100644 --- a/code/components/jomjol_mqtt/interface_mqtt.h +++ b/code/components/jomjol_mqtt/interface_mqtt.h @@ -11,11 +11,11 @@ bool MQTT_Configure(std::string _mqttURI, std::string _clientid, std::string _user, std::string _password, std::string _maintopic, std::string _lwt, std::string _lwt_connected, std::string _lwt_disconnected, - int _keepalive, int SetRetainFlag, void *callbackOnConnected); + int _keepalive, bool SetRetainFlag, void *callbackOnConnected); int MQTT_Init(); void MQTTdestroy_client(bool _disable); -bool MQTTPublish(std::string _key, std::string _content, int retained_flag = 1); // retained Flag as Standart +bool MQTTPublish(std::string _key, std::string _content, bool retained_flag = 1); // retained Flag as Standart bool getMQTTisEnabled(); bool getMQTTisConnected(); diff --git a/code/components/jomjol_mqtt/server_mqtt.cpp b/code/components/jomjol_mqtt/server_mqtt.cpp index bef046530..a10ebce6f 100644 --- a/code/components/jomjol_mqtt/server_mqtt.cpp +++ b/code/components/jomjol_mqtt/server_mqtt.cpp @@ -29,7 +29,7 @@ std::string timeUnit = ""; std::string rateUnit = "Unit/Minute"; float roundInterval; // Minutes int keepAlive = 0; // Seconds -int retainFlag; +bool retainFlag; static std::string maintopic; @@ -221,7 +221,7 @@ esp_err_t sendDiscovery_and_static_Topics(httpd_req_t *req) { return ESP_OK; } -void GotConnected(std::string maintopic, int retainFlag) { +void GotConnected(std::string maintopic, bool retainFlag) { if (HomeassistantDiscovery) { MQTThomeassistantDiscovery(); } @@ -251,7 +251,7 @@ void SetHomeassistantDiscoveryEnabled(bool enabled) { } -void setMqtt_Server_Retain(int _retainFlag) { +void setMqtt_Server_Retain(bool _retainFlag) { retainFlag = _retainFlag; } diff --git a/code/components/jomjol_mqtt/server_mqtt.h b/code/components/jomjol_mqtt/server_mqtt.h index 72e722be0..3cd266c37 100644 --- a/code/components/jomjol_mqtt/server_mqtt.h +++ b/code/components/jomjol_mqtt/server_mqtt.h @@ -10,7 +10,7 @@ void SetHomeassistantDiscoveryEnabled(bool enabled); void mqttServer_setParameter(std::vector* _NUMBERS, int interval, float roundInterval); void mqttServer_setMeterType(std::string meterType, std::string valueUnit, std::string timeUnit,std::string rateUnit); -void setMqtt_Server_Retain(int SetRetainFlag); +void setMqtt_Server_Retain(bool SetRetainFlag); void mqttServer_setMainTopic( std::string maintopic); std::string mqttServer_getMainTopic(); @@ -19,7 +19,7 @@ void register_server_mqtt_uri(httpd_handle_t server); void publishSystemData(); std::string getTimeUnit(void); -void GotConnected(std::string maintopic, int SetRetainFlag); +void GotConnected(std::string maintopic, bool SetRetainFlag); #endif //SERVERMQTT_H diff --git a/code/components/jomjol_tfliteclass/server_tflite.cpp b/code/components/jomjol_tfliteclass/server_tflite.cpp index 5d4cc0396..e8e8a3bad 100644 --- a/code/components/jomjol_tfliteclass/server_tflite.cpp +++ b/code/components/jomjol_tfliteclass/server_tflite.cpp @@ -30,7 +30,7 @@ TaskHandle_t xHandletask_autodoFlow = NULL; bool bTaskAutoFlowCreated = false; bool flowisrunning = false; -long auto_intervall = 0; +long auto_interval = 0; bool auto_isrunning = false; int countRounds = 0; @@ -620,8 +620,8 @@ esp_err_t handler_editflow(httpd_req_t *req) // string zwzw = "Do " + _task + " start\n"; ESP_LOGD(TAG, zwzw.c_str()); Camera.SetBrightnessContrastSaturation(bri, con, sat); Camera.SetLEDIntensity(intens); - ESP_LOGD(TAG, "test_take - vor MakeImage"); - std::string zw = tfliteflow.doSingleStep("[MakeImage]", _host); + ESP_LOGD(TAG, "test_take - vor TakeImage"); + std::string zw = tfliteflow.doSingleStep("[TakeImage]", _host); httpd_resp_set_hdr(req, "Access-Control-Allow-Origin", "*"); httpd_resp_send(req, zw.c_str(), zw.length()); } @@ -825,13 +825,13 @@ void task_autodoFlow(void *pvParameter) ESP_LOGD(TAG, "task_autodoFlow: start"); doInit(); - auto_isrunning = tfliteflow.isAutoStart(auto_intervall); + auto_isrunning = tfliteflow.isAutoStart(auto_interval); if (isSetupModusActive()) { auto_isrunning = false; std::string zw_time = getCurrentTimeString(LOGFILE_TIME_FORMAT); - tfliteflow.doFlowMakeImageOnly(zw_time); + tfliteflow.doFlowTakeImageOnly(zw_time); } while (auto_isrunning) @@ -873,9 +873,9 @@ void task_autodoFlow(void *pvParameter) " completed (" + std::to_string(getUpTime() - roundStartTime) + " seconds)"); fr_delta_ms = (esp_timer_get_time() - fr_start) / 1000; - if (auto_intervall > fr_delta_ms) + if (auto_interval > fr_delta_ms) { - const TickType_t xDelay = (auto_intervall - fr_delta_ms) / portTICK_PERIOD_MS; + const TickType_t xDelay = (auto_interval - fr_delta_ms) / portTICK_PERIOD_MS; ESP_LOGD(TAG, "Autoflow: sleep for: %ldms", (long) xDelay); vTaskDelay( xDelay ); } diff --git a/code/components/jomjol_wlan/connect_wlan.cpp b/code/components/jomjol_wlan/connect_wlan.cpp index 59c429760..3288b916a 100644 --- a/code/components/jomjol_wlan/connect_wlan.cpp +++ b/code/components/jomjol_wlan/connect_wlan.cpp @@ -63,7 +63,7 @@ std::string hostname = ""; std::string std_hostname = "watermeter"; std::string ipadress = ""; std::string ssid = ""; -int RSSIThreashold; +int RSSIThreshold; ///////////////////////////////// ///////////////////////////////// @@ -403,9 +403,9 @@ void strinttoip4(const char *ip, int &a, int &b, int &c, int &d) { } -void wifi_init_sta(const char *_ssid, const char *_password, const char *_hostname, const char *_ipadr, const char *_gw, const char *_netmask, const char *_dns, int _rssithreashold) +void wifi_init_sta(const char *_ssid, const char *_password, const char *_hostname, const char *_ipadr, const char *_gw, const char *_netmask, const char *_dns, int _rssithreshold) { - RSSI_Threshold = _rssithreashold; + RSSI_Threshold = _rssithreshold; s_wifi_event_group = xEventGroupCreate(); ESP_ERROR_CHECK(esp_netif_init()); diff --git a/code/components/jomjol_wlan/connect_wlan.h b/code/components/jomjol_wlan/connect_wlan.h index 044e39fd6..b0c8bc387 100644 --- a/code/components/jomjol_wlan/connect_wlan.h +++ b/code/components/jomjol_wlan/connect_wlan.h @@ -5,7 +5,7 @@ #include -void wifi_init_sta(const char *_ssid, const char *_password, const char *_hostname, const char *_ipadr, const char *_gw, const char *_netmask, const char *_dns, int _rssithreashold); +void wifi_init_sta(const char *_ssid, const char *_password, const char *_hostname, const char *_ipadr, const char *_gw, const char *_netmask, const char *_dns, int _rssithreshold); void wifi_init_sta(const char *_ssid, const char *_password, const char *_hostname); void wifi_init_sta(const char *_ssid, const char *_password); @@ -17,6 +17,6 @@ void WIFIDestroy(); extern std::string hostname; extern std::string std_hostname; -extern int RSSIThreashold; +extern int RSSIThreshold; #endif //CONNECT_WLAN_H \ No newline at end of file diff --git a/code/components/jomjol_wlan/read_wlanini.cpp b/code/components/jomjol_wlan/read_wlanini.cpp index 70f54c976..0cb21adfa 100644 --- a/code/components/jomjol_wlan/read_wlanini.cpp +++ b/code/components/jomjol_wlan/read_wlanini.cpp @@ -41,7 +41,7 @@ std::vector ZerlegeZeileWLAN(std::string input, std::string _delimiter = -bool LoadWlanFromFile(std::string fn, char *&_ssid, char *&_password, char *&_hostname, char *&_ipadr, char *&_gw, char *&_netmask, char *&_dns, int &_rssithreashold) +bool LoadWlanFromFile(std::string fn, char *&_ssid, char *&_password, char *&_hostname, char *&_ipadr, char *&_gw, char *&_netmask, char *&_dns, int &_rssithreshold) { std::string ssid = ""; std::string passphrase = ""; @@ -91,7 +91,7 @@ bool LoadWlanFromFile(std::string fn, char *&_ssid, char *&_password, char *&_ho } } - if ((splitted.size() > 1) && (toUpper(splitted[0]) == "RSSITHREASHOLD")){ + if ((splitted.size() > 1) && (toUpper(splitted[0]) == "RSSITHRESHOLD")){ string _s = trim(splitted[1]); if ((_s[0] == '"') && (_s[_s.length()-1] == '"')){ _s = _s.substr(1, ssid.length()-2); @@ -194,8 +194,8 @@ bool LoadWlanFromFile(std::string fn, char *&_ssid, char *&_password, char *&_ho else _dns = NULL; - _rssithreashold = rssithreshold; - RSSIThreashold = rssithreshold; + _rssithreshold = rssithreshold; + RSSIThreshold = rssithreshold; return true; } @@ -274,9 +274,9 @@ bool ChangeHostName(std::string fn, std::string _newhostname) } -bool ChangeRSSIThreashold(std::string fn, int _newrssithreashold) +bool ChangeRSSIThreshold(std::string fn, int _newrssithreshold) { - if (RSSIThreashold == _newrssithreashold) + if (RSSIThreshold == _newrssithreshold) return false; string line = ""; @@ -305,8 +305,8 @@ bool ChangeRSSIThreashold(std::string fn, int _newrssithreashold) splitted = ZerlegeZeileWLAN(line, "="); splitted[0] = trim(splitted[0], " "); - if ((splitted.size() > 1) && (toUpper(splitted[0]) == "RSSITHREASHOLD")){ - line = "RSSIThreashold = " + to_string(_newrssithreashold) + "\n"; + if ((splitted.size() > 1) && (toUpper(splitted[0]) == "RSSITHRESHOLD")){ + line = "RSSIThreshold = " + to_string(_newrssithreshold) + "\n"; found = true; } @@ -324,7 +324,7 @@ bool ChangeRSSIThreashold(std::string fn, int _newrssithreashold) if (!found) { - line = "RSSIThreashold = " + to_string(_newrssithreashold) + "\n"; + line = "RSSIThreshold = " + to_string(_newrssithreshold) + "\n"; neuesfile.push_back(line); } @@ -340,7 +340,7 @@ bool ChangeRSSIThreashold(std::string fn, int _newrssithreashold) fclose(pFile); - ESP_LOGD(TAG, "*** RSSIThreashold update done ***"); + ESP_LOGD(TAG, "*** RSSIThreshold update done ***"); return true; } diff --git a/code/components/jomjol_wlan/read_wlanini.h b/code/components/jomjol_wlan/read_wlanini.h index 3a1182a82..8f2121ede 100644 --- a/code/components/jomjol_wlan/read_wlanini.h +++ b/code/components/jomjol_wlan/read_wlanini.h @@ -5,10 +5,10 @@ #include -bool LoadWlanFromFile(std::string fn, char *&_ssid, char *&_password, char *&_hostname, char *&_ipadr, char *&_gw, char *&_netmask, char *&_dns, int &_rssithreashold); +bool LoadWlanFromFile(std::string fn, char *&_ssid, char *&_password, char *&_hostname, char *&_ipadr, char *&_gw, char *&_netmask, char *&_dns, int &_rssithreshold); bool ChangeHostName(std::string fn, std::string _newhostname); -bool ChangeRSSIThreashold(std::string fn, int _newrssithreashold); +bool ChangeRSSIThreshold(std::string fn, int _newrssithreshold); #endif //READ_WLANINI_H \ No newline at end of file diff --git a/code/include/defines.h b/code/include/defines.h index c5a13d1d7..8b44f249e 100644 --- a/code/include/defines.h +++ b/code/include/defines.h @@ -56,7 +56,7 @@ //#define CONFIG_IDF_TARGET_ARCH_XTENSA //not needed with platformio/espressif32 @ 5.2.0 - //ClassControllCamera + ClassFlowMakeImage + connect_wlan + main + //ClassControllCamera + ClassFlowTakeImage + connect_wlan + main #define FLASH_GPIO GPIO_NUM_4 #define BLINK_GPIO GPIO_NUM_33 @@ -69,12 +69,13 @@ //server_GPIO #define __LEDGLOBAL - //ClassControllCamera + ClassFlowMakeImage + //ClassControllCamera + ClassFlowTakeImage #define CAMERA_MODEL_AI_THINKER #define BOARD_ESP32CAM_AITHINKER //server_GPIO + server_file + SoftAP #define CONFIG_FILE "/sdcard/config/config.ini" + #define CONFIG_FILE_BACKUP "/sdcard/config/config.bak" //ClassFlowControll + Main + SoftAP #define WLAN_CONFIG_FILE "/sdcard/wlan.ini" diff --git a/code/main/main.cpp b/code/main/main.cpp index 5d945be07..e5e5f5cce 100644 --- a/code/main/main.cpp +++ b/code/main/main.cpp @@ -1,4 +1,8 @@ -//#include +#include +#include +#include +#include + //#include "freertos/FreeRTOS.h" //#include "freertos/task.h" //#include "freertos/event_groups.h" @@ -29,6 +33,7 @@ #include "server_file.h" #include "server_ota.h" #include "time_sntp.h" +#include "configFile.h" //#include "ClassControllCamera.h" #include "server_main.h" #include "server_camera.h" @@ -78,6 +83,14 @@ extern std::string getFwVersion(void); extern std::string getHTMLversion(void); extern std::string getHTMLcommit(void); + +std::vector splitString(const std::string& str); +bool replace(std::string& s, std::string const& toReplace, std::string const& replaceWith); +bool replace(std::string& s, std::string const& toReplace, std::string const& replaceWith, bool logIt); +//bool replace_all(std::string& s, std::string const& toReplace, std::string const& replaceWith); +bool isInString(std::string& s, std::string const& toFind); +void migrateConfiguration(void); + static const char *TAG = "MAIN"; bool Init_NVS_SDCard() @@ -198,6 +211,8 @@ extern "C" void app_main(void) return; // No way to continue without SD-Card! } + migrateConfiguration(); + setupTime(); string versionFormated = getFwVersion() + ", Date/Time: " + std::string(BUILD_TIME) + \ @@ -242,10 +257,10 @@ extern "C" void app_main(void) ESP_ERROR_CHECK( heap_trace_start(HEAP_TRACE_LEAKS) ); #endif - char *ssid = NULL, *passwd = NULL, *hostname = NULL, *ip = NULL, *gateway = NULL, *netmask = NULL, *dns = NULL; int rssithreashold = 0; - LoadWlanFromFile(WLAN_CONFIG_FILE, ssid, passwd, hostname, ip, gateway, netmask, dns, rssithreashold); + char *ssid = NULL, *passwd = NULL, *hostname = NULL, *ip = NULL, *gateway = NULL, *netmask = NULL, *dns = NULL; int rssithreshold = 0; + LoadWlanFromFile(WLAN_CONFIG_FILE, ssid, passwd, hostname, ip, gateway, netmask, dns, rssithreshold); - LogFile.WriteToFile(ESP_LOG_INFO, TAG, "WLAN-Settings - RSSI-Threashold: " + to_string(rssithreashold)); + LogFile.WriteToFile(ESP_LOG_INFO, TAG, "WLAN-Settings - RSSI-Threshold: " + to_string(rssithreshold)); if (ssid != NULL && passwd != NULL) #ifdef __HIDE_PASSWORD @@ -268,7 +283,7 @@ extern "C" void app_main(void) ESP_LOGD(TAG, "DNS IP: %s", dns); - wifi_init_sta(ssid, passwd, hostname, ip, gateway, netmask, dns, rssithreashold); + wifi_init_sta(ssid, passwd, hostname, ip, gateway, netmask, dns, rssithreshold); xDelay = 2000 / portTICK_PERIOD_MS; @@ -398,3 +413,243 @@ extern "C" void app_main(void) } } + +void migrateConfiguration(void) { + bool migrated = false; + + if (!FileExists(CONFIG_FILE)) { + LogFile.WriteToFile(ESP_LOG_ERROR, TAG, "Config file seems to be missing!"); + return; + } + + std::string section = ""; + std::ifstream ifs(CONFIG_FILE); + std::string content((std::istreambuf_iterator(ifs)), (std::istreambuf_iterator())); + + /* Split config file it array of lines */ + std::vector configLines = splitString(content); + + /* Process each line */ + for (int i = 0; i < configLines.size(); i++) { + //ESP_LOGI(TAG, "Line %d: %s", i, configLines[i].c_str()); + + if (configLines[i].find("[") != std::string::npos) { // Start of new section + section = configLines[i]; + replace(section, ";", "", false); // Remove possible semicolon (just for the string comparison) + //ESP_LOGI(TAG, "New section: %s", section.c_str()); + } + + /* Migrate parameters as needed + * For the boolean parameters, we make them enabled all the time now: + * 1. If they where disabled, set them to their default value + * 2. Enable them + * Notes: + * The migration has some simplifications: + * - Case Sensitiveness must be like in the initial config.ini + * - No Whitespace after a semicollon + * - Only one whitespace before/after the equal sign + */ + if (section == "[MakeImage]") { + migrated = migrated | replace(configLines[i], "[MakeImage]", "[TakeImage]"); // Rename the section itself + } + + if (section == "[MakeImage]" || section == "[TakeImage]") { + migrated = migrated | replace(configLines[i], "LogImageLocation", "RawImagesLocation"); + migrated = migrated | replace(configLines[i], "LogfileRetentionInDays", "RawImagesRetention"); + + migrated = migrated | replace(configLines[i], ";Demo = true", ";Demo = false"); // Set it to its default value + migrated = migrated | replace(configLines[i], ";Demo", "Demo"); // Enable it + + migrated = migrated | replace(configLines[i], ";FixedExposure = true", ";FixedExposure = false"); // Set it to its default value + migrated = migrated | replace(configLines[i], ";FixedExposure", "FixedExposure"); // Enable it + } + + if (section == "[Alignment]") { + migrated = migrated | replace(configLines[i], ";InitialMirror = true", ";InitialMirror = false"); // Set it to its default value + migrated = migrated | replace(configLines[i], ";InitialMirror", "InitialMirror"); // Enable it + + migrated = migrated | replace(configLines[i], ";FlipImageSize = true", ";FlipImageSize = false"); // Set it to its default value + migrated = migrated | replace(configLines[i], ";FlipImageSize", "FlipImageSize"); // Enable it + } + + if (section == "[Digits]") { + migrated = migrated | replace(configLines[i], "LogImageLocation", "ROIImagesLocation"); + migrated = migrated | replace(configLines[i], "LogfileRetentionInDays", "ROIImagesRetention"); + } + + if (section == "[Analog]") { + migrated = migrated | replace(configLines[i], "LogImageLocation", "ROIImagesLocation"); + migrated = migrated | replace(configLines[i], "LogfileRetentionInDays", "ROIImagesRetention"); + migrated = migrated | replace(configLines[i], "ExtendedResolution", ";UNUSED_PARAMETER"); // This parameter is no longer used + } + + if (section == "[PostProcessing]") { + migrated = migrated | replace(configLines[i], ";PreValueUse = true", ";PreValueUse = false"); // Set it to its default value + migrated = migrated | replace(configLines[i], ";PreValueUse", "PreValueUse"); // Enable it + + /* AllowNegativeRates has a as prefix! */ + if (isInString(configLines[i], "AllowNegativeRates") && isInString(configLines[i], ";")) { // It is the parameter "AllowNegativeRates" and it is commented out + migrated = migrated | replace(configLines[i], "true", "false"); // Set it to its default value + migrated = migrated | replace(configLines[i], ";", ""); // Enable it + } + + /* IgnoreLeadingNaN has a as prefix! */ + if (isInString(configLines[i], "IgnoreLeadingNaN") && isInString(configLines[i], ";")) { // It is the parameter "IgnoreLeadingNaN" and it is commented out + migrated = migrated | replace(configLines[i], "true", "false"); // Set it to its default value + migrated = migrated | replace(configLines[i], ";", ""); // Enable it + } + + /* ExtendedResolution has a as prefix! */ + if (isInString(configLines[i], "ExtendedResolution") && isInString(configLines[i], ";")) { // It is the parameter "ExtendedResolution" and it is commented out + migrated = migrated | replace(configLines[i], "true", "false"); // Set it to its default value + migrated = migrated | replace(configLines[i], ";", ""); // Enable it + } + + migrated = migrated | replace(configLines[i], ";ErrorMessage = true", ";ErrorMessage = false"); // Set it to its default value + migrated = migrated | replace(configLines[i], ";ErrorMessage", "ErrorMessage"); // Enable it + + migrated = migrated | replace(configLines[i], ";CheckDigitIncreaseConsistency = true", ";CheckDigitIncreaseConsistency = false"); // Set it to its default value + migrated = migrated | replace(configLines[i], ";CheckDigitIncreaseConsistency", "CheckDigitIncreaseConsistency"); // Enable it + } + + if (section == "[MQTT]") { + migrated = migrated | replace(configLines[i], "SetRetainFlag", "RetainMessages"); // First rename it, enable it with its default value + migrated = migrated | replace(configLines[i], ";RetainMessages = true", ";RetainMessages = false"); // Set it to its default value + migrated = migrated | replace(configLines[i], ";RetainMessages", "RetainMessages"); // Enable it + + migrated = migrated | replace(configLines[i], ";HomeassistantDiscovery = true", ";HomeassistantDiscovery = false"); // Set it to its default value + migrated = migrated | replace(configLines[i], ";HomeassistantDiscovery", "HomeassistantDiscovery"); // Enable it + + if (configLines[i].rfind("Topic", 0) != std::string::npos) // only if string starts with "Topic" (Was the naming in very old version) + { + migrated = migrated | replace(configLines[i], "Topic", "MainTopic"); + } + } + + if (section == "[InfluxDB]") { + + } + + if (section == "[GPIO]") { + + } + + if (section == "[DataLogging]") { + migrated = migrated | replace(configLines[i], "DataLogRetentionInDays", "DataFilesRetention"); + /* DataLogActive is true by default! */ + migrated = migrated | replace(configLines[i], ";DataLogActive = true", ";DataLogActive = true"); // Set it to its default value + migrated = migrated | replace(configLines[i], ";DataLogActive", "DataLogActive"); // Enable it + } + + if (section == "[AutoTimer]") { + migrated = migrated | replace(configLines[i], "Intervall", "Interval"); + migrated = migrated | replace(configLines[i], ";AutoStart = true", ";AutoStart = false"); // Set it to its default value + migrated = migrated | replace(configLines[i], ";AutoStart", "AutoStart"); // Enable it + + } + + if (section == "[Debug]") { + migrated = migrated | replace(configLines[i], "Logfile ", "LogLevel "); // Whitespace needed so it does not match `LogfileRetentionInDays` + /* LogLevel (resp. LogFile) was originally a boolean, but we switched it to an int + * For both cases (true/false), we set it to level 2 (WARNING) */ + migrated = migrated | replace(configLines[i], "LogLevel = true", "LogLevel = 2"); + migrated = migrated | replace(configLines[i], "LogLevel = false", "LogLevel = 2"); + migrated = migrated | replace(configLines[i], "LogfileRetentionInDays", "LogfilesRetention"); + } + + if (section == "[System]") { + migrated = migrated | replace(configLines[i], "RSSIThreashold", "RSSIThreshold"); + migrated = migrated | replace(configLines[i], "AutoAdjustSummertime", ";UNUSED_PARAMETER"); // This parameter is no longer used + + migrated = migrated | replace(configLines[i], ";SetupMode = true", ";SetupMode = false"); // Set it to its default value + migrated = migrated | replace(configLines[i], ";SetupMode", "SetupMode"); // Enable it + } + } + + if (migrated) { // At least one replacement happened + if (! RenameFile(CONFIG_FILE, CONFIG_FILE_BACKUP)) { + LogFile.WriteToFile(ESP_LOG_ERROR, TAG, "Failed to create backup of Config file!"); + return; + } + + FILE* pfile = fopen(CONFIG_FILE, "w"); + for (int i = 0; i < configLines.size(); i++) { + fwrite(configLines[i].c_str() , configLines[i].length(), 1, pfile); + fwrite("\n" , 1, 1, pfile); + } + fclose(pfile); + LogFile.WriteToFile(ESP_LOG_INFO, TAG, "Config file migrated. Saved backup to " + string(CONFIG_FILE_BACKUP)); + } +} + + +std::vector splitString(const std::string& str) { + std::vector tokens; + + std::stringstream ss(str); + std::string token; + + while (std::getline(ss, token, '\n')) { + tokens.push_back(token); + } + + return tokens; +} + + +/*bool replace_all(std::string& s, std::string const& toReplace, std::string const& replaceWith) { + std::string buf; + std::size_t pos = 0; + std::size_t prevPos; + bool found = false; + + // Reserves rough estimate of final size of string. + buf.reserve(s.size()); + + while (true) { + prevPos = pos; + pos = s.find(toReplace, pos); + if (pos == std::string::npos) { + break; + } + found = true; + buf.append(s, prevPos, pos - prevPos); + buf += replaceWith; + pos += toReplace.size(); + } + + buf.append(s, prevPos, s.size() - prevPos); + s.swap(buf); + + return found; +}*/ + + +bool replace(std::string& s, std::string const& toReplace, std::string const& replaceWith) { + return replace(s, toReplace, replaceWith, true); +} + +bool replace(std::string& s, std::string const& toReplace, std::string const& replaceWith, bool logIt) { + std::size_t pos = s.find(toReplace); + + if (pos == std::string::npos) { // Not found + return false; + } + + std::string old = s; + s.replace(pos, toReplace.length(), replaceWith); + if (logIt) { + LogFile.WriteToFile(ESP_LOG_ERROR, TAG, "Migrated Configfile line '" + old + "' to '" + s + "'"); + } + return true; +} + + +bool isInString(std::string& s, std::string const& toFind) { + std::size_t pos = s.find(toFind); + + if (pos == std::string::npos) { // Not found + return false; + } + return true; +} diff --git a/code/main/softAP.cpp b/code/main/softAP.cpp index 517ec1b8a..b05911eca 100644 --- a/code/main/softAP.cpp +++ b/code/main/softAP.cpp @@ -140,14 +140,14 @@ void SendHTTPResponse(httpd_req_t *req) // message += "gatewayLeave emtpy if set by router"; // message += "netmaskLeave emtpy if set by router"; // message += "DNSLeave emtpy if set by router"; -// message += "RSSI ThreasholdWLAN Mesh Parameter: Threashold for RSSI value to check for start switching access point in a mesh system.Possible values: -100 to 0, 0 = disabled - Value will be transfered to wlan.ini at next startup)"; +// message += "RSSI ThresholdWLAN Mesh Parameter: Threshold for RSSI value to check for start switching access point in a mesh system.Possible values: -100 to 0, 0 = disabled - Value will be transfered to wlan.ini at next startup)"; // httpd_resp_send_chunk(req, message.c_str(), strlen(message.c_str())); message = ""; message += ""; httpd_resp_send_chunk(req, message.c_str(), strlen(message.c_str())); return; @@ -311,7 +311,7 @@ esp_err_t config_ini_handler(httpd_req_t *req) fputs(dns.c_str(), configfilehandle); if (rssi.length()) - rssi = "RSSIThreashold = \"" + rssi + "\"\n"; + rssi = "RSSIThreshold = \"" + rssi + "\"\n"; else rssi = ";rssi = \"\"\n"; fputs(rssi.c_str(), configfilehandle); diff --git a/code/test/components/jomjol-flowcontroll/test_flow_postrocess_helper.cpp b/code/test/components/jomjol-flowcontroll/test_flow_postrocess_helper.cpp index ba8c2d945..b8ebd4c29 100644 --- a/code/test/components/jomjol-flowcontroll/test_flow_postrocess_helper.cpp +++ b/code/test/components/jomjol-flowcontroll/test_flow_postrocess_helper.cpp @@ -9,11 +9,11 @@ UnderTestPost* setUpClassFlowPostprocessing(t_CNNType digType, t_CNNType anaType ClassFlowCNNGeneral* _analog; ClassFlowCNNGeneral* _digit; std::vector FlowControll; - ClassFlowMakeImage* flowmakeimage; + ClassFlowTakeImage* flowtakeimage; // wird im doFlow verwendet - flowmakeimage = new ClassFlowMakeImage(&FlowControll); - FlowControll.push_back(flowmakeimage); + flowtakeimage = new ClassFlowTakeImage(&FlowControll); + FlowControll.push_back(flowtakeimage); // Die Modeltypen werden gesetzt, da keine Modelle verwendet werden. _analog = new ClassFlowCNNGeneral(nullptr, anaType); diff --git a/code/test/components/jomjol-flowcontroll/test_flow_postrocess_helper.h b/code/test/components/jomjol-flowcontroll/test_flow_postrocess_helper.h index eba0ec394..af74e05da 100644 --- a/code/test/components/jomjol-flowcontroll/test_flow_postrocess_helper.h +++ b/code/test/components/jomjol-flowcontroll/test_flow_postrocess_helper.h @@ -4,7 +4,7 @@ #include #include #include -#include +#include #include diff --git a/sd-card/config/config.ini b/sd-card/config/config.ini index 9f516bd31..5c7368b15 100644 --- a/sd-card/config/config.ini +++ b/sd-card/config/config.ini @@ -1,7 +1,7 @@ -[MakeImage] -;LogImageLocation = /log/source +[TakeImage] +;RawImagesLocation = /log/source WaitBeforeTakingPicture = 5 -;LogfileRetentionInDays = 15 +;RawImagesRetention = 15 Brightness = 0 Contrast = 0 Saturation = 0 @@ -9,7 +9,7 @@ LEDIntensity = 50 ImageQuality = 12 ImageSize = VGA FixedExposure = false -;Demo = true +Demo = false [Alignment] InitialRotate = 179 @@ -24,8 +24,8 @@ FlipImageSize = false [Digits] Model = /config/dig-cont_0600_s3.tflite CNNGoodThreshold = 0.5 -;LogImageLocation = /log/digit -;LogfileRetentionInDays = 3 +;ROIImagesLocation = /log/digit +;ROIImagesRetention = 3 main.dig1 294 126 30 54 false main.dig2 343 126 30 54 false main.dig3 391 126 30 54 false @@ -33,9 +33,8 @@ main.dig3 391 126 30 54 false [Analog] Model = /config/ana-cont_11.3.1_s2.tflite CNNGoodThreshold = 0.5 -;LogImageLocation = /log/analog -;LogfileRetentionInDays = 3 -ExtendedResolution = true +;ROIImagesLocation = /log/analog +;ROIImagesRetention = 3 main.ana1 432 230 92 92 false main.ana2 379 332 92 92 false main.ana3 283 374 92 92 false @@ -46,11 +45,11 @@ main.DecimalShift = 0 main.AnalogDigitalTransitionStart = 9.2 PreValueUse = true PreValueAgeStartup = 720 -AllowNegativeRates = false +main.AllowNegativeRates = false main.MaxRateValue = 0.05 ;main.MaxRateType = AbsoluteChange -;main.ExtendedResolution = false -;main.IgnoreLeadingNaN = true +main.ExtendedResolution = false +main.IgnoreLeadingNaN = false ErrorMessage = true CheckDigitIncreaseConsistency = false @@ -60,8 +59,8 @@ CheckDigitIncreaseConsistency = false ;ClientID = watermeter ;user = USERNAME ;password = PASSWORD -;SetRetainFlag = true -;HomeassistantDiscovery = true +RetainMessages = false +HomeassistantDiscovery = false ;MeterType = other ;[InfluxDB] @@ -85,19 +84,19 @@ LEDColor = 150 150 150 [AutoTimer] AutoStart = true -Intervall = 5 +Interval = 5 [DataLogging] DataLogActive = true -DataLogRetentionInDays = 3 +DataFilesRetention = 3 [Debug] -Logfile = 1 -LogfileRetentionInDays = 3 +LogLevel = 1 +LogfilesRetention = 3 [System] TimeZone = CET-1CEST,M3.5.0,M10.5.0/3 ;TimeServer = pool.ntp.org -;AutoAdjustSummertime = false ;Hostname = undefined +;RSSIThreshold = 0 SetupMode = true diff --git a/sd-card/html/edit_config_param.html b/sd-card/html/edit_config_param.html index d78a6dd18..cf3786574 100644 --- a/sd-card/html/edit_config_param.html +++ b/sd-card/html/edit_config_param.html @@ -102,23 +102,23 @@

Configuration

- - + + - + - Location to store raw images for logging + Location to store raw camera images - - + + - + Time to keep the raw image (in days, resp. "0" = forever) @@ -126,11 +126,10 @@

Configuration

- - + - @@ -144,10 +143,10 @@

Configuration

- WaitBeforeTakingPicture + WaitBeforeTakingPicture - + Wait time between switching illumination on and taking the picture (in seconds) @@ -155,10 +154,10 @@

Configuration

- ImageQuality + ImageQuality - + Quality index for picture (default = "12" - "0" high ... "63" low)
@@ -167,10 +166,10 @@

Configuration

- ImageSize + ImageSize - @@ -182,10 +181,10 @@

Configuration

- LEDIntensity + LEDIntensity - + Internal LED Flash Intensity (PWM from 0% - 100%).
@@ -195,10 +194,10 @@

Configuration

- Brightness + Brightness - + Image Brightness (-2 .. 2 - default = "0") @@ -207,10 +206,10 @@

Configuration

- Contrast + Contrast - + Image Contrast (-2 .. 2 - default = "0")
@@ -220,10 +219,10 @@

Configuration

- Saturation + Saturation - + Image Saturation (-2 .. 2 - default = "0")
@@ -231,12 +230,12 @@

Configuration

- + - FixedExposure + FixedExposure - @@ -289,6 +288,37 @@

Configuration

+ + + FlipImageSize + + + + + + Rotate the viewport together with the alignment rotation. + + + + + + InitialMirror + + + + + + Rotate the viewport together with the alignment rotation. + + + + @@ -325,11 +355,11 @@

- + + - + Location to store separated digits for logging @@ -337,11 +367,11 @@

- + + - + Time to keep the separated digit images (in days, resp. "0" = forever) @@ -367,18 +397,18 @@

- +

Only InfluxDB v1.x is supported as of now
@@ -764,6 +785,9 @@

+ + +

@@ -1286,10 +1310,10 @@

Enabling GPIO handler, disable by default integrated flash light.
Please - Interval + Interval - + Interval in which the number(s) are read (in minutes). If a digitalization round takes longer than this interval, the next run gets postponed until the current run completes. @@ -1316,10 +1340,10 @@
Enabling GPIO handler, disable by default integrated flash light.
Please - DataLogRetentionInDays + DataFilesRetention - + Time to keep the data files (in days - "0" = forever) @@ -1331,10 +1355,10 @@
Enabling GPIO handler, disable by default integrated flash light.
Please - Logfile Log Level + Logfile Log Level - @@ -1347,10 +1371,10 @@
Enabling GPIO handler, disable by default integrated flash light.
Please - LogfileRetentionInDays + LogfilesRetention - + Time to keep the log files (in days - "0" = forever) @@ -1400,15 +1424,15 @@
Enabling GPIO handler, disable by default integrated flash light.
Please Hostname for server - will be transfered to wlan.ini at next startup) - + - - + + - + - WLAN Mesh Parameter: Threashold for RSSI value to check for start switching access point in a mesh system. + WLAN Mesh Parameter: Threshold for RSSI value to check for start switching access point in a mesh system. Possible values: -100 to 0, 0 = disabled - Value will be transfered to wlan.ini at next startup) @@ -1481,6 +1505,7 @@
Enabling GPIO handler, disable by default integrated flash light.
Please option.text = NUMBERS[i]["name"]; option.value = i; _index.add(option); + } _index.selectedIndex = 0; } @@ -1497,8 +1522,14 @@
Enabling GPIO handler, disable by default integrated flash light.
Please } function WriteParameter(_param, _category, _cat, _name, _optional, _number = -1){ - - let anzpara = _param[_cat][_name].anzParam; + let anzpara; + try { + anzpara = _param[_cat][_name].anzParam; + } + catch (error) { + firework.launch("Parameter '" + _name + "' in category '" + _cat + "' is unknown!", 'danger', 30000); + return; + } if (_number > -1) { if ((NUMBERS[_number] == undefined) || (NUMBERS[_number][_cat] == undefined) || (NUMBERS[_number][_cat][_name] == undefined)) @@ -1775,9 +1806,10 @@
Enabling GPIO handler, disable by default integrated flash light.
Please ReadParameter(param, "PostProcessing", "AnalogDigitalTransitionStart", true, NUNBERSAkt) ReadParameter(param, "PostProcessing", "MaxRateValue", true, NUNBERSAkt) ReadParameter(param, "PostProcessing", "MaxRateType", true, NUNBERSAkt) - ReadParameter(param, "PostProcessing", "ExtendedResolution", true, NUNBERSAkt) - ReadParameter(param, "PostProcessing", "IgnoreLeadingNaN", true, NUNBERSAkt) - ReadParameter(param, "PostProcessing", "AllowNegativeRates", true, NUNBERSAkt) + + ReadParameter(param, "PostProcessing", "ExtendedResolution", false, NUNBERSAkt) + ReadParameter(param, "PostProcessing", "IgnoreLeadingNaN", false, NUNBERSAkt) + ReadParameter(param, "PostProcessing", "AllowNegativeRates", false, NUNBERSAkt) } var sel = document.getElementById("Numbers_value1"); @@ -1786,9 +1818,10 @@
Enabling GPIO handler, disable by default integrated flash light.
Please WriteParameter(param, category, "PostProcessing", "AnalogDigitalTransitionStart", true, NUNBERSAkt); WriteParameter(param, category, "PostProcessing", "MaxRateValue", true, NUNBERSAkt); WriteParameter(param, category, "PostProcessing", "MaxRateType", true, NUNBERSAkt); - WriteParameter(param, category, "PostProcessing", "ExtendedResolution", true, NUNBERSAkt); - WriteParameter(param, category, "PostProcessing", "IgnoreLeadingNaN", true, NUNBERSAkt); - WriteParameter(param, category, "PostProcessing", "AllowNegativeRates", true, NUNBERSAkt); + + WriteParameter(param, category, "PostProcessing", "ExtendedResolution", false, NUNBERSAkt); + WriteParameter(param, category, "PostProcessing", "IgnoreLeadingNaN", false, NUNBERSAkt); + WriteParameter(param, category, "PostProcessing", "AllowNegativeRates", false, NUNBERSAkt); } function UpdateInput() { @@ -1799,42 +1832,42 @@
Enabling GPIO handler, disable by default integrated flash light.
Please document.getElementById("Category_InfluxDB_enabled").checked = category["InfluxDB"]["enabled"]; setVisible("GPIO_item", category["GPIO"]["enabled"]); - WriteParameter(param, category, "MakeImage", "LogImageLocation", true); - WriteParameter(param, category, "MakeImage", "LogfileRetentionInDays", true); - WriteParameter(param, category, "MakeImage", "Demo", true); - WriteParameter(param, category, "MakeImage", "WaitBeforeTakingPicture", false); - WriteParameter(param, category, "MakeImage", "ImageQuality", false); - WriteParameter(param, category, "MakeImage", "Brightness", false); - WriteParameter(param, category, "MakeImage", "Contrast", false); - WriteParameter(param, category, "MakeImage", "Saturation", false); - WriteParameter(param, category, "MakeImage", "LEDIntensity", false); - WriteParameter(param, category, "MakeImage", "ImageSize", false); - WriteParameter(param, category, "MakeImage", "FixedExposure", false); + WriteParameter(param, category, "TakeImage", "RawImagesLocation", true); + WriteParameter(param, category, "TakeImage", "RawImagesRetention", true); + WriteParameter(param, category, "TakeImage", "Demo", false); + WriteParameter(param, category, "TakeImage", "WaitBeforeTakingPicture", false); + WriteParameter(param, category, "TakeImage", "ImageQuality", false); + WriteParameter(param, category, "TakeImage", "Brightness", false); + WriteParameter(param, category, "TakeImage", "Contrast", false); + WriteParameter(param, category, "TakeImage", "Saturation", false); + WriteParameter(param, category, "TakeImage", "LEDIntensity", false); + WriteParameter(param, category, "TakeImage", "ImageSize", false); + WriteParameter(param, category, "TakeImage", "FixedExposure", false); WriteParameter(param, category, "Alignment", "SearchFieldX", false); WriteParameter(param, category, "Alignment", "SearchFieldY", false); WriteParameter(param, category, "Alignment", "AlignmentAlgo", true); WriteParameter(param, category, "Digits", "CNNGoodThreshold", true); - WriteParameter(param, category, "Digits", "LogImageLocation", true); - WriteParameter(param, category, "Digits", "LogfileRetentionInDays", true); + WriteParameter(param, category, "Digits", "ROIImagesLocation", true); + WriteParameter(param, category, "Digits", "ROIImagesRetention", true); - WriteParameter(param, category, "Analog", "LogImageLocation", true); - WriteParameter(param, category, "Analog", "LogfileRetentionInDays", true); + WriteParameter(param, category, "Analog", "ROIImagesLocation", true); + WriteParameter(param, category, "Analog", "ROIImagesRetention", true); - WriteParameter(param, category, "PostProcessing", "PreValueUse", true); + WriteParameter(param, category, "PostProcessing", "PreValueUse", false); WriteParameter(param, category, "PostProcessing", "PreValueAgeStartup", true); // WriteParameter(param, category, "PostProcessing", "AllowNegativeRates", true); - WriteParameter(param, category, "PostProcessing", "ErrorMessage", true); - WriteParameter(param, category, "PostProcessing", "CheckDigitIncreaseConsistency", true); + WriteParameter(param, category, "PostProcessing", "ErrorMessage", false); + WriteParameter(param, category, "PostProcessing", "CheckDigitIncreaseConsistency", false); WriteParameter(param, category, "MQTT", "Uri", true); WriteParameter(param, category, "MQTT", "MainTopic", true); WriteParameter(param, category, "MQTT", "ClientID", true); WriteParameter(param, category, "MQTT", "user", true); WriteParameter(param, category, "MQTT", "password", true); - WriteParameter(param, category, "MQTT", "SetRetainFlag", true); - WriteParameter(param, category, "MQTT", "HomeassistantDiscovery", true); + WriteParameter(param, category, "MQTT", "RetainMessages", false); + WriteParameter(param, category, "MQTT", "HomeassistantDiscovery", false); WriteParameter(param, category, "MQTT", "MeterType", true); WriteParameter(param, category, "InfluxDB", "Uri", true); @@ -1854,18 +1887,18 @@
Enabling GPIO handler, disable by default integrated flash light.
Please WriteParameter(param, category, "GPIO", "LEDColor", false); WriteParameter(param, category, "AutoTimer", "AutoStart", false); - WriteParameter(param, category, "AutoTimer", "Intervall", false); + WriteParameter(param, category, "AutoTimer", "Interval", false); WriteParameter(param, category, "DataLogging", "DataLogActive", false); - WriteParameter(param, category, "DataLogging", "DataLogRetentionInDays", false); + WriteParameter(param, category, "DataLogging", "DataFilesRetention", false); - WriteParameter(param, category, "Debug", "Logfile", false); - WriteParameter(param, category, "Debug", "LogfileRetentionInDays", false); + WriteParameter(param, category, "Debug", "LogLevel", false); + WriteParameter(param, category, "Debug", "LogfilesRetention", false); WriteParameter(param, category, "System", "TimeZone", true); WriteParameter(param, category, "System", "Hostname", true); WriteParameter(param, category, "System", "TimeServer", true); - WriteParameter(param, category, "System", "RSSIThreashold", true); + WriteParameter(param, category, "System", "RSSIThreshold", true); WriteModelFiles(); } @@ -1920,17 +1953,17 @@
Enabling GPIO handler, disable by default integrated flash light.
Please category["InfluxDB"]["enabled"] = document.getElementById("Category_InfluxDB_enabled").checked; category["GPIO"]["enabled"] = document.getElementById("Category_GPIO_enabled").checked; - ReadParameter(param, "MakeImage", "LogImageLocation", true); - ReadParameter(param, "MakeImage", "LogfileRetentionInDays", true); - ReadParameter(param, "MakeImage", "Demo", true); - ReadParameter(param, "MakeImage", "WaitBeforeTakingPicture", false); - ReadParameter(param, "MakeImage", "ImageQuality", false); - ReadParameter(param, "MakeImage", "Brightness", false); - ReadParameter(param, "MakeImage", "Contrast", false); - ReadParameter(param, "MakeImage", "Saturation", false); - ReadParameter(param, "MakeImage", "LEDIntensity", false); - ReadParameter(param, "MakeImage", "ImageSize", false); - ReadParameter(param, "MakeImage", "FixedExposure", false); + ReadParameter(param, "TakeImage", "RawImagesLocation", true); + ReadParameter(param, "TakeImage", "RawImagesRetention", true); + ReadParameter(param, "TakeImage", "Demo", false); + ReadParameter(param, "TakeImage", "WaitBeforeTakingPicture", false); + ReadParameter(param, "TakeImage", "ImageQuality", false); + ReadParameter(param, "TakeImage", "Brightness", false); + ReadParameter(param, "TakeImage", "Contrast", false); + ReadParameter(param, "TakeImage", "Saturation", false); + ReadParameter(param, "TakeImage", "LEDIntensity", false); + ReadParameter(param, "TakeImage", "ImageSize", false); + ReadParameter(param, "TakeImage", "FixedExposure", false); ReadParameter(param, "Alignment", "SearchFieldX", false); ReadParameter(param, "Alignment", "SearchFieldY", false); @@ -1938,26 +1971,25 @@
Enabling GPIO handler, disable by default integrated flash light.
Please ReadParameter(param, "Digits", "Model", false); ReadParameter(param, "Digits", "CNNGoodThreshold", true); - ReadParameter(param, "Digits", "LogImageLocation", true); - ReadParameter(param, "Digits", "LogfileRetentionInDays", true); + ReadParameter(param, "Digits", "ROIImagesLocation", true); + ReadParameter(param, "Digits", "ROIImagesRetention", true); ReadParameter(param, "Analog", "Model", false); - ReadParameter(param, "Analog", "LogImageLocation", true); - ReadParameter(param, "Analog", "LogfileRetentionInDays", true); + ReadParameter(param, "Analog", "ROIImagesLocation", true); + ReadParameter(param, "Analog", "ROIImagesRetention", true); - ReadParameter(param, "PostProcessing", "PreValueUse", true); + ReadParameter(param, "PostProcessing", "PreValueUse", false); ReadParameter(param, "PostProcessing", "PreValueAgeStartup", true); -// ReadParameter(param, "PostProcessing", "AllowNegativeRates", true); - ReadParameter(param, "PostProcessing", "ErrorMessage", true); - ReadParameter(param, "PostProcessing", "CheckDigitIncreaseConsistency", true); + ReadParameter(param, "PostProcessing", "ErrorMessage", false); + ReadParameter(param, "PostProcessing", "CheckDigitIncreaseConsistency", false); ReadParameter(param, "MQTT", "Uri", true); ReadParameter(param, "MQTT", "MainTopic", true); ReadParameter(param, "MQTT", "ClientID", true); ReadParameter(param, "MQTT", "user", true); ReadParameter(param, "MQTT", "password", true); - ReadParameter(param, "MQTT", "SetRetainFlag", true); - ReadParameter(param, "MQTT", "HomeassistantDiscovery", true); + ReadParameter(param, "MQTT", "RetainMessages", false); + ReadParameter(param, "MQTT", "HomeassistantDiscovery", false); ReadParameter(param, "MQTT", "MeterType", true); ReadParameter(param, "InfluxDB", "Uri", true); @@ -1984,18 +2016,18 @@
Enabling GPIO handler, disable by default integrated flash light.
Please param["GPIO"]["LEDColor"]["found"] = true; ReadParameter(param, "AutoTimer", "AutoStart", false); - ReadParameter(param, "AutoTimer", "Intervall", false); + ReadParameter(param, "AutoTimer", "Interval", false); ReadParameter(param, "DataLogging", "DataLogActive", false); - ReadParameter(param, "DataLogging", "DataLogRetentionInDays", false); + ReadParameter(param, "DataLogging", "DataFilesRetention", false); - ReadParameter(param, "Debug", "Logfile", false); - ReadParameter(param, "Debug", "LogfileRetentionInDays", false); + ReadParameter(param, "Debug", "LogLevel", false); + ReadParameter(param, "Debug", "LogfilesRetention", false); ReadParameter(param, "System", "TimeZone", true); ReadParameter(param, "System", "Hostname", true); ReadParameter(param, "System", "TimeServer", true); - ReadParameter(param, "System", "RSSIThreashold", true); + ReadParameter(param, "System", "RSSIThreshold", true); UpdateInputIndividual(); @@ -2099,7 +2131,7 @@
Enabling GPIO handler, disable by default integrated flash light.
Please { UpdateInputIndividual(); } - + LoadConfigNeu(); diff --git a/sd-card/html/edit_reference.html b/sd-card/html/edit_reference.html index 951ffa124..e83c0d7a8 100644 --- a/sd-card/html/edit_reference.html +++ b/sd-card/html/edit_reference.html @@ -49,8 +49,8 @@

Create Reference out of Raw Image

- LEDIntensity: - + LEDIntensity: + @@ -58,8 +58,8 @@

Create Reference out of Raw Image

- Brightness: - + Brightness: + @@ -67,16 +67,16 @@

Create Reference out of Raw Image

Degrees - Contrast - + Contrast + Degrees - Saturation - + Saturation + @@ -121,13 +121,13 @@

Create Reference out of Raw Image

function doTake(){ var xhttp = new XMLHttpRequest(); - if (param["MakeImage"]["Brightness"].found && param["MakeImage"]["Brightness"].enabled) + if (param["TakeImage"]["Brightness"].found && param["TakeImage"]["Brightness"].enabled) { - _intensity = document.getElementById("MakeImage_LEDIntensity_value1").value; + _intensity = document.getElementById("TakeImage_LEDIntensity_value1").value; if (_intensity == "") _intensity = "50"; - _brightness = document.getElementById("MakeImage_Brightness_value1").value; - _contrast = document.getElementById("MakeImage_Contrast_value1").value; - _saturation = document.getElementById("MakeImage_Saturation_value1").value; + _brightness = document.getElementById("TakeImage_Brightness_value1").value; + _contrast = document.getElementById("TakeImage_Contrast_value1").value; + _saturation = document.getElementById("TakeImage_Saturation_value1").value; url = getDomainname() + "/editflow?task=test_take&bri=" + _brightness; url = url + "&con=" + _saturation + "&sat=" + _saturation + "&int=" + _intensity; } @@ -166,24 +166,24 @@

Create Reference out of Raw Image

document.getElementById("labelflip").style = "color:lightgrey;"; } - if (param["MakeImage"]["Brightness"].found && param["MakeImage"]["Brightness"].enabled) + if (param["TakeImage"]["Brightness"].found && param["TakeImage"]["Brightness"].enabled) { - document.getElementById("MakeImage_Brightness_value1").disabled = false; - document.getElementById("MakeImage_Contrast_value1").disabled = false; - document.getElementById("MakeImage_Saturation_value1").disabled = false; - document.getElementById("MakeImage_LEDIntensity_value1").disabled = false; + document.getElementById("TakeImage_Brightness_value1").disabled = false; + document.getElementById("TakeImage_Contrast_value1").disabled = false; + document.getElementById("TakeImage_Saturation_value1").disabled = false; + document.getElementById("TakeImage_LEDIntensity_value1").disabled = false; } else { - document.getElementById("MakeImage_Brightness_value1").type = "hidden"; - document.getElementById("MakeImage_Brightness_text").style.visibility = "hidden"; + document.getElementById("TakeImage_Brightness_value1").type = "hidden"; + document.getElementById("TakeImage_Brightness_text").style.visibility = "hidden"; } -// if (param["MakeImage"]["Saturation"].found) -// document.getElementById("MakeImage_Saturation_value1").disabled = false; -// if (param["MakeImage"]["Contrast"].found) -// document.getElementById("MakeImage_Contrast_value1").disabled = false; +// if (param["TakeImage"]["Saturation"].found) +// document.getElementById("TakeImage_Saturation_value1").disabled = false; +// if (param["TakeImage"]["Contrast"].found) +// document.getElementById("TakeImage_Contrast_value1").disabled = false; isActReference = false; loadCanvas(url); @@ -205,16 +205,16 @@

Create Reference out of Raw Image

document.getElementById("prerotateangle").disabled = true; document.getElementById("updatereferenceimage").disabled = true; document.getElementById("take").disabled = true; - document.getElementById("MakeImage_Brightness_value1").disabled = true; - document.getElementById("MakeImage_Saturation_value1").disabled = true; - document.getElementById("MakeImage_Contrast_value1").disabled = true; - document.getElementById("MakeImage_LEDIntensity_value1").disabled = true; + document.getElementById("TakeImage_Brightness_value1").disabled = true; + document.getElementById("TakeImage_Saturation_value1").disabled = true; + document.getElementById("TakeImage_Contrast_value1").disabled = true; + document.getElementById("TakeImage_LEDIntensity_value1").disabled = true; document.getElementById("mirror").disabled = false; document.getElementById("flip").disabled = false; - if (!(param["MakeImage"]["Brightness"].found)) + if (!(param["TakeImage"]["Brightness"].found)) { - document.getElementById("MakeImage_Brightness_value1").type = "hidden"; - document.getElementById("MakeImage_Brightness_text").style.visibility = "hidden"; + document.getElementById("TakeImage_Brightness_value1").type = "hidden"; + document.getElementById("TakeImage_Brightness_text").style.visibility = "hidden"; } @@ -253,12 +253,12 @@

Create Reference out of Raw Image

else param["Alignment"]["FlipImageSize"].value1 = "false"; - if (param["MakeImage"]["Brightness"].found && param["MakeImage"]["Brightness"].enabled) + if (param["TakeImage"]["Brightness"].found && param["TakeImage"]["Brightness"].enabled) { - ReadParameter(param, "MakeImage", "Brightness", false); - ReadParameter(param, "MakeImage", "Contrast", false); - ReadParameter(param, "MakeImage", "Saturation", false); - ReadParameter(param, "MakeImage", "LEDIntensity", false); + ReadParameter(param, "TakeImage", "Brightness", false); + ReadParameter(param, "TakeImage", "Contrast", false); + ReadParameter(param, "TakeImage", "Saturation", false); + ReadParameter(param, "TakeImage", "LEDIntensity", false); } var canvas = document.getElementById("canvas"); @@ -307,30 +307,30 @@

Create Reference out of Raw Image

ParseConfig(); param = getConfigParameters(); - param["MakeImage"]["LEDIntensity"]["enabled"] = true; - param["MakeImage"]["Brightness"]["enabled"] = true; - param["MakeImage"]["Contrast"]["enabled"] = true; - param["MakeImage"]["Saturation"]["enabled"] = true; + param["TakeImage"]["LEDIntensity"]["enabled"] = true; + param["TakeImage"]["Brightness"]["enabled"] = true; + param["TakeImage"]["Contrast"]["enabled"] = true; + param["TakeImage"]["Saturation"]["enabled"] = true; - if (!param["MakeImage"]["LEDIntensity"]["found"]) + if (!param["TakeImage"]["LEDIntensity"]["found"]) { - param["MakeImage"]["LEDIntensity"]["found"] = true; - param["MakeImage"]["LEDIntensity"]["value1"] = "50"; + param["TakeImage"]["LEDIntensity"]["found"] = true; + param["TakeImage"]["LEDIntensity"]["value1"] = "50"; } - if (!param["MakeImage"]["Brightness"]["found"]) + if (!param["TakeImage"]["Brightness"]["found"]) { - param["MakeImage"]["Brightness"]["found"] = true; - param["MakeImage"]["Brightness"]["value1"] = "0"; + param["TakeImage"]["Brightness"]["found"] = true; + param["TakeImage"]["Brightness"]["value1"] = "0"; } - if (!param["MakeImage"]["Contrast"]["found"]) + if (!param["TakeImage"]["Contrast"]["found"]) { - param["MakeImage"]["Contrast"]["found"] = true; - param["MakeImage"]["Contrast"]["value1"] = "0"; + param["TakeImage"]["Contrast"]["found"] = true; + param["TakeImage"]["Contrast"]["value1"] = "0"; } - if (!param["MakeImage"]["Saturation"]["found"]) + if (!param["TakeImage"]["Saturation"]["found"]) { - param["MakeImage"]["Saturation"]["found"] = true; - param["MakeImage"]["Saturation"]["value1"] = "0"; + param["TakeImage"]["Saturation"]["found"] = true; + param["TakeImage"]["Saturation"]["value1"] = "0"; } UpdateInput(); @@ -338,10 +338,10 @@

Create Reference out of Raw Image

} function UpdateInput() { - WriteParameter(param, category, "MakeImage", "Brightness", false); - WriteParameter(param, category, "MakeImage", "Contrast", false); - WriteParameter(param, category, "MakeImage", "Saturation", false); - WriteParameter(param, category, "MakeImage", "LEDIntensity", false); + WriteParameter(param, category, "TakeImage", "Brightness", false); + WriteParameter(param, category, "TakeImage", "Contrast", false); + WriteParameter(param, category, "TakeImage", "Saturation", false); + WriteParameter(param, category, "TakeImage", "LEDIntensity", false); } diff --git a/sd-card/html/readconfigparam.js b/sd-card/html/readconfigparam.js index b92b2611f..3b26c5ce1 100644 --- a/sd-card/html/readconfigparam.js +++ b/sd-card/html/readconfigparam.js @@ -105,14 +105,14 @@ function ParseConfig() { param = new Object(); category = new Object(); - var catname = "MakeImage"; + var catname = "TakeImage"; category[catname] = new Object(); category[catname]["enabled"] = false; category[catname]["found"] = false; param[catname] = new Object(); - ParamAddValue(param, catname, "LogImageLocation"); + ParamAddValue(param, catname, "RawImagesLocation"); ParamAddValue(param, catname, "WaitBeforeTakingPicture"); - ParamAddValue(param, catname, "LogfileRetentionInDays"); + ParamAddValue(param, catname, "RawImagesRetention"); ParamAddValue(param, catname, "Demo"); ParamAddValue(param, catname, "Brightness"); ParamAddValue(param, catname, "Contrast"); @@ -141,8 +141,8 @@ function ParseConfig() { param[catname] = new Object(); ParamAddValue(param, catname, "Model"); ParamAddValue(param, catname, "CNNGoodThreshold", 1); - ParamAddValue(param, catname, "LogImageLocation"); - ParamAddValue(param, catname, "LogfileRetentionInDays"); + ParamAddValue(param, catname, "ROIImagesLocation"); + ParamAddValue(param, catname, "ROIImagesRetention"); var catname = "Analog"; category[catname] = new Object(); @@ -150,8 +150,8 @@ function ParseConfig() { category[catname]["found"] = false; param[catname] = new Object(); ParamAddValue(param, catname, "Model"); - ParamAddValue(param, catname, "LogImageLocation"); - ParamAddValue(param, catname, "LogfileRetentionInDays"); + ParamAddValue(param, catname, "ROIImagesLocation"); + ParamAddValue(param, catname, "ROIImagesRetention"); var catname = "PostProcessing"; category[catname] = new Object(); @@ -181,7 +181,7 @@ function ParseConfig() { ParamAddValue(param, catname, "ClientID"); ParamAddValue(param, catname, "user"); ParamAddValue(param, catname, "password"); - ParamAddValue(param, catname, "SetRetainFlag"); + ParamAddValue(param, catname, "RetainMessages"); ParamAddValue(param, catname, "HomeassistantDiscovery"); ParamAddValue(param, catname, "MeterType"); @@ -196,6 +196,7 @@ function ParseConfig() { ParamAddValue(param, catname, "user"); ParamAddValue(param, catname, "password"); + var catname = "GPIO"; category[catname] = new Object(); category[catname]["enabled"] = false; @@ -224,7 +225,7 @@ function ParseConfig() { category[catname]["found"] = false; param[catname] = new Object(); ParamAddValue(param, catname, "AutoStart"); - ParamAddValue(param, catname, "Intervall"); + ParamAddValue(param, catname, "Interval"); var catname = "DataLogging"; category[catname] = new Object(); @@ -232,15 +233,15 @@ function ParseConfig() { category[catname]["found"] = false; param[catname] = new Object(); ParamAddValue(param, catname, "DataLogActive"); - ParamAddValue(param, catname, "DataLogRetentionInDays"); + ParamAddValue(param, catname, "DataFilesRetention"); var catname = "Debug"; category[catname] = new Object(); category[catname]["enabled"] = false; category[catname]["found"] = false; param[catname] = new Object(); - ParamAddValue(param, catname, "Logfile"); - ParamAddValue(param, catname, "LogfileRetentionInDays"); + ParamAddValue(param, catname, "LogLevel"); + ParamAddValue(param, catname, "LogfilesRetention"); var catname = "System"; category[catname] = new Object(); @@ -249,9 +250,8 @@ function ParseConfig() { param[catname] = new Object(); ParamAddValue(param, catname, "TimeZone"); ParamAddValue(param, catname, "TimeServer"); - ParamAddValue(param, catname, "AutoAdjustSummertime"); ParamAddValue(param, catname, "Hostname"); - ParamAddValue(param, catname, "RSSIThreashold"); + ParamAddValue(param, catname, "RSSIThreshold"); ParamAddValue(param, catname, "SetupMode"); @@ -273,22 +273,7 @@ function ParseConfig() { aktline++; } - - // Make the downward compatiblity with MQTT (Maintopic --> topic) - if (param["MQTT"]["Topic"]["found"] == true && param["MQTT"]["MainTopic"]["found"] == false) - { - param["MQTT"]["MainTopic"] = param["MQTT"]["Topic"] - } - delete param["MQTT"]["Topic"] // Dient nur der Downwardskompatibilität - - - if (param["Debug"]["Logfile"]["value1"] == "false" || param["Debug"]["Logfile"]["value1"] == "true") - { - param["Debug"]["Logfile"]["value1"] = "2"; - } - - - // Make the downward compatiblity with MQTT (Maintopic --> topic) + // Make the downward compatiblity if (category["DataLogging"]["found"] == false) { category["DataLogging"]["found"] = true; @@ -298,9 +283,9 @@ function ParseConfig() { param["DataLogging"]["DataLogActive"]["enabled"] = true; param["DataLogging"]["DataLogActive"]["value1"] = "true"; - param["DataLogging"]["DataLogRetentionInDays"]["found"] = true; - param["DataLogging"]["DataLogRetentionInDays"]["enabled"] = true; - param["DataLogging"]["DataLogRetentionInDays"]["value1"] = "3"; + param["DataLogging"]["DataFilesRetention"]["found"] = true; + param["DataLogging"]["DataFilesRetention"]["enabled"] = true; + param["DataLogging"]["DataFilesRetention"]["value1"] = "3"; } if (category["DataLogging"]["enabled"] == false) @@ -313,11 +298,11 @@ function ParseConfig() { param["DataLogging"]["DataLogActive"]["value1"] = "true"; } - if (param["DataLogging"]["DataLogRetentionInDays"]["enabled"] == false && param["DataLogging"]["DataLogRetentionInDays"]["value1"] == "") + if (param["DataLogging"]["DataFilesRetention"]["enabled"] == false && param["DataLogging"]["DataFilesRetention"]["value1"] == "") { - param["DataLogging"]["DataLogRetentionInDays"]["found"] = true; - param["DataLogging"]["DataLogRetentionInDays"]["enabled"] = true; - param["DataLogging"]["DataLogRetentionInDays"]["value1"] = "3"; + param["DataLogging"]["DataFilesRetention"]["found"] = true; + param["DataLogging"]["DataFilesRetention"]["enabled"] = true; + param["DataLogging"]["DataFilesRetention"]["value1"] = "3"; } }