A RetroSearch Logo

Home - News ( United States | United Kingdom | Italy | Germany ) - Football scores

Search Query:

Showing content from https://freertos.github.io/coreMQTT-Agent/main/core__mqtt__agent_8h.html below:

coreMQTT Agent: core_mqtt_agent.h File Reference

Functions for running a coreMQTT client in a dedicated thread. More...

Go to the source code of this file.

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 other function.
  MQTTStatus_t  MQTTAgent_CommandLoop (MQTTAgentContext_t *pMqttAgentContext)   Process commands from the command queue in a loop.
  MQTTStatus_t  MQTTAgent_ResumeSession (MQTTAgentContext_t *pMqttAgentContext, bool sessionPresent)   Resume a session by resending publishes if a session is present in the broker, or clear state information if not.
  MQTTStatus_t  MQTTAgent_CancelAll (MQTTAgentContext_t *pMqttAgentContext)   Cancel all enqueued commands and those awaiting acknowledgment while the command loop is not running.
  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.
  MQTTStatus_t  MQTTAgent_Unsubscribe (const MQTTAgentContext_t *pMqttAgentContext, MQTTAgentSubscribeArgs_t *pSubscriptionArgs, const MQTTAgentCommandInfo_t *pCommandInfo)   Add a command to call MQTT_Unsubscribe() for an MQTT connection.
  MQTTStatus_t  MQTTAgent_Publish (const MQTTAgentContext_t *pMqttAgentContext, MQTTPublishInfo_t *pPublishInfo, const MQTTAgentCommandInfo_t *pCommandInfo)   Add a command to call MQTT_Publish() for an MQTT connection.
  MQTTStatus_t  MQTTAgent_ProcessLoop (const MQTTAgentContext_t *pMqttAgentContext, const MQTTAgentCommandInfo_t *pCommandInfo)   Send a message to the MQTT agent purely to trigger an iteration of its loop, which will result in a call to MQTT_ProcessLoop(). This function can be used to wake the MQTT agent task when it is known data may be available on the connected socket.
  MQTTStatus_t  MQTTAgent_Ping (const MQTTAgentContext_t *pMqttAgentContext, const MQTTAgentCommandInfo_t *pCommandInfo)   Add a command to call MQTT_Ping() for an MQTT connection.
  MQTTStatus_t  MQTTAgent_Connect (const MQTTAgentContext_t *pMqttAgentContext, MQTTAgentConnectArgs_t *pConnectArgs, const MQTTAgentCommandInfo_t *pCommandInfo)   Add a command to call MQTT_Connect() for an MQTT connection. If a session is resumed with the broker, it will also resend the necessary QoS1/2 publishes.
  MQTTStatus_t  MQTTAgent_Disconnect (const MQTTAgentContext_t *pMqttAgentContext, const MQTTAgentCommandInfo_t *pCommandInfo)   Add a command to disconnect an MQTT connection.
  MQTTStatus_t  MQTTAgent_Terminate (const MQTTAgentContext_t *pMqttAgentContext, const MQTTAgentCommandInfo_t *pCommandInfo)   Add a termination command to the command queue.
 

Functions for running a coreMQTT client in a dedicated thread.

◆ MQTTAgent_Init()

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

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/Documentation/03-Libraries/03-FreeRTOS-core/06-Transport-Interface/01-Transport-interface [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;

fixedBuffer.

size

= 1024;

&messageInterface,

&networkBuffer,

&transportInterface,

stubGetTime,

stubPublishCallback,

incomingPacketContext );

if( status == MQTTSuccess )

{

}

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:968

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

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

NetworkContext_t * pNetworkContext

Array used to maintain the outgoing publish records and their state by the coreMQTT library.

Array used to maintain the outgoing publish records and their state by the coreMQTT library.

◆ MQTTAgent_CommandLoop()

Process commands from the command queue in a loop.

Parameters
[in] pMqttAgentContext The MQTT agent to use.
Returns
appropriate error code, or MQTTSuccess from a successful disconnect or termination.

Example

{

}

else if( status == MQTTSuccess )

{

assert( status == MQTTSuccess );

}

else

{

}

MQTTStatus_t MQTT_Disconnect(MQTTContext_t *pContext)

MQTTStatus_t MQTTAgent_CommandLoop(MQTTAgentContext_t *pMqttAgentContext)

Process commands from the command queue in a loop.

Definition: core_mqtt_agent.c:1043

MQTTContext_t mqttContext

Definition: core_mqtt_agent.h:154

MQTTConnectionStatus_t connectStatus

TransportInterface_t transportInterface

◆ MQTTAgent_ResumeSession()

Resume a session by resending publishes if a session is present in the broker, or clear state information if not.

Parameters
[in] pMqttAgentContext The MQTT agent to use. [in] sessionPresent The session present flag from the broker.
Note
This function is NOT thread-safe and should only be called from the context of the task responsible for MQTTAgent_CommandLoop.
Returns
MQTTSuccess if it succeeds in resending publishes, else an appropriate error code from MQTT_Publish()

