coreMQTT Agent v2.0.0
Thread safe MQTT 3.1.1 Client
Loading...
Searching...
No Matches
MQTTAgent_Publish
MQTTStatus_t MQTTAgent_Publish( const MQTTAgentContext_t * pMqttAgentContext,
MQTTAgentPublishArgs_t * pPublishArgs,
const MQTTAgentCommandInfo_t * pCommandInfo );

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

Parameters
[in]pMqttAgentContextThe MQTT agent to use.
[in]pPublishArgsMQTT PUBLISH arguments including publish info and optional v5 properties.
[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.
Note
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.
Returns
#MQTTSuccess if the command was posted to the MQTT agent's event queue. Otherwise an enumerated error code.

Example

// Variables used in this example.
MQTTAgentContext_t agentContext;
MQTTStatus_t status;
MQTTAgentCommandInfo_t commandInfo = { 0 };
MQTTPublishInfo_t publishInfo = { 0 };
// Function for command complete callback.
void publishCmdCompleteCb( MQTTAgentCommandContext_t * pCmdCallbackContext,
MQTTAgentReturnInfo_t * pReturnInfo );
// Fill the command information.
commandInfo.cmdCompleteCallback = publishCmdCompleteCb;
commandInfo.blockTimeMs = 500;
// Fill the information for publish operation.
publishInfo.qos = MQTTQoS1;
publishInfo.pTopicName = "/some/topic/name";
publishInfo.topicNameLength = strlen( publishInfo.pTopicName );
publishInfo.pPayload = "Hello World!";
publishInfo.payloadLength = strlen( "Hello World!" );
status = MQTTAgent_Publish( &agentContext, &publishInfo, &commandInfo );
if( status == MQTTSuccess )
{
// Command to publish message to broker has been queued.
// The event of publish operation completion will be notified with
// the invocation of the publishCmdCompleteCb().
}
MQTTStatus_t MQTTAgent_Publish(const MQTTAgentContext_t *pMqttAgentContext, MQTTAgentPublishArgs_t *pPublishArgs, const MQTTAgentCommandInfo_t *pCommandInfo)
Add a command to call MQTT_Publish() for an MQTT connection.
Definition core_mqtt_agent.c:1218
struct MQTTAgentCommandContext MQTTAgentCommandContext_t
Struct containing context for a specific command.
Definition core_mqtt_agent.h:83
Struct holding arguments that are common to every command.
Definition core_mqtt_agent.h:214
MQTTAgentCommandCallback_t cmdCompleteCallback
Callback to invoke upon completion.
Definition core_mqtt_agent.h:215
uint32_t blockTimeMs
Maximum block time for enqueueing the command.
Definition core_mqtt_agent.h:217
Information used by each MQTT agent. A context will be initialized by MQTTAgent_Init(),...
Definition core_mqtt_agent.h:153
Struct holding return codes and outputs from a command.
Definition core_mqtt_agent.h:71