Page 1 of 1

ESP32 PubSubClient

Posted: Wed Sep 04, 2024 6:23 pm
by gomez9656
Hello there Espressif team!

I'm currently running a FreeRTOS application on ESP32. All the tasks are event-driven with the same priority.

I'm using the library PubSubClient to connect to AWS but I'm having a problem with the client.connect() function.

The AWS task inits the certificates and so on. At the end, it calls client.connect(). The problem is that this is a blocking function that is triggering the watchdog timer.

This is the error log:

Code: Select all

E (12868) task_wdt: Task watchdog got triggered. The following tasks did not reset the watchdog in time:
E (12868) task_wdt:  - IDLE (CPU 0)
E (12868) task_wdt: Tasks currently running:
E (12868) task_wdt: CPU 0: awsTask
E (12868) task_wdt: CPU 1: loopTask
E (12868) task_wdt: Aborting
This problem is solved by pinning the AWS task to CPU 1, but I would like to keep all related wifi stuff in CPU 0 and CPU 1 for all the other tasks.

Is there any way to reset the watchdog timer even though this is a blocking function?

Thanks a lot in advance

Re: ESP32 PubSubClient

Posted: Wed Sep 04, 2024 7:06 pm
by lbernstone
You can increase the timeout of the watchdog timer before you connect and then set it back to 5 seconds when you are done.
If you are comfortable with freeRTOS/esp-idf/C, I'd suggest you take a look at the esp-mqtt library, which is a fully functional mqtt client (including all QoS and mqttv5). It is likely to be much faster than the layers upon layers of abstraction in PubSubClient. It allows async messaging.

Re: ESP32 PubSubClient

Posted: Wed Sep 04, 2024 9:49 pm
by gomez9656
Thanks for the quick reply.

Can you write ESP-IDF alongside the Arduino framework? I understand you can only choose one.

Re: ESP32 PubSubClient

Posted: Thu Sep 05, 2024 5:26 am
by lbernstone
arduino-esp32 is a HAL built on top of the esp-idf. About 97% of the framework's functionality is available in Arduino. Some of the examples may need massaging if you want to use them in C++, but the code should all work.