IoT managed integrations End Device SDK
Loading...
Searching...
No Matches
Macros | Typedefs | Functions
iotmi_device_MqttAgent.h File Reference

This file defines MQTT agent public header. More...

#include "core_mqtt.h"
#include "core_pkcs11.h"
#include "iotmi_pal_NetworkTransport.h"

Go to the source code of this file.

Macros

#define MQTT_AGENT_MAX_SUBSCRIPTIONS   (30U)
 

Typedefs

typedef struct iotmiDev_MQTTAgentUserContext iotmiDev_MQTTAgentUserContext_t
 
typedef iotmiDev_MQTTAgentUserContext_t * iotmiDev_MQTTAgentUserHandle_t
 
typedef void(* IncomingPubCallback_t) (void *pvIncomingPublishCallbackContext, MQTTPublishInfo_t *pxPublishInfo)
 Callback function called when receiving a publish.
 

Functions

MQTTStatus_t iotmiDev_MQTTAgentInit (NetworkContext_t *pxNetworkContext, size_t networkBufferSize)
 MQTT Agent init function for IoT managed integrations connection. Two type of the MQTT connections are used in the SDK. The fleet provisioning connection is used to provision the device with credentials to connect to IoT managed integrations endpoint. iotmiDev_MQTTAgentFleetProvisioningInit should be called for fleet provisioning connection. The IoT Managed Integrations connection is used to exchange message with IoT Managed Integrations service. iotmiDev_MQTTAgentInit should be called for IoT managed integrations service connection.
 
MQTTStatus_t iotmiDev_MQTTAgentFleetProvisioningInit (NetworkContext_t *pxNetworkContext, size_t networkBufferSize)
 MQTT Agent init function for fleet provisioning connection.
 
void iotmiDev_MQTTAgentDeinit (void)
 MQTT Agent de-init function to free all the resource allocated in iotmiDev_MQTTAgentInit.
 
MQTTStatus_t iotmiDev_MQTTAgentThreadLoop (char *pClientId, const char *pManagedIntegrationsEndpoint, uint16_t managedIntegrationsEndpointPort, bool xCleanSession, CK_SESSION_HANDLE pxSession, char *pRootCaLabel, char *pCertificateLabel, char *pPrivateKeyLabel)
 MQTT Agent connection and command loop function.
 
MQTTStatus_t iotmiDev_MQTTAgentStop (void)
 MQTT Agent thread loop stop function.
 
iotmiDev_MQTTAgentUserHandle_t iotmiDev_MQTTAgentCreateUserContext (void)
 MQTT Agent create user context for IoT managed integrations connection. User context should be created according to the which iotmiDev_MQTTAgentInit is called. iotmiDev_MQTTAgentCreateFleetProvisioningUserContext should be called to create user context with iotmiDev_MQTTAgentFleetProvisioningInit. iotmiDev_MQTTAgentCreateUserContext should be called to create user context with iotmiDev_MQTTAgentInit.
 
iotmiDev_MQTTAgentUserHandle_t iotmiDev_MQTTAgentCreateFleetProvisioningUserContext (void)
 MQTT Agent create user context for fleet provisioning connection.
 
void iotmiDev_MQTTAgentDeleteUserContext (iotmiDev_MQTTAgentUserHandle_t userHandle)
 MQTT Agent delete user context.
 
MQTTStatus_t iotmiDev_MQTTAgentPublish (iotmiDev_MQTTAgentUserHandle_t userHandle, MQTTPublishInfo_t *pPublishInfo, uint32_t blockTimeMs)
 MQTT Agent synchronous publish function.
 
MQTTStatus_t iotmiDev_MQTTAgentAddSubscription (iotmiDev_MQTTAgentUserHandle_t userHandle, const char *pcTopicFilterString, uint16_t usTopicFilterLength, IncomingPubCallback_t pxIncomingPublishCallback, void *pvIncomingPublishCallbackContext, uint32_t blockTimeMs)
 MQTT Agent synchronous subscription function. Qos1 will be used in this function.
 
MQTTStatus_t iotmiDev_MQTTAgentRemoveSubscription (iotmiDev_MQTTAgentUserHandle_t userHandle, const char *pcTopicFilterString, uint16_t usTopicFilterLength, uint32_t blockTimeMs)
 MQTT Agent synchronous unsubscription function. Qos1 will be used in this function.
 

Detailed Description

This file defines MQTT agent public header.

Typedef Documentation

◆ IncomingPubCallback_t

typedef void(* IncomingPubCallback_t) (void *pvIncomingPublishCallbackContext, MQTTPublishInfo_t *pxPublishInfo)

Callback function called when receiving a publish.

Parameters
[in]pvIncomingPublishCallbackContextThe incoming publish callback context.
[in]pxPublishInfoDeserialized publish information.

Function Documentation

◆ iotmiDev_MQTTAgentAddSubscription()

MQTTStatus_t iotmiDev_MQTTAgentAddSubscription ( iotmiDev_MQTTAgentUserHandle_t  userHandle,
const char *  pcTopicFilterString,
uint16_t  usTopicFilterLength,
IncomingPubCallback_t  pxIncomingPublishCallback,
void *  pvIncomingPublishCallbackContext,
uint32_t  blockTimeMs 
)

MQTT Agent synchronous subscription function. Qos1 will be used in this function.

Note
Different publish callback or callback context are regarded as individual subscription record.
Parameters
[in]pUserContextpointer to MQTT Agent user context.
[in]pcTopicFilterStringTopic filter of the subscription.
[in]usTopicFilterLengthTopic filter length.
[in]pxIncomingPublishCallbackcallback function for incoming publish.
[in]pvIncomingPublishCallbackContextcontext passed to callback function.
[in]blockTimeMsMaximum block time to wait for operation complete.
Returns
Return MQTTSuccess to indicate success. Other value to indicate error.

