ESP32 PubSubClient

gomez9656
Posts: 21
Joined: Mon Mar 14, 2022 7:48 pm

ESP32 PubSubClient

Postby gomez9656 » Wed Sep 04, 2024 6:23 pm

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

lbernstone
Posts: 828
Joined: Mon Jul 22, 2019 3:20 pm

Re: ESP32 PubSubClient

Postby lbernstone » Wed Sep 04, 2024 7:06 pm

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.

gomez9656
Posts: 21
Joined: Mon Mar 14, 2022 7:48 pm

Re: ESP32 PubSubClient

Postby gomez9656 » Wed Sep 04, 2024 9:49 pm

Thanks for the quick reply.

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

lbernstone
Posts: 828
Joined: Mon Jul 22, 2019 3:20 pm

Re: ESP32 PubSubClient

Postby lbernstone » Thu Sep 05, 2024 5:26 am

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.

Who is online

Users browsing this forum: No registered users and 137 guests