espressif / esp-idf

Espressif IoT Development Framework. Official development framework for Espressif SoCs.
Apache License 2.0
13.05k stars 7.13k forks source link

Add timeout for MQTT APis (like publish and subscribe) (IDFGH-6771) #8399

Open GioTB opened 2 years ago

GioTB commented 2 years ago

Is your feature request related to a problem? Please describe.

No

Describe the solution you'd like

Add timeout for users API like publish so if the requesting task coulnd´t be waiting "for ever" (portMAX_DELAY).

Describe alternatives you've considered

A simple alternative it´s to add the parameter "timeout" (in mS) to the publish and subscribe APIs and so it can me put on the "MQTT_API_LOCK" Macro (or changed to function) , so it will only block for that time (obvisouly it should implement an "if" statement to continue the process):

define MQTT_API_LOCK(c, timeout) xSemaphoreTakeRecursive(c->api_lock, (pdMS_TO_TICKS(timeout)))

int esp_mqtt_client_publish(esp_mqtt_client_handle_t client, const char topic, const char data, int len, int qos, int retain, uint32_t timeout) .... if(MQTT_API_LOCK(client, timeout) == pdTrue) { ....

Another, or better said complementary idea it´s to make a queue so every publish or subscribe request goes directly (or alternatively in case the timeouts occurs) to the queue and the MQTT task handles the actual publish

Please give as many details as you can. Include suggestions for useful APIs or interfaces if relevant.

I think it could be usefull for all the APIs that could block the users code, like publish, subscribe, start, stop, etc

Add any other context or screenshots about the feature request here.

euripedesrocha commented 2 years ago

Hi, thank you for your suggestion.

We'll add this feature in our roadmap.