Perform any initialization the MQTT agent requires before it can be used. Must be called before any other function.
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:974
void(* MQTTAgentIncomingPublishCallback_t)(struct MQTTAgentContext *pMqttAgentContext, uint16_t packetId, MQTTPublishInfo_t *pPublishInfo)
Callback function called when receiving a publish.
Definition: core_mqtt_agent.h:142
uint32_t(* MQTTGetCurrentTimeFunc_t)(void)
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
- Parameters
-
[in] | pMqttAgentContext | Pointer to struct to initialize. |
[in] | pMsgInterface | Command interface to use for allocating and sending commands. |
[in] | pNetworkBuffer | Pointer to network buffer to use. |
[in] | pTransportInterface | Transport interface to use with the MQTT library. See https://www.freertos.org/network-interface.html |
[in] | getCurrentTimeMs | Pointer to a function that returns a count value that increments every millisecond. |
[in] | incomingCallback | The callback to execute when receiving publishes. |
[in] | pIncomingPacketContext | A 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
uint32_t getTimeStampMs();
uint16_t packetId,
int32_t networkSend(
NetworkContext_t * pContext,
const void * pBuffer,
size_t bytes );
int32_t networkRecv(
NetworkContext_t * pContext,
void * pBuffer,
size_t bytes );
MQTTAgentCommand_t * const * pCommandToSend,
uint32_t blockTimeMs );
MQTTAgentCommand_t ** pCommandToSend,
uint32_t blockTimeMs );
MQTTAgentCommand_t * getCommand( uint32_t blockTimeMs );
bool releaseCommand( MQTTAgentCommand_t * pCommandToRelease );
uint8_t buffer[ 1024 ];
transport.
send = networkSend;
transport.
recv = networkRecv;
messageInterface.
pMsgCtx = &messageContext;
messageInterface.
send = agentSendMessage;
messageInterface.
recv = agentReceiveMessage;
&messageInterface,
&networkBuffer,
&transportInterface,
stubGetTime,
stubPublishCallback,
incomingPacketContext );
{
}
struct MQTTAgentMessageContext MQTTAgentMessageContext_t
Context with which tasks may deliver messages to the agent.
Definition: core_mqtt_agent_message_interface.h:54
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
NetworkContext_t * pNetworkContext