coreMQTT Agent v2.0.0
Thread safe MQTT 3.1.1 Client
Loading...
Searching...
No Matches
MQTTAgent_Init
MQTTStatus_t MQTTAgent_Init( MQTTAgentContext_t * pMqttAgentContext,
const MQTTAgentMessageInterface_t * pMsgInterface,
const MQTTFixedBuffer_t * pNetworkBuffer,
const TransportInterface_t * pTransportInterface,
MQTTGetCurrentTimeFunc_t getCurrentTimeMs,
void * pIncomingPacketContext,
uint8_t * pAckPropsBuffer,
size_t ackPropsBufferSize );

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

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/Documentation/03-Libraries/03-FreeRTOS-core/06-Transport-Interface/01-Transport-interface
[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.
[in]pAckPropsBufferBuffer for storing ACK properties in QoS > 0 flows.
[in]ackPropsBufferSizeSize of the ACK properties buffer.
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;
TransportInterface_t transport;
// 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.
}
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, uint8_t *pAckPropsBuffer, size_t ackPropsBufferSize)
Perform any initialization the MQTT agent requires before it can be used. Must be called before any o...
Definition core_mqtt_agent.c:967
struct MQTTAgentMessageContext MQTTAgentMessageContext_t
Context with which tasks may deliver messages to the agent.
Definition core_mqtt_agent_message_interface.h:54
Information used by each MQTT agent. A context will be initialized by MQTTAgent_Init(),...
Definition core_mqtt_agent.h:153
Function pointers and contexts used for sending and receiving commands, and allocating memory for the...
Definition core_mqtt_agent_message_interface.h:133
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