From 26cbc8f9562834e34a322dfed9234f69d2638cd7 Mon Sep 17 00:00:00 2001 From: Mathieu Carbou Date: Mon, 30 Dec 2024 16:34:53 +0100 Subject: [PATCH] code cleanup + logging set for once at boot time (debug mode requires restart) --- include/YaSolR.h | 35 ++---- .../{YaSolRWebsite.h => yasolr_dashboard.h} | 2 +- include/{YaSolRDefines.h => yasolr_macros.h} | 0 src/main.cpp | 33 ++---- ...yasolr_configure.cpp => yasolr_router.cpp} | 53 ++++++--- src/yasolr_boot.cpp | 2 +- src/yasolr_config.cpp | 7 +- src/{Website.cpp => yasolr_dashboard.cpp} | 8 +- src/yasolr_display.cpp | 4 +- src/yasolr_ds18.cpp | 4 +- src/yasolr_grid.cpp | 2 +- src/yasolr_jsy.cpp | 8 +- src/yasolr_jsy_remote.cpp | 2 +- src/yasolr_lights.cpp | 2 +- src/yasolr_logging.cpp | 112 +++++------------- src/yasolr_mqtt.cpp | 10 +- src/yasolr_network.cpp | 4 +- src/yasolr_pzem.cpp | 11 +- src/yasolr_system.cpp | 2 +- src/yasolr_trial.cpp | 2 +- src/yasolr_web_server.cpp | 16 ++- src/yasolr_zcd.cpp | 2 +- 22 files changed, 139 insertions(+), 182 deletions(-) rename include/{YaSolRWebsite.h => yasolr_dashboard.h} (99%) rename include/{YaSolRDefines.h => yasolr_macros.h} (100%) rename src/todo/{yasolr_configure.cpp => yasolr_router.cpp} (89%) rename src/{Website.cpp => yasolr_dashboard.cpp} (99%) diff --git a/include/YaSolR.h b/include/YaSolR.h index a5975b4d..707b327e 100644 --- a/include/YaSolR.h +++ b/include/YaSolR.h @@ -55,14 +55,14 @@ #include #endif -#include +#include // web server extern AsyncWebServer webServer; -extern LoggingMiddleware loggingMiddleware; extern ESPDash dashboard; extern Mycila::Task dashboardInitTask; extern Mycila::Task dashboardUpdateTask; +extern void yasolr_init_web_server(); // Config extern Mycila::Config config; @@ -70,7 +70,6 @@ extern void yasolr_init_config(); // Network extern Mycila::ESPConnect espConnect; -extern Mycila::Task networkStartTask; extern void yasolr_init_network(); // grid electricity @@ -81,15 +80,9 @@ extern float yasolr_frequency(); // logging extern Mycila::Logger logger; extern void yasolr_init_logging(); -extern void yasolr_configure_logging(); - -// router -extern Mycila::PID pidController; -extern Mycila::Router router; // JSY extern Mycila::JSY* jsy; -extern Mycila::Task* jsyTask; extern Mycila::TaskManager* jsyTaskManager; extern void yasolr_init_jsy(); @@ -103,25 +96,21 @@ extern void yasolr_init_jsy_remote(); extern Mycila::DS18* ds18O1; extern Mycila::DS18* ds18O2; extern Mycila::DS18* ds18Sys; -extern Mycila::Task* ds18Task; extern void yasolr_init_ds18(); // Display extern Mycila::EasyDisplay* display; -extern Mycila::Task* displayCarouselTask; -extern Mycila::Task* displayTask; extern void yasolr_init_display(); // ZCD extern Mycila::PulseAnalyzer* pulseAnalyzer; +extern void yasolr_init_zcd(); // MQTT extern Mycila::MQTT* mqtt; extern Mycila::Task* mqttConnectTask; extern Mycila::Task* mqttPublishConfigTask; -extern Mycila::Task* mqttPublishStaticTask; extern Mycila::Task* mqttPublishTask; -extern Mycila::Task* haDiscoveryTask; extern void yasolr_init_mqtt(); // PZEM @@ -129,7 +118,6 @@ extern Mycila::PZEM* pzemO1; extern Mycila::PZEM* pzemO2; extern Mycila::Task* pzemO1PairingTask; extern Mycila::Task* pzemO2PairingTask; -extern Mycila::Task* pzemTask; extern Mycila::TaskManager* pzemTaskManager; extern void yasolr_init_pzem(); @@ -149,25 +137,18 @@ extern void yasolr_init_system(); // Trial extern void yasolr_init_trial(); -// init -extern void yasolr_init_web_server(); -extern void yasolr_init_zcd(); - -// TODO -extern void yasolr_divert(); -extern void yasolr_configure(); - +// router extern Mycila::Dimmer dimmerO1; extern Mycila::Dimmer dimmerO2; +extern Mycila::PID pidController; extern Mycila::Relay bypassRelayO1; extern Mycila::Relay bypassRelayO2; extern Mycila::Relay relay1; extern Mycila::Relay relay2; +extern Mycila::Router router; extern Mycila::RouterOutput output1; extern Mycila::RouterOutput output2; extern Mycila::RouterRelay routerRelay1; extern Mycila::RouterRelay routerRelay2; - -extern Mycila::Task calibrationTask; -extern Mycila::Task relayTask; -extern Mycila::Task routerTask; +extern void yasolr_divert(); +extern void yasolr_init_router(); diff --git a/include/YaSolRWebsite.h b/include/yasolr_dashboard.h similarity index 99% rename from include/YaSolRWebsite.h rename to include/yasolr_dashboard.h index f03b73b8..5a801e65 100644 --- a/include/YaSolRWebsite.h +++ b/include/yasolr_dashboard.h @@ -4,7 +4,7 @@ */ #pragma once -#include +#include #include #include diff --git a/include/YaSolRDefines.h b/include/yasolr_macros.h similarity index 100% rename from include/YaSolRDefines.h rename to include/yasolr_macros.h diff --git a/src/main.cpp b/src/main.cpp index f062003a..0b2bed9a 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -2,30 +2,14 @@ /* * Copyright (C) 2023-2024 Mathieu Carbou */ -#include - -Mycila::PID pidController; -Mycila::Router router(pidController); -Mycila::Dimmer dimmerO1; -Mycila::Dimmer dimmerO2; -Mycila::Relay bypassRelayO1; -Mycila::Relay bypassRelayO2; -Mycila::Relay relay1; -Mycila::Relay relay2; -Mycila::RouterRelay routerRelay1(relay1); -Mycila::RouterRelay routerRelay2(relay2); -Mycila::RouterOutput output1("output1", dimmerO1, bypassRelayO1); -Mycila::RouterOutput output2("output2", dimmerO2, bypassRelayO2); +#include void setup() { - // boot - yasolr_boot(); - // config - yasolr_init_config(); - // logging - yasolr_init_logging(); - // system - yasolr_init_system(); + yasolr_boot(); // boot sequence + yasolr_init_config(); // load configuration from NVS + yasolr_init_logging(); // init logging + yasolr_init_system(); // init system (safeboot, restart, reset, etc) + // hardware yasolr_init_display(); yasolr_init_ds18(); @@ -39,10 +23,9 @@ void setup() { yasolr_init_trial(); yasolr_init_web_server(); yasolr_init_zcd(); - // logging configuration - yasolr_configure_logging(); - yasolr_configure(); // TODO + // router + yasolr_init_router(); // core task manager assert(coreTaskManager.asyncStart(512 * 8, 1, 1, 100, true)); diff --git a/src/todo/yasolr_configure.cpp b/src/todo/yasolr_router.cpp similarity index 89% rename from src/todo/yasolr_configure.cpp rename to src/todo/yasolr_router.cpp index e2e968ad..f0e4c347 100644 --- a/src/todo/yasolr_configure.cpp +++ b/src/todo/yasolr_router.cpp @@ -2,11 +2,24 @@ /* * Copyright (C) 2023-2024 Mathieu Carbou */ -#include -#include +#include +#include #include +Mycila::PID pidController; +Mycila::Router router(pidController); +Mycila::Dimmer dimmerO1; +Mycila::Dimmer dimmerO2; +Mycila::Relay bypassRelayO1; +Mycila::Relay bypassRelayO2; +Mycila::Relay relay1; +Mycila::Relay relay2; +Mycila::RouterRelay routerRelay1(relay1); +Mycila::RouterRelay routerRelay2(relay2); +Mycila::RouterOutput output1("output1", dimmerO1, bypassRelayO1); +Mycila::RouterOutput output2("output2", dimmerO2, bypassRelayO2); + Mycila::Task calibrationTask("Calibration", [](void* params) { router.calibrate(); }); Mycila::Task relayTask("Relay", [](void* params) { @@ -58,7 +71,7 @@ void yasolr_divert() { } } -void yasolr_configure() { +void yasolr_init_router() { logger.info(TAG, "Configuring %s", Mycila::AppInfo.nameModelVersion.c_str()); // PID Controller @@ -119,21 +132,6 @@ void yasolr_configure() { routerRelay1.setLoad(config.getLong(KEY_RELAY1_LOAD)); routerRelay2.setLoad(config.getLong(KEY_RELAY2_LOAD)); - // Dimmers - - // coreTaskManager - calibrationTask.setEnabledWhen([]() { return router.isCalibrationRunning(); }); - calibrationTask.setInterval(1 * Mycila::TaskDuration::SECONDS); - relayTask.setEnabledWhen([]() { return !router.isCalibrationRunning() && (routerRelay1.isAutoRelayEnabled() || routerRelay2.isAutoRelayEnabled()); }); - relayTask.setInterval(7 * Mycila::TaskDuration::SECONDS); - routerTask.setEnabledWhen([]() { return !router.isCalibrationRunning(); }); - routerTask.setInterval(500 * Mycila::TaskDuration::MILLISECONDS); - - // coreTaskManager - calibrationTask.setManager(coreTaskManager); - relayTask.setManager(coreTaskManager); - routerTask.setManager(coreTaskManager); - // Router router.addOutput(output1); router.addOutput(output2); @@ -158,4 +156,23 @@ void yasolr_configure() { if (mqttPublishTask) mqttPublishTask->requestEarlyRun(); }); + + // coreTaskManager + calibrationTask.setEnabledWhen([]() { return router.isCalibrationRunning(); }); + calibrationTask.setInterval(1 * Mycila::TaskDuration::SECONDS); + calibrationTask.setManager(coreTaskManager); + + relayTask.setEnabledWhen([]() { return !router.isCalibrationRunning() && (routerRelay1.isAutoRelayEnabled() || routerRelay2.isAutoRelayEnabled()); }); + relayTask.setInterval(7 * Mycila::TaskDuration::SECONDS); + relayTask.setManager(coreTaskManager); + + routerTask.setEnabledWhen([]() { return !router.isCalibrationRunning(); }); + routerTask.setInterval(500 * Mycila::TaskDuration::MILLISECONDS); + routerTask.setManager(coreTaskManager); + + if (config.getBool(KEY_ENABLE_DEBUG)) { + calibrationTask.enableProfiling(10, Mycila::TaskTimeUnit::MILLISECONDS); + relayTask.enableProfiling(10, Mycila::TaskTimeUnit::MILLISECONDS); + routerTask.enableProfiling(10, Mycila::TaskTimeUnit::MILLISECONDS); + } } diff --git a/src/yasolr_boot.cpp b/src/yasolr_boot.cpp index 3daa16b0..98d97b87 100644 --- a/src/yasolr_boot.cpp +++ b/src/yasolr_boot.cpp @@ -2,7 +2,7 @@ /* * Copyright (C) 2023-2024 Mathieu Carbou */ -#include +#include void yasolr_boot() { Serial.begin(YASOLR_SERIAL_BAUDRATE); diff --git a/src/yasolr_config.cpp b/src/yasolr_config.cpp index 44ef12f5..410827b8 100644 --- a/src/yasolr_config.cpp +++ b/src/yasolr_config.cpp @@ -2,7 +2,7 @@ /* * Copyright (C) 2023-2024 Mathieu Carbou */ -#include +#include #include @@ -129,10 +129,7 @@ void yasolr_init_config() { logger.info(TAG, "'%s' => '%s'", k, newValue.c_str()); const std::string key = k; - if (key == KEY_ENABLE_DEBUG) { - yasolr_configure_logging(); - - } else if (key == KEY_RELAY1_LOAD) { + if (key == KEY_RELAY1_LOAD) { routerRelay1.setLoad(config.getLong(KEY_RELAY1_LOAD)); } else if (key == KEY_RELAY2_LOAD) { diff --git a/src/Website.cpp b/src/yasolr_dashboard.cpp similarity index 99% rename from src/Website.cpp rename to src/yasolr_dashboard.cpp index f1abca6c..d9f4220d 100644 --- a/src/Website.cpp +++ b/src/yasolr_dashboard.cpp @@ -2,7 +2,7 @@ /* * Copyright (C) 2023-2024 Mathieu Carbou */ -#include +#include #include #include @@ -967,13 +967,15 @@ void YaSolR::Website::initCards() { // management + const bool debug = config.getBool(KEY_ENABLE_DEBUG); _configBackup.setValue("/api/config/backup"); _configRestore.setValue("/api/config/restore"); _consoleLink.setValue("/console"); _debugInfo.setValue("/api/debug"); - _debugMode.setValue(config.getBool(KEY_ENABLE_DEBUG)); + _debugMode.setValue(debug); _energyReset.setDisplay(jsyEnabled || pzem1Enabled || pzem2Enabled); - _debugInfo.setDisplay(config.getBool(KEY_ENABLE_DEBUG)); + _consoleLink.setDisplay(debug); + _debugInfo.setDisplay(debug); // network diff --git a/src/yasolr_display.cpp b/src/yasolr_display.cpp index ef5115f3..170e001b 100644 --- a/src/yasolr_display.cpp +++ b/src/yasolr_display.cpp @@ -2,7 +2,7 @@ /* * Copyright (C) 2023-2024 Mathieu Carbou */ -#include +#include #include @@ -201,5 +201,7 @@ void yasolr_init_display() { displayTask->setInterval(500 * Mycila::TaskDuration::MILLISECONDS); displayTask->setManager(coreTaskManager); + if (config.getBool(KEY_ENABLE_DEBUG)) + displayTask->enableProfiling(10, Mycila::TaskTimeUnit::MILLISECONDS); } } diff --git a/src/yasolr_ds18.cpp b/src/yasolr_ds18.cpp index 0d41da84..e316c94a 100644 --- a/src/yasolr_ds18.cpp +++ b/src/yasolr_ds18.cpp @@ -2,7 +2,7 @@ /* * Copyright (C) 2023-2024 Mathieu Carbou */ -#include +#include Mycila::DS18* ds18O1; Mycila::DS18* ds18O2; @@ -93,5 +93,7 @@ void yasolr_init_ds18() { }); ds18Task->setInterval(10 * Mycila::TaskDuration::SECONDS); ds18Task->setManager(coreTaskManager); + if (config.getBool(KEY_ENABLE_DEBUG)) + ds18Task->enableProfiling(10, Mycila::TaskTimeUnit::MILLISECONDS); } } diff --git a/src/yasolr_grid.cpp b/src/yasolr_grid.cpp index c53fc365..96ae4415 100644 --- a/src/yasolr_grid.cpp +++ b/src/yasolr_grid.cpp @@ -2,7 +2,7 @@ /* * Copyright (C) 2023-2024 Mathieu Carbou */ -#include +#include Mycila::Grid grid; diff --git a/src/yasolr_jsy.cpp b/src/yasolr_jsy.cpp index 7d3a80c8..ec3c3cee 100644 --- a/src/yasolr_jsy.cpp +++ b/src/yasolr_jsy.cpp @@ -2,7 +2,7 @@ /* * Copyright (C) 2023-2024 Mathieu Carbou */ -#include +#include Mycila::JSY* jsy; Mycila::Task* jsyTask; @@ -96,10 +96,16 @@ void yasolr_init_jsy() { }); // async task + jsyTaskManager = new Mycila::TaskManager("y-jsy"); + jsyTask = new Mycila::Task("JSY", [](void* params) { jsy->read(); }); jsyTask->setManager(*jsyTaskManager); + if (config.getBool(KEY_ENABLE_DEBUG)) + jsyTask->enableProfiling(10, Mycila::TaskTimeUnit::MILLISECONDS); + assert(jsyTaskManager->asyncStart(512 * 4, 5, 0, 100, true)); + Mycila::TaskMonitor.addTask(jsyTaskManager->getName()); } } diff --git a/src/yasolr_jsy_remote.cpp b/src/yasolr_jsy_remote.cpp index 1f7e99fc..6430e652 100644 --- a/src/yasolr_jsy_remote.cpp +++ b/src/yasolr_jsy_remote.cpp @@ -2,7 +2,7 @@ /* * Copyright (C) 2023-2024 Mathieu Carbou */ -#include +#include AsyncUDP* udp; Mycila::CircularBuffer* udpMessageRateBuffer; diff --git a/src/yasolr_lights.cpp b/src/yasolr_lights.cpp index 5ba523d7..cb233dad 100644 --- a/src/yasolr_lights.cpp +++ b/src/yasolr_lights.cpp @@ -2,7 +2,7 @@ /* * Copyright (C) 2023-2024 Mathieu Carbou */ -#include +#include Mycila::TrafficLight lights; diff --git a/src/yasolr_logging.cpp b/src/yasolr_logging.cpp index 3f28450c..87920749 100644 --- a/src/yasolr_logging.cpp +++ b/src/yasolr_logging.cpp @@ -2,106 +2,48 @@ /* * Copyright (C) 2023-2024 Mathieu Carbou */ -#include +#include static const Mycila::TaskDoneCallback LOG_EXEC_TIME = [](const Mycila::Task& me, const uint32_t elapsed) { logger.debug(TAG, "Task '%s' finished in %" PRIu32 " us", me.getName(), elapsed); }; Mycila::Logger logger; - -Mycila::Task loggingTask("Debug", [](void* params) { - logger.info(TAG, "Free Heap: %" PRIu32, ESP.getFreeHeap()); - Mycila::TaskMonitor.log(); - coreTaskManager.log(); - unsafeTaskManager.log(); - if (jsyTaskManager) - jsyTaskManager->log(); - if (pzemTaskManager) - pzemTaskManager->log(); -}); +Mycila::Task* loggingTask; void yasolr_init_logging() { logger.info(TAG, "Initialize logging..."); - logger.setLevel(config.getBool(KEY_ENABLE_DEBUG) ? ARDUHAL_LOG_LEVEL_DEBUG : ARDUHAL_LOG_LEVEL_INFO); - esp_log_level_set("*", static_cast(logger.getLevel())); + if (config.getBool(KEY_ENABLE_DEBUG)) { + logger.setLevel(ARDUHAL_LOG_LEVEL_DEBUG); + esp_log_level_set("*", static_cast(ARDUHAL_LOG_LEVEL_DEBUG)); #ifdef APP_MODEL_PRO - WebSerial.setID(Mycila::AppInfo.firmware.c_str()); - WebSerial.setTitle((Mycila::AppInfo.name + " Web Console").c_str()); - WebSerial.setInput(false); + WebSerial.setID(Mycila::AppInfo.firmware.c_str()); + WebSerial.setTitle((Mycila::AppInfo.name + " Web Console").c_str()); + WebSerial.setInput(false); #endif + WebSerial.begin(&webServer, "/console"); + logger.forwardTo(&WebSerial); + + loggingTask = new Mycila::Task("Debug", [](void* params) { + logger.info(TAG, "Free Heap: %" PRIu32, ESP.getFreeHeap()); + Mycila::TaskMonitor.log(); + coreTaskManager.log(); + unsafeTaskManager.log(); + if (jsyTaskManager) + jsyTaskManager->log(); + if (pzemTaskManager) + pzemTaskManager->log(); + }); + + loggingTask->setInterval(20 * Mycila::TaskDuration::SECONDS); + loggingTask->enableProfiling(10, Mycila::TaskTimeUnit::MILLISECONDS); + loggingTask->setManager(unsafeTaskManager); - WebSerial.begin(&webServer, "/console"); - logger.forwardTo(&WebSerial); - - loggingTask.setInterval(20 * Mycila::TaskDuration::SECONDS); - loggingTask.setManager(coreTaskManager); -} - -void yasolr_configure_logging() { - logger.info(TAG, "Configuring logging..."); - - const bool debug = config.getBool(KEY_ENABLE_DEBUG); - - logger.setLevel(debug ? ARDUHAL_LOG_LEVEL_DEBUG : ARDUHAL_LOG_LEVEL_INFO); - esp_log_level_set("*", static_cast(logger.getLevel())); - - loggingMiddleware.setEnabled(debug); - loggingTask.setEnabled(debug); - - if (debug) { Mycila::TaskMonitor.begin(); - - dashboardUpdateTask.enableProfiling(10, Mycila::TaskTimeUnit::MILLISECONDS); - loggingTask.enableProfiling(10, Mycila::TaskTimeUnit::MILLISECONDS); - if (ds18Task) - ds18Task->enableProfiling(10, Mycila::TaskTimeUnit::MILLISECONDS); - if (displayTask) - displayTask->enableProfiling(10, Mycila::TaskTimeUnit::MILLISECONDS); - if (jsyTask) - jsyTask->enableProfiling(10, Mycila::TaskTimeUnit::MILLISECONDS); - if (mqttPublishTask) - mqttPublishTask->enableProfiling(10, Mycila::TaskTimeUnit::MILLISECONDS); - if (pzemTask) - pzemTask->enableProfiling(10, Mycila::TaskTimeUnit::MILLISECONDS); - } else { - Mycila::TaskMonitor.end(); - - dashboardUpdateTask.disableProfiling(); - loggingTask.disableProfiling(); - if (ds18Task) - ds18Task->disableProfiling(); - if (displayTask) - displayTask->disableProfiling(); - if (jsyTask) - jsyTask->disableProfiling(); - if (mqttPublishTask) - mqttPublishTask->disableProfiling(); - if (pzemTask) - pzemTask->disableProfiling(); + logger.setLevel(ARDUHAL_LOG_LEVEL_INFO); + esp_log_level_set("*", static_cast(ARDUHAL_LOG_LEVEL_INFO)); } - - // Log execution time for some "ONCE" tasks - dashboardInitTask.setCallback(debug ? LOG_EXEC_TIME : nullptr); - if (ds18Task) - ds18Task->setCallback(debug ? LOG_EXEC_TIME : nullptr); - if (haDiscoveryTask) - haDiscoveryTask->setCallback(debug ? LOG_EXEC_TIME : nullptr); - if (mqttPublishConfigTask) - mqttPublishConfigTask->setCallback(debug ? LOG_EXEC_TIME : nullptr); - if (mqttPublishStaticTask) - mqttPublishStaticTask->setCallback(debug ? LOG_EXEC_TIME : nullptr); - if (mqttPublishTask) - mqttPublishTask->setCallback(debug ? LOG_EXEC_TIME : nullptr); - networkStartTask.setCallback(debug ? LOG_EXEC_TIME : nullptr); - safeBootTask.setCallback(debug ? LOG_EXEC_TIME : nullptr); - loggingTask.setCallback(debug ? LOG_EXEC_TIME : nullptr); - if (pzemO1PairingTask) - pzemO1PairingTask->setCallback(debug ? LOG_EXEC_TIME : nullptr); - if (pzemO2PairingTask) - pzemO2PairingTask->setCallback(debug ? LOG_EXEC_TIME : nullptr); - relayTask.setCallback(debug ? LOG_EXEC_TIME : nullptr); } diff --git a/src/yasolr_mqtt.cpp b/src/yasolr_mqtt.cpp index 0395dfee..816accde 100644 --- a/src/yasolr_mqtt.cpp +++ b/src/yasolr_mqtt.cpp @@ -2,7 +2,7 @@ /* * Copyright (C) 2023-2024 Mathieu Carbou */ -#include +#include #include @@ -429,5 +429,13 @@ void yasolr_init_mqtt() { mqttPublishTask->setManager(unsafeTaskManager); Mycila::TaskMonitor.addTask("mqtt_task"); // MQTT (set stack size with MYCILA_MQTT_STACK_SIZE) + + if (config.getBool(KEY_ENABLE_DEBUG)) { + haDiscoveryTask->enableProfiling(10, Mycila::TaskTimeUnit::MILLISECONDS); + mqttConnectTask->enableProfiling(10, Mycila::TaskTimeUnit::MILLISECONDS); + mqttPublishConfigTask->enableProfiling(10, Mycila::TaskTimeUnit::MILLISECONDS); + mqttPublishStaticTask->enableProfiling(10, Mycila::TaskTimeUnit::MILLISECONDS); + mqttPublishTask->enableProfiling(10, Mycila::TaskTimeUnit::MILLISECONDS); + } } } diff --git a/src/yasolr_network.cpp b/src/yasolr_network.cpp index 81618901..7bcf813a 100644 --- a/src/yasolr_network.cpp +++ b/src/yasolr_network.cpp @@ -2,7 +2,7 @@ /* * Copyright (C) 2023-2024 Mathieu Carbou */ -#include +#include Mycila::Task networkManagerTask("ESPConnect", [](void* params) { espConnect.loop(); }); @@ -106,6 +106,8 @@ void yasolr_init_network() { }); networkStartTask.setManager(coreTaskManager); + if (config.getBool(KEY_ENABLE_DEBUG)) + networkStartTask.enableProfiling(10, Mycila::TaskTimeUnit::MILLISECONDS); networkManagerTask.setInterval(200 * Mycila::TaskDuration::MILLISECONDS); networkManagerTask.setManager(coreTaskManager); diff --git a/src/yasolr_pzem.cpp b/src/yasolr_pzem.cpp index 8e1ddc3f..9f637ffb 100644 --- a/src/yasolr_pzem.cpp +++ b/src/yasolr_pzem.cpp @@ -2,7 +2,7 @@ /* * Copyright (C) 2023-2024 Mathieu Carbou */ -#include +#include Mycila::PZEM* pzemO1; Mycila::PZEM* pzemO2; @@ -80,6 +80,8 @@ void yasolr_init_pzem() { } }); pzemO1PairingTask->setManager(unsafeTaskManager); + if (config.getBool(KEY_ENABLE_DEBUG)) + pzemO1PairingTask->enableProfiling(10, Mycila::TaskTimeUnit::MILLISECONDS); } else { logger.error(TAG, "Failed to initialize PZEM for Output 1!"); @@ -151,6 +153,8 @@ void yasolr_init_pzem() { } }); pzemO2PairingTask->setManager(unsafeTaskManager); + if (config.getBool(KEY_ENABLE_DEBUG)) + pzemO2PairingTask->enableProfiling(10, Mycila::TaskTimeUnit::MILLISECONDS); } else { logger.error(TAG, "Failed to initialize PZEM for Output 2!"); @@ -159,6 +163,7 @@ void yasolr_init_pzem() { if (count) { pzemTaskManager = new Mycila::TaskManager("y-pzem"); + pzemTask = new Mycila::Task("PZEM", [](void* params) { if (pzemO1) { pzemO1->read(); @@ -171,7 +176,11 @@ void yasolr_init_pzem() { }); pzemTask->setEnabledWhen([]() { return (!pzemO1PairingTask || pzemO1PairingTask->isPaused()) && (!pzemO2PairingTask || pzemO2PairingTask->isPaused()); }); pzemTask->setManager(*pzemTaskManager); + if (config.getBool(KEY_ENABLE_DEBUG)) + pzemTask->enableProfiling(10, Mycila::TaskTimeUnit::MILLISECONDS); + assert(pzemTaskManager->asyncStart(512 * 4, 5, 0, 100, true)); + Mycila::TaskMonitor.addTask(pzemTaskManager->getName()); } } diff --git a/src/yasolr_system.cpp b/src/yasolr_system.cpp index 1acfdc63..996387ca 100644 --- a/src/yasolr_system.cpp +++ b/src/yasolr_system.cpp @@ -2,7 +2,7 @@ /* * Copyright (C) 2023-2024 Mathieu Carbou */ -#include +#include Mycila::TaskManager coreTaskManager("y-core"); Mycila::TaskManager unsafeTaskManager("y-unsafe"); diff --git a/src/yasolr_trial.cpp b/src/yasolr_trial.cpp index 065eebc2..28739e53 100644 --- a/src/yasolr_trial.cpp +++ b/src/yasolr_trial.cpp @@ -2,7 +2,7 @@ /* * Copyright (C) 2023-2024 Mathieu Carbou */ -#include +#include #ifdef APP_MODEL_TRIAL Mycila::Task* trialTask; diff --git a/src/yasolr_web_server.cpp b/src/yasolr_web_server.cpp index ab0aa318..525353d0 100644 --- a/src/yasolr_web_server.cpp +++ b/src/yasolr_web_server.cpp @@ -2,8 +2,8 @@ /* * Copyright (C) 2023-2024 Mathieu Carbou */ -#include -#include +#include +#include #include #include @@ -500,15 +500,16 @@ void yasolr_init_web_server() { // Middleware - loggingMiddleware.setOutput(Serial); + if (config.getBool(KEY_ENABLE_DEBUG)) { + loggingMiddleware.setOutput(Serial); + webServer.addMiddleware(&loggingMiddleware); + } authMiddleware.setAuthType(AsyncAuthType::AUTH_DIGEST); authMiddleware.setRealm("YaSolR"); authMiddleware.setUsername(YASOLR_ADMIN_USERNAME); authMiddleware.setPassword(config.get(KEY_ADMIN_PASSWORD)); authMiddleware.generateHash(); - - webServer.addMiddleware(&loggingMiddleware); webServer.addMiddleware(&authMiddleware); rewrites(); @@ -540,6 +541,11 @@ void yasolr_init_web_server() { dashboardUpdateTask.setInterval(1 * Mycila::TaskDuration::SECONDS); dashboardUpdateTask.setManager(coreTaskManager); + if (config.getBool(KEY_ENABLE_DEBUG)) { + dashboardUpdateTask.enableProfiling(10, Mycila::TaskTimeUnit::MILLISECONDS); + dashboardInitTask.enableProfiling(10, Mycila::TaskTimeUnit::MILLISECONDS); + } + // Task Monitor Mycila::TaskMonitor.addTask("async_tcp"); // AsyncTCP (set stack size with CONFIG_ASYNC_TCP_STACK_SIZE) diff --git a/src/yasolr_zcd.cpp b/src/yasolr_zcd.cpp index 3cb012e0..7c3390be 100644 --- a/src/yasolr_zcd.cpp +++ b/src/yasolr_zcd.cpp @@ -2,7 +2,7 @@ /* * Copyright (C) 2023-2024 Mathieu Carbou */ -#include +#include #include