From 0a0e7fe9015aefceccb74c4eb81fae3c3218b648 Mon Sep 17 00:00:00 2001 From: mooiweertje Date: Wed, 17 Dec 2025 18:26:29 +0100 Subject: [PATCH 1/2] heartBeat --- main/Kconfig.projbuild | 4 ++++ main/main.cpp | 13 ++++++++++--- sdkconfig.supermini | 3 +++ 3 files changed, 17 insertions(+), 3 deletions(-) diff --git a/main/Kconfig.projbuild b/main/Kconfig.projbuild index 085e674..e7b4f6c 100644 --- a/main/Kconfig.projbuild +++ b/main/Kconfig.projbuild @@ -87,4 +87,8 @@ menu "Sparta Ion Config" int "The actual battery voltage in mv for full (=100%). For example 42000mv for a 10s battery" default 42000 + config CONFIG_ION_KEEPALIVE + bool "Enable keepalive heartbeat. Will reset the ESP32 when main loop is stuck for more than a minute." + default n + endmenu diff --git a/main/main.cpp b/main/main.cpp index e6643a2..20848a5 100644 --- a/main/main.cpp +++ b/main/main.cpp @@ -64,8 +64,6 @@ static const int MEASURE_BAT_BIT = BIT7; static EventGroupHandle_t controlEventGroup; -volatile bool myTaskAlive = false; - enum messageHandlingResult { // We got a handoff back, so we get to send the next message CONTROL_TO_US, @@ -76,16 +74,21 @@ enum messageHandlingResult { }; static TimerHandle_t measureBatTimer; -TimerHandle_t healthCheckTimer ; static void measureBatTimerCallback(TimerHandle_t xTimer) { xEventGroupSetBits(controlEventGroup, MEASURE_BAT_BIT); } +#if CONFIG_ION_KEEPALIVE +volatile bool myTaskAlive = false; +TimerHandle_t healthCheckTimer ; + static void checkMyTaskHealth(TimerHandle_t xTimer) { if (!myTaskAlive) { esp_restart(); } myTaskAlive = false; // Reset voor volgende check } +#endif + static messageHandlingResult handleMotorMessage(ion_state * state) { messageType message = {}; @@ -261,8 +264,10 @@ static void my_task(void *pvParameter) { measureBatTimer = xTimerCreate("measureBatTimer", (100 / portTICK_PERIOD_MS), pdTRUE, (void *)0, measureBatTimerCallback); xTimerStart(measureBatTimer, 0); +#if CONFIG_ION_KEEPALIVE healthCheckTimer = xTimerCreate("healthCheckTimer", 60000 / portTICK_PERIOD_MS, pdTRUE, NULL, checkMyTaskHealth); xTimerStart(healthCheckTimer, 0); +#endif ion_state state = { .state = IDLE, @@ -278,7 +283,9 @@ static void my_task(void *pvParameter) { while(true) { +#if CONFIG_ION_KEEPALIVE myTaskAlive = true; // sign of life +#endif // TODO: // More use of timeouts diff --git a/sdkconfig.supermini b/sdkconfig.supermini index 7b1ba63..249563c 100644 --- a/sdkconfig.supermini +++ b/sdkconfig.supermini @@ -42,3 +42,6 @@ CONFIG_ION_ADC_EMPTY_MV=18000 # Consider 25.2V (4.2V/cell for 6s) full CONFIG_ION_ADC_FULL_MV=25200 + +# keepalive +CONFIG_ION_KEEPALIVE=y From e8ac218d957679ff0a16b267b3bf5c9965141bd4 Mon Sep 17 00:00:00 2001 From: mooiweertje Date: Tue, 23 Dec 2025 13:20:31 +0100 Subject: [PATCH 2/2] heartBeat --- main/Kconfig.projbuild | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/main/Kconfig.projbuild b/main/Kconfig.projbuild index e7b4f6c..b942e2e 100644 --- a/main/Kconfig.projbuild +++ b/main/Kconfig.projbuild @@ -87,7 +87,7 @@ menu "Sparta Ion Config" int "The actual battery voltage in mv for full (=100%). For example 42000mv for a 10s battery" default 42000 - config CONFIG_ION_KEEPALIVE + config ION_KEEPALIVE bool "Enable keepalive heartbeat. Will reset the ESP32 when main loop is stuck for more than a minute." default n