◆ iotmiDev_MQTTAgentCreateFleetProvisioningUserContext()

iotmiDev_MQTTAgentUserHandle_t iotmiDev_MQTTAgentCreateFleetProvisioningUserContext ( void  )

MQTT Agent create user context for fleet provisioning connection.

Returns
Return pointer to created iotmiDev_MQTTAgentUserHandle_t when success. Otherwise, NULL is returned.

◆ iotmiDev_MQTTAgentCreateUserContext()

iotmiDev_MQTTAgentUserHandle_t iotmiDev_MQTTAgentCreateUserContext ( void  )

MQTT Agent create user context for IoT managed integrations connection. User context should be created according to the which iotmiDev_MQTTAgentInit is called. iotmiDev_MQTTAgentCreateFleetProvisioningUserContext should be called to create user context with iotmiDev_MQTTAgentFleetProvisioningInit. iotmiDev_MQTTAgentCreateUserContext should be called to create user context with iotmiDev_MQTTAgentInit.

Returns
Return pointer to created iotmiDev_MQTTAgentUserHandle_t when success. Otherwise, NULL is returned.

◆ iotmiDev_MQTTAgentDeleteUserContext()

void iotmiDev_MQTTAgentDeleteUserContext ( iotmiDev_MQTTAgentUserHandle_t  userHandle)

MQTT Agent delete user context.

Parameters
[in]pUserContextuser context to be deleted.

◆ iotmiDev_MQTTAgentFleetProvisioningInit()

MQTTStatus_t iotmiDev_MQTTAgentFleetProvisioningInit ( NetworkContext_t *  pxNetworkContext,
size_t  networkBufferSize 
)

MQTT Agent init function for fleet provisioning connection.

Parameters
[in]pxNetworkContextpointer to user defined network context.
[in]networkBufferSizeSize of network buffer.
Returns
Return MQTTSuccess to indicate success. Other value to indicate error.

◆ iotmiDev_MQTTAgentInit()

MQTTStatus_t iotmiDev_MQTTAgentInit ( NetworkContext_t *  pxNetworkContext,
size_t  networkBufferSize 
)

MQTT Agent init function for IoT managed integrations connection. Two type of the MQTT connections are used in the SDK. The fleet provisioning connection is used to provision the device with credentials to connect to IoT managed integrations endpoint. iotmiDev_MQTTAgentFleetProvisioningInit should be called for fleet provisioning connection. The IoT Managed Integrations connection is used to exchange message with IoT Managed Integrations service. iotmiDev_MQTTAgentInit should be called for IoT managed integrations service connection.

Parameters
[in]pxNetworkContextpointer to user defined network context.
[in]networkBufferSizeSize of network buffer.
Returns
Return MQTTSuccess to indicate success. Other value to indicate error.

◆ iotmiDev_MQTTAgentPublish()

MQTTStatus_t iotmiDev_MQTTAgentPublish ( iotmiDev_MQTTAgentUserHandle_t  userHandle,
MQTTPublishInfo_t *  pPublishInfo,
uint32_t  blockTimeMs 
)

MQTT Agent synchronous publish function.

Parameters
[in]pUserContextpointer to MQTT Agent user context.
[in]pPublishInfopublish info.
[in]blockTimeMsMaximum block time to wait for operation complete.
Returns
Return MQTTSuccess to indicate success. Other value to indicate error.

◆ iotmiDev_MQTTAgentRemoveSubscription()

MQTTStatus_t iotmiDev_MQTTAgentRemoveSubscription ( iotmiDev_MQTTAgentUserHandle_t  userHandle,
const char *  pcTopicFilterString,
uint16_t  usTopicFilterLength,
uint32_t  blockTimeMs 
)

MQTT Agent synchronous unsubscription function. Qos1 will be used in this function.

Note
All the subscription record with the same topic will be removed.
Parameters
[in]pUserContextpointer to MQTT Agent user context.
[in]pcTopicFilterStringTopic filter of the unsubscription.
[in]usTopicFilterLengthTopic filter length. function.
[in]blockTimeMsMaximum block time to wait for operation complete.
Returns
Return MQTTSuccess to indicate success. Other value to indicate error.

◆ iotmiDev_MQTTAgentStop()

MQTTStatus_t iotmiDev_MQTTAgentStop ( void  )

MQTT Agent thread loop stop function.

Returns
Return MQTTSuccess to indicate success. Other value to indicate error.

◆ iotmiDev_MQTTAgentThreadLoop()

MQTTStatus_t iotmiDev_MQTTAgentThreadLoop ( char *  pClientId,
const char *  pManagedIntegrationsEndpoint,
uint16_t  managedIntegrationsEndpointPort,
bool  xCleanSession,
CK_SESSION_HANDLE  pxSession,
char *  pRootCaLabel,
char *  pCertificateLabel,
char *  pPrivateKeyLabel 
)

MQTT Agent connection and command loop function.

Parameters
[in]pClientIdfor the MQTT connection.
[in]pManagedIntegrationsEndpointpointer to IoT managed integrations endpoint.
[in]managedIntegrationsEndpointPortport of the IoT Managed Integrations endpoint.
[in]xCleanSessionSet true to create a clean session.
[in]pxSessionUser created PKCS11 session.
[in]pRootCaLabelPKCS11 Root CA label.
[in]pCertificateLabelPKCS11 device certificate label.
[in]pPrivateKeyLabelPKCS11 private key label.
Returns
Return MQTTSuccess to indicate exit by iotmiDev_MQTTAgentStop API. Other value to indicate error.