refactored check if logfile is enabled. error messages always get logged now

This commit is contained in:
CaCO3
2022-10-27 10:44:28 +02:00
parent ca45d0a278
commit f4ae688527
8 changed files with 8 additions and 23 deletions

View File

@@ -263,7 +263,6 @@ void CCamera::EnableAutoExposure(int flashdauer)
ESP_LOGE(TAGCAMERACLASS, "Camera Capture Failed"); ESP_LOGE(TAGCAMERACLASS, "Camera Capture Failed");
LEDOnOff(false); LEDOnOff(false);
LightOnOff(false); LightOnOff(false);
LogFile.SwitchOnOff(true);
LogFile.WriteToFile(ESP_LOG_ERROR, "Camera Capture Failed (Procedure 'EnableAutoExposure') --> Reboot! " LogFile.WriteToFile(ESP_LOG_ERROR, "Camera Capture Failed (Procedure 'EnableAutoExposure') --> Reboot! "
"Check that your camera module is working and connected properly."); "Check that your camera module is working and connected properly.");
//doReboot(); //doReboot();
@@ -315,7 +314,6 @@ esp_err_t CCamera::CaptureToBasisImage(CImageBasis *_Image, int delay)
LEDOnOff(false); LEDOnOff(false);
LightOnOff(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, ...). " LogFile.WriteToFile(ESP_LOG_ERROR, "Camera is not working anymore (CCamera::CaptureToBasisImage) - most probably caused by a hardware problem (instablility, ...). "
"System will reboot."); "System will reboot.");
doReboot(); doReboot();
@@ -328,7 +326,6 @@ esp_err_t CCamera::CaptureToBasisImage(CImageBasis *_Image, int delay)
if (!zwischenspeicher) if (!zwischenspeicher)
{ {
ESP_LOGE(TAGCAMERACLASS, "Insufficient memory space for image in function CaptureToBasisImage()"); 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()"); LogFile.WriteToFile(ESP_LOG_ERROR, "Insufficient memory space for image in function CaptureToBasisImage()");
} }
for (int i = 0; i < _size; ++i) 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"); ESP_LOGE(TAGCAMERACLASS, "CaptureToFile: Camera Capture Failed");
LEDOnOff(false); LEDOnOff(false);
LightOnOff(false); LightOnOff(false);
LogFile.SwitchOnOff(true);
LogFile.WriteToFile(ESP_LOG_ERROR, "Camera Capture Failed (CCamera::CaptureToFile) --> Reboot! " LogFile.WriteToFile(ESP_LOG_ERROR, "Camera Capture Failed (CCamera::CaptureToFile) --> Reboot! "
"Check that your camera module is working and connected properly."); "Check that your camera module is working and connected properly.");
//doReboot(); //doReboot();

View File

