From f4ae688527a75a12ac1773be84194914092573e5 Mon Sep 17 00:00:00 2001 From: CaCO3 Date: Thu, 27 Oct 2022 10:44:28 +0200 Subject: [PATCH] refactored check if logfile is enabled. error messages always get logged now --- .../jomjol_controlcamera/ClassControllCamera.cpp | 4 ---- code/components/jomjol_fileserver_ota/server_ota.cpp | 1 - code/components/jomjol_flowcontroll/ClassFlowControll.cpp | 4 +--- code/components/jomjol_flowcontroll/ClassFlowMQTT.cpp | 5 ++--- code/components/jomjol_image_proc/CImageBasis.cpp | 1 - code/components/jomjol_logfile/ClassLogFile.cpp | 2 +- code/components/jomjol_mqtt/interface_mqtt.cpp | 8 ++++---- code/main/main.cpp | 6 ------ 8 files changed, 8 insertions(+), 23 deletions(-) diff --git a/code/components/jomjol_controlcamera/ClassControllCamera.cpp b/code/components/jomjol_controlcamera/ClassControllCamera.cpp index 5790cf70..208dcefb 100644 --- a/code/components/jomjol_controlcamera/ClassControllCamera.cpp +++ b/code/components/jomjol_controlcamera/ClassControllCamera.cpp @@ -263,7 +263,6 @@ void CCamera::EnableAutoExposure(int flashdauer) ESP_LOGE(TAGCAMERACLASS, "Camera Capture Failed"); LEDOnOff(false); LightOnOff(false); - LogFile.SwitchOnOff(true); LogFile.WriteToFile(ESP_LOG_ERROR, "Camera Capture Failed (Procedure 'EnableAutoExposure') --> Reboot! " "Check that your camera module is working and connected properly."); //doReboot(); @@ -315,7 +314,6 @@ esp_err_t CCamera::CaptureToBasisImage(CImageBasis *_Image, int delay) LEDOnOff(false); LightOnOff(false); - LogFile.SwitchOnOff(true); LogFile.WriteToFile(ESP_LOG_ERROR, "Camera is not working anymore (CCamera::CaptureToBasisImage) - most probably caused by a hardware problem (instablility, ...). " "System will reboot."); doReboot(); @@ -328,7 +326,6 @@ esp_err_t CCamera::CaptureToBasisImage(CImageBasis *_Image, int delay) if (!zwischenspeicher) { ESP_LOGE(TAGCAMERACLASS, "Insufficient memory space for image in function CaptureToBasisImage()"); - LogFile.SwitchOnOff(true); LogFile.WriteToFile(ESP_LOG_ERROR, "Insufficient memory space for image in function CaptureToBasisImage()"); } for (int i = 0; i < _size; ++i) @@ -413,7 +410,6 @@ esp_err_t CCamera::CaptureToFile(std::string nm, int delay) ESP_LOGE(TAGCAMERACLASS, "CaptureToFile: Camera Capture Failed"); LEDOnOff(false); LightOnOff(false); - LogFile.SwitchOnOff(true); LogFile.WriteToFile(ESP_LOG_ERROR, "Camera Capture Failed (CCamera::CaptureToFile) --> Reboot! " "Check that your camera module is working and connected properly."); //doReboot(); diff --git a/code/components/jomjol_fileserver_ota/server_ota.cpp b/code/components/jomjol_fileserver_ota/server_ota.cpp index 17facf15..7df5e72c 100644 --- a/code/components/jomjol_fileserver_ota/server_ota.cpp +++ b/code/components/jomjol_fileserver_ota/server_ota.cpp @@ -492,7 +492,6 @@ void task_reboot(void *pvParameter) } void doReboot(){ - LogFile.SwitchOnOff(true); LogFile.WriteToFile(ESP_LOG_INFO, "Reboot triggered by Software (5s)."); LogFile.WriteToFile(ESP_LOG_WARN, "Reboot in 5sec"); xTaskCreate(&task_reboot, "reboot", configMINIMAL_STACK_SIZE * 64, NULL, 10, NULL); diff --git a/code/components/jomjol_flowcontroll/ClassFlowControll.cpp b/code/components/jomjol_flowcontroll/ClassFlowControll.cpp index bc8bfa4a..c306447c 100644 --- a/code/components/jomjol_flowcontroll/ClassFlowControll.cpp +++ b/code/components/jomjol_flowcontroll/ClassFlowControll.cpp @@ -308,7 +308,6 @@ bool ClassFlowControll::doFlow(string time) if (i) i -= 1; // vorheriger Schritt muss wiederholt werden (vermutlich Bilder aufnehmen) result = false; if (repeat > 5) { - LogFile.SwitchOnOff(true); LogFile.WriteToFile(ESP_LOG_ERROR, "Wiederholung 5x nicht erfolgreich --> reboot"); doReboot(); // Schritt wurde 5x wiederholt --> reboot @@ -496,8 +495,7 @@ bool ClassFlowControll::ReadParameter(FILE* pfile, string& aktparamgraph) { // reboot notwendig damit die neue wlan.ini auch benutzt wird !!! fclose(pfile); - LogFile.SwitchOnOff(true); - LogFile.WriteToFile(ESP_LOG_WARN, "Rebooting to activate new HOSTNAME..."); + LogFile.WriteToFile(ESP_LOG_ERROR, "Rebooting to activate new HOSTNAME..."); esp_restart(); hard_restart(); doReboot(); diff --git a/code/components/jomjol_flowcontroll/ClassFlowMQTT.cpp b/code/components/jomjol_flowcontroll/ClassFlowMQTT.cpp index 8d5351af..c2801114 100644 --- a/code/components/jomjol_flowcontroll/ClassFlowMQTT.cpp +++ b/code/components/jomjol_flowcontroll/ClassFlowMQTT.cpp @@ -137,9 +137,8 @@ bool ClassFlowMQTT::ReadParameter(FILE* pfile, string& aktparamgraph) maintopic = hostname; } } - - ESP_LOGW(TAG, "KEEPALIVE: %d", keepAlive); - MQTT_Configure(uri, clientname, user, password, maintopic, "/connection", keepAlive); + + MQTT_Configure(uri, clientname, user, password, maintopic, "connection", keepAlive); if (!MQTT_Init()) { if (!MQTT_Init()) { // Retry diff --git a/code/components/jomjol_image_proc/CImageBasis.cpp b/code/components/jomjol_image_proc/CImageBasis.cpp index f72632c7..b7fa3e84 100644 --- a/code/components/jomjol_image_proc/CImageBasis.cpp +++ b/code/components/jomjol_image_proc/CImageBasis.cpp @@ -362,7 +362,6 @@ void CImageBasis::LoadFromMemory(stbi_uc *_buffer, int len) ESP_LOGD(TAG, "Image loaded from memory: %d, %d, %d", width, height, channels); if ((width * height * channels) == 0) { - LogFile.SwitchOnOff(true); LogFile.WriteToFile(ESP_LOG_ERROR, "Image with size 0 loaded --> reboot to be done! " "Check that your camera module is working and connected properly."); diff --git a/code/components/jomjol_logfile/ClassLogFile.cpp b/code/components/jomjol_logfile/ClassLogFile.cpp index c40aeef9..05667514 100644 --- a/code/components/jomjol_logfile/ClassLogFile.cpp +++ b/code/components/jomjol_logfile/ClassLogFile.cpp @@ -120,7 +120,7 @@ void ClassLogFile::WriteToDedicatedFile(std::string _fn, esp_log_level_t level, std::string zwtime; std::string logline = ""; - if (!doLogFile){ + if (!doLogFile && level != ESP_LOG_ERROR){ // Only write to file if logfile is enabled or its an error message return; } diff --git a/code/components/jomjol_mqtt/interface_mqtt.cpp b/code/components/jomjol_mqtt/interface_mqtt.cpp index e1cc08ae..5d7e97a8 100644 --- a/code/components/jomjol_mqtt/interface_mqtt.cpp +++ b/code/components/jomjol_mqtt/interface_mqtt.cpp @@ -118,16 +118,16 @@ static void mqtt_event_handler(void *handler_args, esp_event_base_t base, int32_ void MQTT_Configure(std::string _mqttURI, std::string _clientid, std::string _user, std::string _password, std::string _maintopic, std::string _lwt, int _keepalive){ #ifdef __HIDE_PASSWORD LogFile.WriteToFile(ESP_LOG_INFO, "MQTT Configuration: uri: " + _mqttURI + ", clientname: " + _clientid + - ", user: " + _user + ", password: XXXXXXXX, last-will-topic: " + _maintopic + _lwt + ", keepAlive: " + std::to_string(_keepalive)); + ", user: " + _user + ", password: XXXXXXXX, last-will-topic: " + _maintopic + "/" + _lwt + ", keepAlive: " + std::to_string(_keepalive)); #else LogFile.WriteToFile(ESP_LOG_INFO, "MQTT Configuration: uri: " + _mqttURI + ", clientname: " + _clientid + - ", user: " + _user + ", password: " + _password + ", last-will-topic: " + _maintopic + _lwt + ", keepAlive: " + std::to_string(_keepalive)); + ", user: " + _user + ", password: " + _password + ", last-will-topic: " + _maintopic + "/" + _lwt + ", keepAlive: " + std::to_string(_keepalive)); #endif uri = _mqttURI; client_id = _clientid; - lwt_topic = _lwt; + lwt_topic = _maintopic + "/" + _lwt; keepalive = _keepalive; if (_user.length() && _password.length()){ @@ -136,7 +136,7 @@ void MQTT_Configure(std::string _mqttURI, std::string _clientid, std::string _us } - LogFile.WriteToFile(ESP_LOG_INFO, "MQTT maintopic: %s", _maintopic.c_str()); + LogFile.WriteToFile(ESP_LOG_INFO, "MQTT maintopic: " + _maintopic); } bool MQTT_Init() { diff --git a/code/main/main.cpp b/code/main/main.cpp index 9cdf60fc..5f1da209 100644 --- a/code/main/main.cpp +++ b/code/main/main.cpp @@ -219,7 +219,6 @@ extern "C" void app_main(void) LogFile.WriteToFile(ESP_LOG_INFO, "============================================================================================="); LogFile.WriteToFile(ESP_LOG_INFO, versionFormated); LogFile.WriteToFile(ESP_LOG_INFO, "Reset reason: " + getResetReason()); - LogFile.SwitchOnOff(false); std::string zw = gettimestring("%Y%m%d-%H%M%S"); ESP_LOGD(TAGMAIN, "time %s", zw.c_str()); @@ -229,20 +228,15 @@ extern "C" void app_main(void) { std::string _zws = "Not enough PSRAM available. Expected 4.194.304 MByte - available: " + std::to_string(_hsize); _zws = _zws + "\nEither not initialzed, too small (2MByte only) or not present at all. Firmware cannot start!!"; - LogFile.SwitchOnOff(true); LogFile.WriteToFile(ESP_LOG_ERROR, _zws); - LogFile.SwitchOnOff(false); } else { if (cam != ESP_OK) { - LogFile.SwitchOnOff(true); LogFile.WriteToFile(ESP_LOG_ERROR, "Failed to initialize camera module. " "Check that your camera module is working and connected properly."); - LogFile.SwitchOnOff(false); } else { // Test Camera camera_fb_t * fb = esp_camera_fb_get(); if (!fb) { - LogFile.SwitchOnOff(true); LogFile.WriteToFile(ESP_LOG_ERROR, "Camera cannot be initialzed. " "System will reboot."); doReboot();