coreMQTT Agent v1.1.0
Thread safe MQTT 3.1.1 Client

Add a command to call MQTT_Subscribe() for an MQTT connection.

MQTTAgentSubscribeArgs_t * pSubscriptionArgs,
const MQTTAgentCommandInfo_t * pCommandInfo );
MQTTStatus_t MQTTAgent_Subscribe(const MQTTAgentContext_t *pMqttAgentContext, MQTTAgentSubscribeArgs_t *pSubscriptionArgs, const MQTTAgentCommandInfo_t *pCommandInfo)
Add a command to call MQTT_Subscribe() for an MQTT connection.
Definition: core_mqtt_agent.c:1130
Struct holding arguments that are common to every command.
Definition: core_mqtt_agent.h:221
Information used by each MQTT agent. A context will be initialized by MQTTAgent_Init(),...
Definition: core_mqtt_agent.h:185
Struct holding arguments for a SUBSCRIBE or UNSUBSCRIBE call.
Definition: core_mqtt_agent.h:199
[in]pMqttAgentContextThe MQTT agent to use.
[in]pSubscriptionArgsStruct describing topic to subscribe to.
[in]pCommandInfoThe information pertaining to the command, including:
  • cmdCompleteCallback Optional callback to invoke when the command completes.
  • pCmdCompleteCallbackContext Optional completion callback context.
  • blockTimeMs The maximum amount of time in milliseconds to wait for the command to be posted to the MQTT agent, should the agent's event queue be full. Tasks wait in the Blocked state so don't use any CPU time.
The context passed to the callback through pCmdContext member of pCommandInfo parameter MUST remain in scope at least until the callback has been executed by the agent task.
MQTTSuccess if the command was posted to the MQTT agent's event queue. Otherwise an enumerated error code.


// Variables used in this example.
MQTTAgentContext_t agentContext;
MQTTStatus_t status;
MQTTAgentCommandInfo_t commandInfo = { 0 };
MQTTSubscribeInfo_t subscribeInfo = { 0 };
MQTTAgentSubscribeArgs_t subscribeArgs = { 0 };
// Function for command complete callback.
void subscribeCmdCompleteCb( MQTTAgentCommandContext_t * pCmdCallbackContext,
MQTTAgentReturnInfo_t * pReturnInfo );
// Fill the command information.
commandInfo.CmdCompleteCallback = subscribeCmdCompleteCb;
commandInfo.blockTimeMs = 500;
// Fill the information for topic filters to subscribe to.
subscribeInfo.qos = Qos1;
subscribeInfo.pTopicFilter = "/foo/bar";
subscribeInfo.topicFilterLength = strlen("/foo/bar");
subscribeArgs.pSubscribeInfo = &subscribeInfo;
subscribeArgs.numSubscriptions = 1U;
status = MQTTAgent_Subscribe( &agentContext, &subscribeArgs, &commandInfo );
if( status == MQTTSuccess )
// Command to send subscribe request to the server has been queued. Notification
// about completion of the subscribe operation will be notified to application
// through invocation of subscribeCmdCompleteCb().
struct MQTTAgentCommandContext MQTTAgentCommandContext_t
Struct containing context for a specific command.
Definition: core_mqtt_agent.h:115
uint32_t blockTimeMs
Maximum block time for enqueueing the command.
Definition: core_mqtt_agent.h:224
Struct holding return codes and outputs from a command.
Definition: core_mqtt_agent.h:103
MQTTSubscribeInfo_t * pSubscribeInfo
List of MQTT subscriptions.
Definition: core_mqtt_agent.h:200
size_t numSubscriptions
Number of elements in pSubscribeInfo.
Definition: core_mqtt_agent.h:201
uint16_t topicFilterLength
const char * pTopicFilter