Example

bool sessionPresent;

if( status == MQTTSuccess )

{

}

MQTTStatus_t MQTT_Connect(MQTTContext_t *pContext, const MQTTConnectInfo_t *pConnectInfo, const MQTTPublishInfo_t *pWillInfo, uint32_t timeoutMs, bool *pSessionPresent)

MQTTStatus_t MQTTAgent_ResumeSession(MQTTAgentContext_t *pMqttAgentContext, bool sessionPresent)

Resume a session by resending publishes if a session is present in the broker, or clear state informa...

Definition: core_mqtt_agent.c:1085

◆ MQTTAgent_CancelAll()

Cancel all enqueued commands and those awaiting acknowledgment while the command loop is not running.

Canceled commands will be terminated with return code MQTTRecvFailed.

Parameters
[in] pMqttAgentContext The MQTT agent to use.
Note
This function is NOT thread-safe and should only be called from the context of the task responsible for MQTTAgent_CommandLoop.
Returns
MQTTBadParameter if an invalid context is given, else MQTTSuccess.

Example

if( status != MQTTSuccess )

{

}

MQTTStatus_t MQTTAgent_CancelAll(MQTTAgentContext_t *pMqttAgentContext)

Cancel all enqueued commands and those awaiting acknowledgment while the command loop is not running.

Definition: core_mqtt_agent.c:1128

◆ MQTTAgent_Subscribe()

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

Parameters
[in] pMqttAgentContext The MQTT agent to use. [in] pSubscriptionArgs Struct describing topic to subscribe to. [in] pCommandInfo The information pertaining to the command, including:
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

commandInfo.CmdCompleteCallback = subscribeCmdCompleteCb;

subscribeInfo.

qos

= Qos1;

if( status == MQTTSuccess )

{

}

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:1177

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:189

uint32_t blockTimeMs

Maximum block time for enqueueing the command.

Definition: core_mqtt_agent.h:192

Struct holding return codes and outputs from a command.

Definition: core_mqtt_agent.h:71

Struct holding arguments for a SUBSCRIBE or UNSUBSCRIBE call.

Definition: core_mqtt_agent.h:167

MQTTSubscribeInfo_t * pSubscribeInfo

List of MQTT subscriptions.

Definition: core_mqtt_agent.h:168

size_t numSubscriptions

Number of elements in pSubscribeInfo.

Definition: core_mqtt_agent.h:169

uint16_t topicFilterLength

const char * pTopicFilter

◆ MQTTAgent_Unsubscribe()

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

Parameters
[in] pMqttAgentContext The MQTT agent to use. [in] pSubscriptionArgs List of topics to unsubscribe from. [in] pCommandInfo The information pertaining to the command, including:
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

if( status == MQTTSuccess )

{

}

MQTTStatus_t MQTTAgent_Unsubscribe(const MQTTAgentContext_t *pMqttAgentContext, MQTTAgentSubscribeArgs_t *pSubscriptionArgs, const MQTTAgentCommandInfo_t *pCommandInfo)

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

Definition: core_mqtt_agent.c:1202

MQTTAgentCommandCallback_t cmdCompleteCallback

Callback to invoke upon completion.

Definition: core_mqtt_agent.h:190

◆ MQTTAgent_Publish()

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

Parameters
[in] pMqttAgentContext The MQTT agent to use. [in] pPublishInfo MQTT PUBLISH information. [in] pCommandInfo The information pertaining to the command, including:
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

publishInfo.

pPayload

=

"Hello World!"

;

if( status == MQTTSuccess )

{

}

MQTTStatus_t MQTTAgent_Publish(const MQTTAgentContext_t *pMqttAgentContext, MQTTPublishInfo_t *pPublishInfo, const MQTTAgentCommandInfo_t *pCommandInfo)

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

Definition: core_mqtt_agent.c:1227

◆ MQTTAgent_ProcessLoop()

Send a message to the MQTT agent purely to trigger an iteration of its loop, which will result in a call to MQTT_ProcessLoop(). This function can be used to wake the MQTT agent task when it is known data may be available on the connected socket.

Parameters
[in] pMqttAgentContext The MQTT agent to use. [in] pCommandInfo The information pertaining to the command, including:
Returns
MQTTSuccess if the command was posted to the MQTT agent's event queue. Otherwise an enumerated error code.

Example

if( status == MQTTSuccess )

{

}

MQTTStatus_t MQTTAgent_ProcessLoop(const MQTTAgentContext_t *pMqttAgentContext, const MQTTAgentCommandInfo_t *pCommandInfo)

Send a message to the MQTT agent purely to trigger an iteration of its loop, which will result in a c...

Definition: core_mqtt_agent.c:1252

◆ MQTTAgent_Ping()

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