@@ -492,7 +492,6 @@ void task_reboot(void *pvParameter)
} }
void doReboot(){ void doReboot(){
LogFile.SwitchOnOff(true);
LogFile.WriteToFile(ESP_LOG_INFO, "Reboot triggered by Software (5s)."); LogFile.WriteToFile(ESP_LOG_INFO, "Reboot triggered by Software (5s).");
LogFile.WriteToFile(ESP_LOG_WARN, "Reboot in 5sec"); LogFile.WriteToFile(ESP_LOG_WARN, "Reboot in 5sec");
xTaskCreate(&task_reboot, "reboot", configMINIMAL_STACK_SIZE * 64, NULL, 10, NULL); xTaskCreate(&task_reboot, "reboot", configMINIMAL_STACK_SIZE * 64, NULL, 10, NULL);

View File

@@ -308,7 +308,6 @@ bool ClassFlowControll::doFlow(string time)
if (i) i -= 1; // vorheriger Schritt muss wiederholt werden (vermutlich Bilder aufnehmen) if (i) i -= 1; // vorheriger Schritt muss wiederholt werden (vermutlich Bilder aufnehmen)
result = false; result = false;
if (repeat > 5) { if (repeat > 5) {
LogFile.SwitchOnOff(true);
LogFile.WriteToFile(ESP_LOG_ERROR, "Wiederholung 5x nicht erfolgreich --> reboot"); LogFile.WriteToFile(ESP_LOG_ERROR, "Wiederholung 5x nicht erfolgreich --> reboot");
doReboot(); doReboot();
// Schritt wurde 5x wiederholt --> reboot // 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 !!! // reboot notwendig damit die neue wlan.ini auch benutzt wird !!!
fclose(pfile); fclose(pfile);
LogFile.SwitchOnOff(true); LogFile.WriteToFile(ESP_LOG_ERROR, "Rebooting to activate new HOSTNAME...");
LogFile.WriteToFile(ESP_LOG_WARN, "Rebooting to activate new HOSTNAME...");
esp_restart(); esp_restart();
hard_restart(); hard_restart();
doReboot(); doReboot();

View File

@@ -138,8 +138,7 @@ bool ClassFlowMQTT::ReadParameter(FILE* pfile, string& aktparamgraph)
} }
} }
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()) {
if (!MQTT_Init()) { // Retry if (!MQTT_Init()) { // Retry

View File

@@ -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); ESP_LOGD(TAG, "Image loaded from memory: %d, %d, %d", width, height, channels);
if ((width * height * channels) == 0) if ((width * height * channels) == 0)
{ {
LogFile.SwitchOnOff(true);
LogFile.WriteToFile(ESP_LOG_ERROR, "Image with size 0 loaded --> reboot to be done! " LogFile.WriteToFile(ESP_LOG_ERROR, "Image with size 0 loaded --> reboot to be done! "
"Check that your camera module is working and connected properly."); "Check that your camera module is working and connected properly.");

View File

@@ -120,7 +120,7 @@ void ClassLogFile::WriteToDedicatedFile(std::string _fn, esp_log_level_t level,
std::string zwtime; std::string zwtime;
std::string logline = ""; 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; return;
} }

View File

@@ -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){ 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 #ifdef __HIDE_PASSWORD
LogFile.WriteToFile(ESP_LOG_INFO, "MQTT Configuration: uri: " + _mqttURI + ", clientname: " + _clientid + 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 #else
LogFile.WriteToFile(ESP_LOG_INFO, "MQTT Configuration: uri: " + _mqttURI + ", clientname: " + _clientid + 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 #endif
uri = _mqttURI; uri = _mqttURI;
client_id = _clientid; client_id = _clientid;
lwt_topic = _lwt; lwt_topic = _maintopic + "/" + _lwt;
keepalive = _keepalive; keepalive = _keepalive;
if (_user.length() && _password.length()){ 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() { bool MQTT_Init() {

View File

@@ -219,7 +219,6 @@ extern "C" void app_main(void)
LogFile.WriteToFile(ESP_LOG_INFO, "============================================================================================="); LogFile.WriteToFile(ESP_LOG_INFO, "=============================================================================================");
LogFile.WriteToFile(ESP_LOG_INFO, versionFormated); LogFile.WriteToFile(ESP_LOG_INFO, versionFormated);
LogFile.WriteToFile(ESP_LOG_INFO, "Reset reason: " + getResetReason()); LogFile.WriteToFile(ESP_LOG_INFO, "Reset reason: " + getResetReason());
LogFile.SwitchOnOff(false);
std::string zw = gettimestring("%Y%m%d-%H%M%S"); std::string zw = gettimestring("%Y%m%d-%H%M%S");
ESP_LOGD(TAGMAIN, "time %s", zw.c_str()); 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); 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!!"; _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.WriteToFile(ESP_LOG_ERROR, _zws);
LogFile.SwitchOnOff(false);
} else { } else {
if (cam != ESP_OK) { if (cam != ESP_OK) {
LogFile.SwitchOnOff(true);
LogFile.WriteToFile(ESP_LOG_ERROR, "Failed to initialize camera module. " LogFile.WriteToFile(ESP_LOG_ERROR, "Failed to initialize camera module. "
"Check that your camera module is working and connected properly."); "Check that your camera module is working and connected properly.");
LogFile.SwitchOnOff(false);
} else { } else {
// Test Camera // Test Camera
camera_fb_t * fb = esp_camera_fb_get(); camera_fb_t * fb = esp_camera_fb_get();
if (!fb) { if (!fb) {
LogFile.SwitchOnOff(true);
LogFile.WriteToFile(ESP_LOG_ERROR, "Camera cannot be initialzed. " LogFile.WriteToFile(ESP_LOG_ERROR, "Camera cannot be initialzed. "
"System will reboot."); "System will reboot.");
doReboot(); doReboot();