AWS IoT Device SDK C: MQTT
MQTT 3.1.1 client library
Return to main page ↑
aws_iot_mqtt_client_interface.h File Reference

Interface definition for MQTT client. More...

#include "stdio.h"
#include "stdbool.h"
#include "stdint.h"
#include "stddef.h"
#include "aws_iot_error.h"
#include "aws_iot_config.h"
#include "aws_iot_mqtt_client.h"
#include "network_interface.h"
#include "timer_interface.h"

Go to the source code of this file.

Functions

IoT_Error_t aws_iot_mqtt_free (AWS_IoT_Client *pClient)
 Clean mqtt client from all dynamic memory allocate. More...
 
IoT_Error_t aws_iot_mqtt_init (AWS_IoT_Client *pClient, IoT_Client_Init_Params *pInitParams)
 MQTT Client Initialization Function. More...
 
IoT_Error_t aws_iot_mqtt_connect (AWS_IoT_Client *pClient, IoT_Client_Connect_Params *pConnectParams)
 MQTT Connection Function. More...
 
IoT_Error_t aws_iot_mqtt_publish (AWS_IoT_Client *pClient, const char *pTopicName, uint16_t topicNameLen, IoT_Publish_Message_Params *pParams)
 Publish an MQTT message on a topic. More...
 
IoT_Error_t aws_iot_mqtt_subscribe (AWS_IoT_Client *pClient, const char *pTopicName, uint16_t topicNameLen, QoS qos, pApplicationHandler_t pApplicationHandler, void *pApplicationHandlerData)
 Subscribe to an MQTT topic. More...
 
IoT_Error_t aws_iot_mqtt_resubscribe (AWS_IoT_Client *pClient)
 Subscribe to an MQTT topic. More...
 
IoT_Error_t aws_iot_mqtt_unsubscribe (AWS_IoT_Client *pClient, const char *pTopicFilter, uint16_t topicFilterLen)
 Unsubscribe to an MQTT topic. More...
 
IoT_Error_t aws_iot_mqtt_disconnect (AWS_IoT_Client *pClient)
 Disconnect an MQTT Connection. More...
 
IoT_Error_t aws_iot_mqtt_yield (AWS_IoT_Client *pClient, uint32_t timeout_ms)
 Yield to the MQTT client. More...
 
IoT_Error_t aws_iot_mqtt_attempt_reconnect (AWS_IoT_Client *pClient)
 MQTT Manual Re-Connection Function. More...
 

Detailed Description

Interface definition for MQTT client.

Function Documentation

◆ aws_iot_mqtt_free()

IoT_Error_t aws_iot_mqtt_free ( AWS_IoT_Client *  pClient)

Clean mqtt client from all dynamic memory allocate.

This function will free up memory that was dynamically allocated for the client.

Parameters
pClientMQTT Client that was previously created by calling aws_iot_mqtt_init
Returns
An IoT Error Type defining successful/failed freeing

◆ aws_iot_mqtt_init()

IoT_Error_t aws_iot_mqtt_init ( AWS_IoT_Client *  pClient,
IoT_Client_Init_Params pInitParams 
)

MQTT Client Initialization Function.

Called to initialize the MQTT Client

Parameters
pClientReference to the IoT Client
pInitParamsPointer to MQTT connection parameters
Returns
IoT_Error_t Type defining successful/failed API call

◆ aws_iot_mqtt_connect()

IoT_Error_t aws_iot_mqtt_connect ( AWS_IoT_Client *  pClient,
IoT_Client_Connect_Params pConnectParams 
)

MQTT Connection Function.

Called to establish an MQTT connection with the AWS IoT Service

Parameters
pClientReference to the IoT Client
pConnectParamsPointer to MQTT connection parameters
Returns
An IoT Error Type defining successful/failed connection

Called to establish an MQTT connection with the AWS IoT Service This is the outer function which does the validations and calls the internal connect above to perform the actual operation. It is also responsible for client state changes

Parameters
pClientReference to the IoT Client
pConnectParamsPointer to MQTT connection parameters
Returns
An IoT Error Type defining successful/failed connection

◆ aws_iot_mqtt_publish()

IoT_Error_t aws_iot_mqtt_publish ( AWS_IoT_Client *  pClient,
const char *  pTopicName,
uint16_t  topicNameLen,
IoT_Publish_Message_Params pParams 
)

Publish an MQTT message on a topic.

Called to publish an MQTT message on a topic.

Note
Call is blocking. In the case of a QoS 0 message the function returns after the message was successfully passed to the TLS layer. In the case of QoS 1 the function returns after the receipt of the PUBACK control packet.
Parameters
pClientReference to the IoT Client
pTopicNameTopic Name to publish to
topicNameLenLength of the topic name
pParamsPointer to Publish Message parameters
Returns
An IoT Error Type defining successful/failed publish

