Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

CTBot ESP32 && Task watchdog #128

Open
bosoft-ESP opened this issue Nov 24, 2024 · 4 comments
Open

CTBot ESP32 && Task watchdog #128

bosoft-ESP opened this issue Nov 24, 2024 · 4 comments

Comments

@bosoft-ESP
Copy link

Hi, I've been trying for a few months to get a 2 core esp32 to not run Task watchdog.
The code has 2 tasks:
task1 in loop core 1: reads 2 pins and handles a flash led with millis().
task2 in Task_2 core 0: only reads and sends Telegram messages. Read is checked every 40 seconds and send is usually every 15 to 20 hours.

The ESP32 is reset from time to time with this information:

E (12865821) task_wdt: Task watchdog got triggered. The following tasks/users did not reset the watchdog in time:
E (12865821) task_wdt: - IDLE0 (CPU 0)
E (12865821) task_wdt: Tasks currently running:
E (12865821) task_wdt: CPU 0: Task_2
E (12865821) task_wdt: CPU 1: loopTask
E (12865821) task_wdt: Aborting.
E (12865821) task_wdt: Print CPU 0 (current core) backtrace	
Rebooting...

After several tests, I think I found the solution: Add in the CTBotSecureConnection.cpp file a vTaskDelay( pdMS_TO_TICKS( 7 ) ) only for ESP32. I only tried 7 and it worked. Other values might work better or worse.

	while (telegramServer.connected()) {
		#if defined ARDUINO_ARCH_ESP32
		vTaskDelay( pdMS_TO_TICKS( 7 ) ) ); <------
		#endif
		while (telegramServer.available()) {
			c = telegramServer.read();
			response += (char)c;
			if (c == ‘\’) {
				// escape character -> read next and skip
				c = telegramServer.read();
				response += (char)c;
				continue;
			}

Regards

@shurillu
Copy link
Owner

Hello bosoft-ESP,
adding delays in any form inside a library is not a good way to solve the problem, becasuse you slow down the entire process: if you will need a faster execution you can`t (but your software could be!).
I'm not very skilled in multitasking, but seems that the watchdog is triggered because the CPU 0 (so the Task_2) is doing nothing for the watchdog waiting time.
A better solution is to feed the watchdog so the timeout doesn't last: take a look here, maybe you can find a better solution!
From your snippet, it seems that you are using the CTBot library version v2.1.14. Could you try the v3.0.0? You can download that version from here.
Please let me know it you will find a better solution.

Regards,

Stefano

@bosoft-ESP
Copy link
Author

Thank you, Stefano, for your reply.
As I said in the first post, I've been trying for several months to stop the watchdog from popping up.
I had seen those solutions, but they didn't work for me. In the long run watchdog jumps (2 or 3 days) and some functions are no longer in the ESP32 library.
My solution simply gives the watchdog a 7 tick timeout (I'll try lowering it), too little to slow down the CTBot, but too much time to reset the watchdog to 0.
Of course, there is also a vTaskDelay in the for(;;) that keeps the task_2 infinite.
So far this solution is working for several days without skipping the watchdog.
No, I haven't tested version 3, I have it on the agenda.

Regards

@bosoft-ESP
Copy link
Author

Hello.
After testing CTBot 3, I had watchdog resets again after a few hours.
2 days ago I switched back to 2.14 and since then there are no resets.
Also, to test, I have reduced the ms in CTBotSecureConnection.cpp to 5: vTaskDelay( pdMS_TO_TICKS(5) ) ); and it seems to be working fine. I'll keep it in testing for 5 or 6 more days to make sure.

Regards

@bosoft-ESP
Copy link
Author

Hello
After many days without problems, I asked Copilot how to disable watchdog. The suggested solution is:
`#include "esp_task_wdt.h"
TaskHandle_t Task2;

void setup(){
esp_task_wdt_deinit(); //<--must be at the beginning of the setup
.
.
.
xTaskCreatePinnedToCore(loop2,"Task_2",9216,NULL,1,&Task2,0); // and this as last as possible
}

void loop() {
.
.
.
}

void loop2(void *parameter){
for(;;){
.
.
.
vTaskDelay(pdMS_TO_TICKS(50));
}
}`

But as I had been without watchdog for quite a few days using vTaskDelay, I have left vTaskDelay just in case and, in addition, implemented Copilot's solution.
At the moment the system has been faultless for 12 days.

Regards

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants