FreeRTOS
|
MQTT Agent Interface. More...
Go to the source code of this file.
Data Structures | |
struct | MQTTAgentCallbackParams |
Passed by the library in the callback to inform the user of various events. More... | |
struct | MQTTAgentConnectParams |
Parameters passed to the MQTT_AGENT_Connect API. More... | |
struct | MQTTAgentSubscribeParams |
Parameters passed to the MQTT_AGENT_Subscribe API. More... | |
struct | MQTTAgentUnsubscribeParams |
Parameters passed to the MQTT_AGENT_Unsubscribe API. More... | |
struct | MQTTAgentPublishParams |
Parameters passed to the MQTT_AGENT_Publish API. More... | |
Macros | |
#define | mqttagentURL_IS_IP_ADDRESS 0x00000001 |
Flags for the MQTT agent connect params. More... | |
#define | mqttagentREQUIRE_TLS 0x00000002 |
#define | mqttagentUSE_AWS_IOT_ALPN_443 0x00000004 |
Typedefs | |
typedef void * | MQTTAgentHandle_t |
Opaque handle to represent an MQTT client. More... | |
typedef struct MQTTAgentCallbackParams | MQTTAgentCallbackParams_t |
Passed by the library in the callback to inform the user of various events. More... | |
typedef BaseType_t(* | MQTTAgentCallback_t) (void *pvUserData, const MQTTAgentCallbackParams_t *const pxCallbackParams) |
Signature of the callback registered by the user to get notified of various events. More... | |
typedef struct MQTTAgentConnectParams | MQTTAgentConnectParams_t |
Parameters passed to the MQTT_AGENT_Connect API. | |
typedef struct MQTTAgentSubscribeParams | MQTTAgentSubscribeParams_t |
Parameters passed to the MQTT_AGENT_Subscribe API. | |
typedef struct MQTTAgentUnsubscribeParams | MQTTAgentUnsubscribeParams_t |
Parameters passed to the MQTT_AGENT_Unsubscribe API. | |
typedef struct MQTTAgentPublishParams | MQTTAgentPublishParams_t |
Parameters passed to the MQTT_AGENT_Publish API. | |
Enumerations | |
enum | MQTTAgentReturnCode_t { eMQTTAgentSuccess, eMQTTAgentFailure, eMQTTAgentTimeout, eMQTTAgentAPICalledFromCallback } |
Return codes. More... | |
enum | MQTTAgentEvent_t { eMQTTAgentPublish, eMQTTAgentDisconnect } |
Various events reported by the library in the callback. More... | |
Functions | |
lib_initDECLARE_LIB_INIT (MQTT_AGENT_Init) | |
MQTT library Init function. More... | |
MQTTAgentReturnCode_t | MQTT_AGENT_Create (MQTTAgentHandle_t *const pxMQTTHandle) |
Creates a new MQTT client. More... | |
MQTTAgentReturnCode_t | MQTT_AGENT_Delete (MQTTAgentHandle_t xMQTTHandle) |
Deletes the already created MQTT client. More... | |
MQTTAgentReturnCode_t | MQTT_AGENT_Connect (MQTTAgentHandle_t xMQTTHandle, const MQTTAgentConnectParams_t *const pxConnectParams, TickType_t xTimeoutTicks) |
Establishes a connection with the MQTT broker. More... | |
MQTTAgentReturnCode_t | MQTT_AGENT_Disconnect (MQTTAgentHandle_t xMQTTHandle, TickType_t xTimeoutTicks) |
Disconnects the connection with the MQTT broker. More... | |
MQTTAgentReturnCode_t | MQTT_AGENT_Subscribe (MQTTAgentHandle_t xMQTTHandle, const MQTTAgentSubscribeParams_t *const pxSubscribeParams, TickType_t xTimeoutTicks) |
Subscribes to a given topic. More... | |
MQTTAgentReturnCode_t | MQTT_AGENT_Unsubscribe (MQTTAgentHandle_t xMQTTHandle, const MQTTAgentUnsubscribeParams_t *const pxUnsubscribeParams, TickType_t xTimeoutTicks) |
Unsubscribes from a given topic. More... | |
MQTTAgentReturnCode_t | MQTT_AGENT_Publish (MQTTAgentHandle_t xMQTTHandle, const MQTTAgentPublishParams_t *const pxPublishParams, TickType_t xTimeoutTicks) |
Publishes a message to a given topic. More... | |
MQTTAgentReturnCode_t | MQTT_AGENT_ReturnBuffer (MQTTAgentHandle_t xMQTTHandle, MQTTBufferHandle_t xBufferHandle) |
Returns the buffer provided in the publish callback. More... | |
MQTT Agent Interface.
Definition in file aws_mqtt_agent.h.
#define mqttagentREQUIRE_TLS 0x00000002 |
Set this bit in xFlags to use TLS.
Definition at line 129 of file aws_mqtt_agent.h.
#define mqttagentURL_IS_IP_ADDRESS 0x00000001 |
Flags for the MQTT agent connect params.
Set this bit in xFlags if the provided URL is an IP address.
Definition at line 128 of file aws_mqtt_agent.h.
#define mqttagentUSE_AWS_IOT_ALPN_443 0x00000004 |
Set this bit in xFlags to use AWS IoT support for MQTT over TLS port 443.
Definition at line 130 of file aws_mqtt_agent.h.
typedef BaseType_t( * MQTTAgentCallback_t) (void *pvUserData, const MQTTAgentCallbackParams_t *const pxCallbackParams) |
Signature of the callback registered by the user to get notified of various events.
The user can register an optional callback to get notified of various events.
[in] | pvUserData | The user data as provided in the connect parameters while connecting. |
[in] | pxCallbackParams | The event and related data. |
Definition at line 122 of file aws_mqtt_agent.h.
typedef struct MQTTAgentCallbackParams MQTTAgentCallbackParams_t |
Passed by the library in the callback to inform the user of various events.
If the user has registered a callback to get notified of various events, a pointer to this structure is passed in the callback function.
typedef void* MQTTAgentHandle_t |
Opaque handle to represent an MQTT client.
The MQTT library is capable of creating multiple MQTT clients, maximum number of which is controlled by mqttconfigMAX_BROKERS macro. Each client is identified by an opaque handle which is returned by the MQTT_AGENT_Create API call and later used in all the subsequent API calls.
Definition at line 52 of file aws_mqtt_agent.h.
enum MQTTAgentEvent_t |
Various events reported by the library in the callback.
The user can register an optional callback with the MQTT library to get notified of various events including Publish messages received from the broker. This enum identifies the event received in the callback.
Enumerator | |
---|---|
eMQTTAgentPublish | A Publish message was received from the broker. |
eMQTTAgentDisconnect | The connection to the broker got disconnected. |
Definition at line 77 of file aws_mqtt_agent.h.
Return codes.
Each API returns a value of this type.
Definition at line 59 of file aws_mqtt_agent.h.
lib_initDECLARE_LIB_INIT | ( | MQTT_AGENT_Init | ) |
MQTT library Init function.
This function does general initialization and setup. It must be called once and only once before calling any other function.
MQTTAgentReturnCode_t MQTT_AGENT_Connect | ( | MQTTAgentHandle_t | xMQTTHandle, |
const MQTTAgentConnectParams_t *const | pxConnectParams, | ||
TickType_t | xTimeoutTicks | ||
) |
Establishes a connection with the MQTT broker.
[in] | xMQTTHandle | The opaque handle as returned from MQTT_AGENT_Create. |
[in] | pxConnectParams | Connect parameters. |
[in] | xTimeoutTicks | Maximum time in ticks after which the operation should fail. Use pdMS_TO_TICKS macro to convert milliseconds to ticks. |
MQTTAgentReturnCode_t MQTT_AGENT_Create | ( | MQTTAgentHandle_t *const | pxMQTTHandle | ) |
Creates a new MQTT client.
The MQTT library is capable of creating multiple MQTT clients, maximum number of which is controlled by mqttconfigMAX_BROKERS macro. If mqttconfigMAX_BROKERS clients are already in use, this function will fail immediately. Otherwise a new client is setup and the handle to the created client is returned in the pxMQTTHandle parameter which should be used in all the subsequent API calls. Note that the returned handled is only valid if the return value of the API is eMQTTAgentSuccess.
[out] | pxMQTTHandle | Output parameter to return the opaque client handle. |
MQTTAgentReturnCode_t MQTT_AGENT_Delete | ( | MQTTAgentHandle_t | xMQTTHandle | ) |
Deletes the already created MQTT client.
This function just frees up the internal resources and does not disconnect. The user must call MQTT_AGENT_Disconnect API to make sure that the client is disconnected before deleting it.
[in] | xMQTTHandle | The opaque handle as returned from MQTT_AGENT_Create. |
MQTTAgentReturnCode_t MQTT_AGENT_Disconnect | ( | MQTTAgentHandle_t | xMQTTHandle, |
TickType_t | xTimeoutTicks | ||
) |
Disconnects the connection with the MQTT broker.
[in] | xMQTTHandle | The opaque handle as returned from MQTT_AGENT_Create. |
[in] | xTimeoutTicks | Maximum time in ticks after which the operation should fail. Use pdMS_TO_TICKS macro to convert milliseconds to ticks. |
MQTTAgentReturnCode_t MQTT_AGENT_Publish | ( | MQTTAgentHandle_t | xMQTTHandle, |
const MQTTAgentPublishParams_t *const | pxPublishParams, | ||
TickType_t | xTimeoutTicks | ||
) |
Publishes a message to a given topic.
[in] | xMQTTHandle | The opaque handle as returned from MQTT_AGENT_Create. |
[in] | pxPublishParams | Publish parameters. |
[in] | xTimeoutTicks | Maximum time in ticks after which the operation should fail. Use pdMS_TO_TICKS macro to convert milliseconds to ticks. |
MQTTAgentReturnCode_t MQTT_AGENT_ReturnBuffer | ( | MQTTAgentHandle_t | xMQTTHandle, |
MQTTBufferHandle_t | xBufferHandle | ||
) |
Returns the buffer provided in the publish callback.
When a publish message is received from the broker, the buffer containing the message is returned in the user supplied callback (xBuffer in MQTTPublishData_t) and the user can take the ownership by returning pdTRUE from the callback. The user should later return the buffer whenever done by calling the MQTT_AGENT_ReturnBuffer API.
[in] | xMQTTHandle | The opaque handle as returned from MQTT_AGENT_Create. |
[in] | xBufferHandle | The buffer to return. |
MQTTAgentReturnCode_t MQTT_AGENT_Subscribe | ( | MQTTAgentHandle_t | xMQTTHandle, |
const MQTTAgentSubscribeParams_t *const | pxSubscribeParams, | ||
TickType_t | xTimeoutTicks | ||
) |
Subscribes to a given topic.
Whenever a publish message is received on a topic, the registered callbacks are invoked in the following order:
[in] | xMQTTHandle | The opaque handle as returned from MQTT_AGENT_Create. |
[in] | pxSubscribeParams | Subscribe parameters. |
[in] | xTimeoutTicks | Maximum time in ticks after which the operation should fail. Use pdMS_TO_TICKS macro to convert milliseconds to ticks. |
MQTTAgentReturnCode_t MQTT_AGENT_Unsubscribe | ( | MQTTAgentHandle_t | xMQTTHandle, |
const MQTTAgentUnsubscribeParams_t *const | pxUnsubscribeParams, | ||
TickType_t | xTimeoutTicks | ||
) |
Unsubscribes from a given topic.
[in] | xMQTTHandle | The opaque handle as returned from MQTT_AGENT_Create. |
[in] | pxUnsubscribeParams | Unsubscribe parameters. |
[in] | xTimeoutTicks | Maximum time in ticks after which the operation should fail. Use pdMS_TO_TICKS macro to convert milliseconds to ticks. |