Note
This API function ONLY enqueues a command to send a ping request to the server, and DOES NOT wait for a ping response to be received from the server. To detect whether a Ping Response, has not been received from the server, the MQTTAgent_CommandLoop function SHOULD be used, which returns the MQTTKeepAliveTimeout return code on a ping response (or keep-alive) timeout.
Parameters
[in] pMqttAgentContext The MQTT agent to use. [in] pCommandInfo The information pertaining to the command, including:
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

if( status == MQTTSuccess )

{

}

MQTTStatus_t MQTTAgent_Ping(const MQTTAgentContext_t *pMqttAgentContext, const MQTTAgentCommandInfo_t *pCommandInfo)

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

Definition: core_mqtt_agent.c:1323

◆ MQTTAgent_Connect()

Add a command to call MQTT_Connect() for an MQTT connection. If a session is resumed with the broker, it will also resend the necessary QoS1/2 publishes.

Note
The MQTTAgent_Connect function is provided to give a thread safe equivalent to the MQTT_Connect API. However, it is RECOMMENDED that instead of the application tasks (i.e. tasks other than the agent task), the agent be responsible for creating the MQTT connection (by calling MQTT_Connect) before starting the command loop (with the MQTTAgent_CommandLoop() call). In that case, the agent SHOULD also be responsible for disconnecting the MQTT connection after the command loop has terminated (through an MQTTAgent_Terminate() call from an application task).
Parameters
[in] pMqttAgentContext The MQTT agent to use. [in,out] pConnectArgs Struct holding args for MQTT_Connect(). On a successful connection after the command is processed, the sessionPresent member will be filled to indicate whether the broker resumed an existing session. [in] pCommandInfo The information pertaining to the command, including:
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

connectArgs.pConnectInfo = &connectInfo;

connectArgs.pWillInfo = &willInfo;

connectArgs.timeoutMs = 500;

if( status == MQTTSuccess )

{

}

MQTTStatus_t MQTTAgent_Connect(const MQTTAgentContext_t *pMqttAgentContext, MQTTAgentConnectArgs_t *pConnectArgs, const MQTTAgentCommandInfo_t *pCommandInfo)

Add a command to call MQTT_Connect() for an MQTT connection. If a session is resumed with the broker,...

Definition: core_mqtt_agent.c:1275

Struct holding arguments for a CONNECT call.

Definition: core_mqtt_agent.h:177

const char * pClientIdentifier

uint16_t keepAliveSeconds

uint16_t clientIdentifierLength

◆ MQTTAgent_Disconnect()

Add a command to disconnect an MQTT connection.

Note
MQTTAgent_CommandLoop will return after processing a DISCONNECT command to allow the network connection to be disconnected. However, any pending commands in the queue, as well as those waiting for an acknowledgment, will NOT be terminated.
The MQTTAgent_Disconnect function is provided to give a thread safe equivalent to the MQTT_Disconnect API. However, if the agent task is responsible for creating the MQTT connection (before calling MQTTAgent_CommandLoop()), then it is RECOMMENDED that an application task (i.e. a task other than the agent task) use MQTTAgent_Terminate to terminate the command loop in the agent, and the agent task be responsible for disconnecting the MQTT connection.
Parameters
[in] pMqttAgentContext The MQTT agent to use. [in] pCommandInfo The information pertaining to the command, including:
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

if( status == MQTTSuccess )

{

}

MQTTStatus_t MQTTAgent_Disconnect(const MQTTAgentContext_t *pMqttAgentContext, const MQTTAgentCommandInfo_t *pCommandInfo)

Add a command to disconnect an MQTT connection.

Definition: core_mqtt_agent.c:1300

◆ MQTTAgent_Terminate()

Add a termination command to the command queue.

On command loop termination, all pending commands in the queue, as well as those waiting for an acknowledgment, will be terminated with error code MQTTRecvFailed.

Note
Commands may still be posted to the command queue after MQTTAgent_CommandLoop has returned. It is the responsibility of the application to cancel any commands that are posted while the command loop is not running, such as by invoking MQTTAgent_CancelAll.
We RECOMMEND that this function is used from application task(s), that is a task not running the agent, to terminate the agent loop instead of calling MQTTAgent_Disconnect, so that the logic for creating and closing MQTT connection is owned by the agent task.
Parameters
[in] pMqttAgentContext The MQTT agent to use. [in] pCommandInfo The information pertaining to the command, including:
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

if( status == MQTTSuccess )

{

}

MQTTStatus_t MQTTAgent_Terminate(const MQTTAgentContext_t *pMqttAgentContext, const MQTTAgentCommandInfo_t *pCommandInfo)

Add a termination command to the command queue.

Definition: core_mqtt_agent.c:1346


RetroSearch is an open source project built by @garambo | Open a GitHub Issue

Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo

HTML: 3.2 | Encoding: UTF-8 | Version: 0.7.4