No, that is not correct. MQTT Agent APIs are thread safe and can be called from multiple threads. So you can have 2 threads both of which share the same
- MQTT Thread - Subscribes and publishes messages using MQTT Agent APIs (MQTTAgent_Subscribe and MQTTAgent_Publish).
- Shadow Thread - Subscribes and publishes shadow messages using MQTT Agent APIs (MQTTAgent_Subscribe and MQTTAgent_Publish).
You can share the
MQTTContextHandle_t by defining it in a common header file. Lets say you have a file
app_config.h which contains all the configurations for your application. You define the following in this file:
#define appMQTT_CONTEXT_HANDLE ( ( MQTTContextHandle_t ) 0 )
The updated implementation of
xSubscribeToTopic should look something like:
BaseType_t xSubscribeToTopic( MQTTContextHandle_t mqttContextHandle,
const char * pcTopicFilter,
uint16_t usTopicFilterLength ) <-- May need additional callbacks too.
/* Call MQTTAgent_Subscribe. */
The application should call
xSubscribeToTopic like the following:
xSubscribeToTopic( appMQTT_CONTEXT_HANDLE, "/example/topic", sizeof( "/example/topic" ) - 1 );