Functions for running a coreMQTT client in a dedicated thread. More...
#include "core_mqtt.h"
#include "core_mqtt_state.h"
#include "core_mqtt_agent_config_defaults.h"
#include "core_mqtt_agent_message_interface.h"
Go to the source code of this file.
Data Structures | |
struct | MQTTAgentReturnInfo_t |
Struct holding return codes and outputs from a command. More... | |
struct | MQTTAgentCommand_t |
The commands sent from the APIs to the MQTT agent task. More... | |
struct | MQTTAgentAckInfo_t |
Information for a pending MQTT ack packet expected by the agent. More... | |
struct | MQTTAgentContext_t |
Information used by each MQTT agent. A context will be initialized by MQTTAgent_Init(), and every API function will accept a pointer to the initalized struct. More... | |
struct | MQTTAgentSubscribeArgs_t |
Struct holding arguments for a SUBSCRIBE or UNSUBSCRIBE call. More... | |
struct | MQTTAgentConnectArgs_t |
Struct holding arguments for a CONNECT call. More... | |
struct | MQTTAgentCommandInfo_t |
Struct holding arguments that are common to every command. More... | |
Typedefs | |
typedef struct MQTTAgentCommandContext | MQTTAgentCommandContext_t |
Struct containing context for a specific command. More... | |
typedef void(* | MQTTAgentCommandCallback_t) (MQTTAgentCommandContext_t *pCmdCallbackContext, MQTTAgentReturnInfo_t *pReturnInfo) |
Callback function called when a command completes. More... | |
typedef void(* | MQTTAgentIncomingPublishCallback_t) (struct MQTTAgentContext *pMqttAgentContext, uint16_t packetId, MQTTPublishInfo_t *pPublishInfo) |
Callback function called when receiving a publish. More... | |
Enumerations | |
enum | MQTTAgentCommandType_t { NONE = 0 , PROCESSLOOP , PUBLISH , SUBSCRIBE , UNSUBSCRIBE , PING , CONNECT , DISCONNECT , TERMINATE , NUM_COMMANDS } |
A type of command for interacting with the MQTT API. More... | |
Functions | |
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. More... | |
MQTTStatus_t | MQTTAgent_CommandLoop (MQTTAgentContext_t *pMqttAgentContext) |
Process commands from the command queue in a loop. More... | |
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. More... | |
MQTTStatus_t | MQTTAgent_CancelAll (MQTTAgentContext_t *pMqttAgentContext) |
Cancel all enqueued commands and those awaiting acknowledgment while the command loop is not running. More... | |
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. More... | |
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. More... | |
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. More... | |
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. More... | |
MQTTStatus_t | MQTTAgent_Ping (const MQTTAgentContext_t *pMqttAgentContext, const MQTTAgentCommandInfo_t *pCommandInfo) |
Add a command to call MQTT_Ping() for an MQTT connection. More... | |
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. More... | |
MQTTStatus_t | MQTTAgent_Disconnect (const MQTTAgentContext_t *pMqttAgentContext, const MQTTAgentCommandInfo_t *pCommandInfo) |
Add a command to disconnect an MQTT connection. More... | |
MQTTStatus_t | MQTTAgent_Terminate (const MQTTAgentContext_t *pMqttAgentContext, const MQTTAgentCommandInfo_t *pCommandInfo) |
Add a termination command to the command queue. More... | |
Functions for running a coreMQTT client in a dedicated thread.
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.
[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. |
pIncomingPacketContext
context provided for the incoming publish callback MUST remain in scope throughout the period that the agent task is running.Example
MQTTStatus_t MQTTAgent_CommandLoop | ( | MQTTAgentContext_t * | pMqttAgentContext | ) |
Process commands from the command queue in a loop.
[in] | pMqttAgentContext | The MQTT agent to use. |
Example
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.
[in] | pMqttAgentContext | The MQTT agent to use. |
[in] | sessionPresent | The session present flag from the broker. |
MQTT_Publish()
Example
MQTTStatus_t MQTTAgent_CancelAll | ( | MQTTAgentContext_t * | pMqttAgentContext | ) |
Cancel all enqueued commands and those awaiting acknowledgment while the command loop is not running.
Canceled commands will be terminated with return code MQTTRecvFailed.
[in] | pMqttAgentContext | The MQTT agent to use. |
Example
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.
[in] | pMqttAgentContext | The MQTT agent to use. |
[in] | pSubscriptionArgs | Struct describing topic to subscribe to. |
[in] | pCommandInfo | The information pertaining to the command, including:
|
pCommandInfo
parameter MUST remain in scope at least until the callback has been executed by the agent task.Example
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.
[in] | pMqttAgentContext | The MQTT agent to use. |
[in] | pSubscriptionArgs | List of topics to unsubscribe from. |
[in] | pCommandInfo | The information pertaining to the command, including:
|
pCommandInfo
parameter MUST remain in scope at least until the callback has been executed by the agent task.Example
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.
[in] | pMqttAgentContext | The MQTT agent to use. |
[in] | pPublishInfo | MQTT PUBLISH information. |
[in] | pCommandInfo | The information pertaining to the command, including:
|
pCommandInfo
parameter MUST remain in scope at least until the callback has been executed by the agent task.Example
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.
[in] | pMqttAgentContext | The MQTT agent to use. |
[in] | pCommandInfo | The information pertaining to the command, including:
|
Example
MQTTStatus_t MQTTAgent_Ping | ( | const MQTTAgentContext_t * | pMqttAgentContext, |
const MQTTAgentCommandInfo_t * | pCommandInfo | ||
) |
Add a command to call MQTT_Ping() for an MQTT connection.
[in] | pMqttAgentContext | The MQTT agent to use. |
[in] | pCommandInfo | The information pertaining to the command, including:
|
pCommandInfo
parameter MUST remain in scope at least until the callback has been executed by the agent task.Example
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.
[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:
|
pCommandInfo
parameter MUST remain in scope at least until the callback has been executed by the agent task.Example
MQTTStatus_t MQTTAgent_Disconnect | ( | const MQTTAgentContext_t * | pMqttAgentContext, |
const MQTTAgentCommandInfo_t * | pCommandInfo | ||
) |
Add a command to disconnect an MQTT connection.
[in] | pMqttAgentContext | The MQTT agent to use. |
[in] | pCommandInfo | The information pertaining to the command, including:
|
pCommandInfo
parameter MUST remain in scope at least until the callback has been executed by the agent task.Example
MQTTStatus_t MQTTAgent_Terminate | ( | const MQTTAgentContext_t * | pMqttAgentContext, |
const MQTTAgentCommandInfo_t * | pCommandInfo | ||
) |
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.
[in] | pMqttAgentContext | The MQTT agent to use. |
[in] | pCommandInfo | The information pertaining to the command, including:
|
pCommandInfo
parameter MUST remain in scope at least until the callback has been executed by the agent task.Example