coreMQTT Agent v1.1.0
Thread safe MQTT 3.1.1 Client
MQTTAgent_Init

Perform any initialization the MQTT agent requires before it can be used. Must be called before any other function.

const MQTTAgentMessageInterface_t * pMsgInterface,
const MQTTFixedBuffer_t * pNetworkBuffer,
const TransportInterface_t * pTransportInterface,
MQTTGetCurrentTimeFunc_t getCurrentTimeMs,
void * pIncomingPacketContext );
MQTTStatus_t MQTTAgent_Init(MQTTAgentContext_t *pMqttAgentContext, const MQTTAgentMessageInterface_t *pMsgInterface, const MQTTFixedBuffer_t *pNetworkBuffer, const TransportInterface_t *pTransportInterface, MQTTGetCurrentTimeFunc_t getCurrentTimeMs, MQTTAgentIncomingPublishCallback_t incomingCallback, void *pIncomingPacketContext)
Perform any initialization the MQTT agent requires before it can be used. Must be called before any o...
Definition: core_mqtt_agent.c:946
void(* MQTTAgentIncomingPublishCallback_t)(struct MQTTAgentContext *pMqttAgentContext, uint16_t packetId, MQTTPublishInfo_t *pPublishInfo)
Callback function called when receiving a publish.
Definition: core_mqtt_agent.h:174
uint32_t(* MQTTGetCurrentTimeFunc_t)(void)
MQTTStatus_t
Information used by each MQTT agent. A context will be initialized by MQTTAgent_Init(),...
Definition: core_mqtt_agent.h:185
Function pointers and contexts used for sending and receiving commands, and allocating memory for the...
Definition: core_mqtt_agent_message_interface.h:133
Parameters
[in]pMqttAgentContextPointer to struct to initialize.
[in]pMsgInterfaceCommand interface to use for allocating and sending commands.
[in]pNetworkBufferPointer to network buffer to use.
[in]pTransportInterfaceTransport interface to use with the MQTT library. See https://www.freertos.org/network-interface.html
[in]getCurrentTimeMsPointer to a function that returns a count value that increments every millisecond.
[in]incomingCallbackThe callback to execute when receiving publishes.
[in]pIncomingPacketContextA pointer to a context structure defined by the application writer.
Note
The pIncomingPacketContext context provided for the incoming publish callback MUST remain in scope throughout the period that the agent task is running.
Returns
Appropriate status code from MQTT_Init().

Example

// Function for obtaining a timestamp.
uint32_t getTimeStampMs();
// Callback function for receiving packets.
void incomingPublishCallback( MQTTAgentContext_t * pMqttAgentContext,
uint16_t packetId,
MQTTPublishInfo_t * pPublishInfo );
// Platform function for network send interface.
int32_t networkSend( NetworkContext_t * pContext, const void * pBuffer, size_t bytes );
// Platform for network receive interface.
int32_t networkRecv( NetworkContext_t * pContext, void * pBuffer, size_t bytes );
// Platform function for Agent Message Send.
bool agentSendMessage( MQTTAgentMessageContext_t * pMsgCtx,
MQTTAgentCommand_t * const * pCommandToSend,
uint32_t blockTimeMs );
// Platform function for Agent Message Receive.
bool agentReceiveMessage( MQTTAgentMessageContext_t * pMsgCtx,
MQTTAgentCommand_t ** pCommandToSend,
uint32_t blockTimeMs );
// Platform function to Get Agent Command.
MQTTAgentCommand_t * getCommand( uint32_t blockTimeMs );
// Platform function to Release Agent Command.
bool releaseCommand( MQTTAgentCommand_t * pCommandToRelease );
// Variables used in this example.
MQTTAgentMessageInterface_t messageInterface;
MQTTAgentContext_t agentContext;
// Buffer for storing outgoing and incoming MQTT packets.
MQTTFixedBuffer_t fixedBuffer;
uint8_t buffer[ 1024 ];
MQTTStatus_t status;
// Set transport interface members.
transport.pNetworkContext = &someTransportContext;
transport.send = networkSend;
transport.recv = networkRecv;
// Set agent message interface members.
messageInterface.pMsgCtx = &messageContext;
messageInterface.send = agentSendMessage;
messageInterface.recv = agentReceiveMessage;
messageInterface.getCommand = getCommand;
messageInterface.releaseCommand = releaseCommand;
// Set buffer members.
fixedBuffer.pBuffer = buffer;
fixedBuffer.size = 1024;
status = MQTTAgent_Init( &agentContext,
&messageInterface,
&networkBuffer,
&transportInterface,
stubGetTime,
stubPublishCallback,
incomingPacketContext );
if( status == MQTTSuccess )
{
// Do something with agentContext. The transport and message interfaces, and
// fixedBuffer structs were copied into the context, so the original structs
// do not need to stay in scope.
}
struct MQTTAgentMessageContext MQTTAgentMessageContext_t
Context with which tasks may deliver messages to the agent.
Definition: core_mqtt_agent_message_interface.h:54
MQTTSuccess
struct NetworkContext NetworkContext_t
MQTTAgentMessageContext_t * pMsgCtx
Definition: core_mqtt_agent_message_interface.h:134
MQTTAgentMessageRecv_t recv
Definition: core_mqtt_agent_message_interface.h:136
MQTTAgentCommandGet_t getCommand
Definition: core_mqtt_agent_message_interface.h:137
MQTTAgentMessageSend_t send
Definition: core_mqtt_agent_message_interface.h:135
MQTTAgentCommandRelease_t releaseCommand
Definition: core_mqtt_agent_message_interface.h:138
TransportSend_t send
TransportRecv_t recv
NetworkContext_t * pNetworkContext