Core Mqtt Agent API callbacks


I’m working in an IoT project where I’m trying to use the MQTT Agent library for the first time. I’ve got some user app tasks running in a main thread and the MqttAgent running in another thread.

Reading the library functions I can see that the user App can use the thread safe API functions to publish, subscribe,… passing a callback function in the command info arguments.

So if I got it right, these callback functions will be called from the MQTT_Agent thread when the publish/subscribe command is completed, which means that are being executed from the Agent’s thread and will have the Agent’s task priority?

If I want to pass the data from the responses to the main user app (which is in different thread) should I use a queue from the callback to the user app main tasks or is there any better/smarter way do handle this?

My concern is that if I want for instance to execute a blocking piece of code in one of the callbacks that would prevent the MQTT Agent from handle its other commands. So should I treat the callbacks like a sort of ISR running only non blocking code?

Diego B

Yes, that is correct.

That is one way. You can also copy to a buffer (which can be dynamically allocated or you can maintain a static pool of buffer) and pass the pointer to that buffer using queue.



Hi Aggarg,

Thanks very much for clarifying that, it makes a lot of sense now.