◆ aws_iot_mqtt_subscribe()

IoT_Error_t aws_iot_mqtt_subscribe ( AWS_IoT_Client *  pClient,
const char *  pTopicName,
uint16_t  topicNameLen,
QoS  qos,
pApplicationHandler_t  pApplicationHandler,
void *  pApplicationHandlerData 
)

Subscribe to an MQTT topic.

Called to send a subscribe message to the broker requesting a subscription to an MQTT topic.

Note
Call is blocking. The call returns after the receipt of the SUBACK control packet.
Warning
pTopicName and pApplicationHandlerData need to be static in memory.
Parameters
pClientReference to the IoT Client
pTopicNameTopic Name to publish to. pTopicName needs to be static in memory since no malloc is performed by the SDK
topicNameLenLength of the topic name
qosQuality of service for subscription
pApplicationHandlerReference to the handler function for this subscription
pApplicationHandlerDataPoint to data passed to the callback. pApplicationHandlerData also needs to be static in memory since no malloc is performed by the SDK
Returns
An IoT Error Type defining successful/failed subscription

◆ aws_iot_mqtt_resubscribe()

IoT_Error_t aws_iot_mqtt_resubscribe ( AWS_IoT_Client *  pClient)

Subscribe to an MQTT topic.

Called to resubscribe to the topics that the client has active subscriptions on. Internally called when autoreconnect is enabled

Note
Call is blocking. The call returns after the receipt of the SUBACK control packet.
Parameters
pClientReference to the IoT Client
Returns
An IoT Error Type defining successful/failed subscription

◆ aws_iot_mqtt_unsubscribe()

IoT_Error_t aws_iot_mqtt_unsubscribe ( AWS_IoT_Client *  pClient,
const char *  pTopicFilter,
uint16_t  topicFilterLen 
)

Unsubscribe to an MQTT topic.

Called to send an unsubscribe message to the broker requesting removal of a subscription to an MQTT topic.

Note
Call is blocking. The call returns after the receipt of the UNSUBACK control packet.
Parameters
pClientReference to the IoT Client
pTopicFilterTopic filter of subscription
topicFilterLenLength of the topic filter
Returns
An IoT Error Type defining successful/failed unsubscribe call

◆ aws_iot_mqtt_disconnect()

IoT_Error_t aws_iot_mqtt_disconnect ( AWS_IoT_Client *  pClient)

Disconnect an MQTT Connection.

Called to send a disconnect message to the broker.

Parameters
pClientReference to the IoT Client
Returns
An IoT Error Type defining successful/failed send of the disconnect control packet.

Called to send a disconnect message to the broker. This is the outer function which does the validations and calls the internal disconnect above to perform the actual operation. It is also responsible for client state changes

Parameters
pClientReference to the IoT Client
Returns
An IoT Error Type defining successful/failed send of the disconnect control packet.

◆ aws_iot_mqtt_yield()

IoT_Error_t aws_iot_mqtt_yield ( AWS_IoT_Client *  pClient,
uint32_t  timeout_ms 
)

Yield to the MQTT client.

Called to yield the current thread to the underlying MQTT client. This time is used by the MQTT client to manage PING requests to monitor the health of the TCP connection as well as periodically check the socket receive buffer for subscribe messages. Yield() must be called at a rate faster than the keepalive interval. It must also be called at a rate faster than the incoming message rate as this is the only way the client receives processing time to manage incoming messages.

Parameters
pClientReference to the IoT Client
timeout_msMaximum number of milliseconds to pass thread execution to the client.
Returns
An IoT Error Type defining successful/failed client processing. If this call results in an error it is likely the MQTT connection has dropped. iot_is_mqtt_connected can be called to confirm.

◆ aws_iot_mqtt_attempt_reconnect()

IoT_Error_t aws_iot_mqtt_attempt_reconnect ( AWS_IoT_Client *  pClient)

MQTT Manual Re-Connection Function.

Called to establish an MQTT connection with the AWS IoT Service using parameters from the last time a connection was attempted Use after disconnect to start the reconnect process manually Makes only one reconnect attempt Sets the client state to pending reconnect in case of failure

Parameters
pClientReference to the IoT Client
Returns
An IoT Error Type defining successful/failed connection

Called to establish an MQTT connection with the AWS IoT Service using parameters from the last time a connection was attempted Use after disconnect to start the reconnect process manually Makes only one reconnect attempt. Sets the client state to pending reconnect in case of failure

Parameters
pClientReference to the IoT Client
Returns
An IoT Error Type defining successful/failed connection