39 #ifndef AWS_IOT_SDK_SRC_IOT_MQTT_CLIENT_H
40 #define AWS_IOT_SDK_SRC_IOT_MQTT_CLIENT_H
50 #include "aws_iot_config.h"
56 #ifdef _ENABLE_THREAD_SUPPORT_
60 #define MAX_PACKET_ID 65535
119 #define IoT_MQTT_Will_Options_Initializer { {'M', 'Q', 'T', 'W'}, NULL, 0, NULL, 0, false, QOS0 }
143 #define IoT_Client_Connect_Params_initializer { {'M', 'Q', 'T', 'C'}, MQTT_3_1_1, NULL, 0, 60, true, false, \
144 IoT_MQTT_Will_Options_Initializer, NULL, 0, NULL, 0 }
169 #ifdef _ENABLE_THREAD_SUPPORT_
170 bool isBlockOnThreadLockEnabled;
186 CLIENT_STATE_INVALID = 0,
187 CLIENT_STATE_INITIALIZED = 1,
188 CLIENT_STATE_CONNECTING = 2,
189 CLIENT_STATE_CONNECTED_IDLE = 3,
190 CLIENT_STATE_CONNECTED_YIELD_IN_PROGRESS = 4,
191 CLIENT_STATE_CONNECTED_PUBLISH_IN_PROGRESS = 5,
192 CLIENT_STATE_CONNECTED_SUBSCRIBE_IN_PROGRESS = 6,
193 CLIENT_STATE_CONNECTED_UNSUBSCRIBE_IN_PROGRESS = 7,
194 CLIENT_STATE_CONNECTED_RESUBSCRIBE_IN_PROGRESS = 8,
195 CLIENT_STATE_CONNECTED_WAIT_FOR_CB_RETURN = 9,
196 CLIENT_STATE_DISCONNECTING = 10,
197 CLIENT_STATE_DISCONNECTED_ERROR = 11,
198 CLIENT_STATE_DISCONNECTED_MANUALLY = 12,
199 CLIENT_STATE_PENDING_RECONNECT = 13
220 const char *topicName;
221 uint16_t topicNameLen;
224 void *pApplicationHandlerData;
236 bool isPingOutstanding;
237 bool isAutoReconnectEnabled;
248 uint16_t nextPacketId;
250 uint32_t commandTimeoutMs;
251 uint16_t keepAliveInterval;
252 uint32_t currentReconnectWaitInterval;
253 uint32_t counterNetworkDisconnected;
261 unsigned char writeBuf[AWS_IOT_MQTT_TX_BUF_LEN];
262 unsigned char readBuf[AWS_IOT_MQTT_RX_BUF_LEN];
264 #ifdef _ENABLE_THREAD_SUPPORT_
265 bool isBlockOnThreadLockEnabled;
266 IoT_Mutex_t state_change_mutex;
267 IoT_Mutex_t tls_read_mutex;
268 IoT_Mutex_t tls_write_mutex;
276 void *disconnectHandlerData;
287 Timer reconnectDelayTimer;
368 void *pDisconnectHandlerData);
IoT_Error_t aws_iot_mqtt_set_disconnect_handler(AWS_IoT_Client *pClient, iot_disconnect_handler pDisconnectHandler, void *pDisconnectHandlerData)
Set the IoT Client disconnect handler.
Definition: aws_iot_mqtt_client.c:278
bool isWillMsgPresent
Is there a LWT associated with this connection?
Definition: aws_iot_mqtt_client.h:134
bool isSSLHostnameVerify
Client should perform server certificate hostname validation.
Definition: aws_iot_mqtt_client.h:173
uint16_t msgLen
The length of the Message, 16 bit unsinged integer.
Definition: aws_iot_mqtt_client.h:113
bool aws_iot_mqtt_is_client_connected(AWS_IoT_Client *pClient)
Is the MQTT client currently connected?
Definition: aws_iot_mqtt_client.c:222
MQTT Client.
Definition: aws_iot_mqtt_client.h:285
char * pMessage
Message to be delivered as LWT.
Definition: aws_iot_mqtt_client.h:112
Definition of error types for the SDK.
Timer interface definition for MQTT client.
QoS qos
Message Quality of Service.
Definition: aws_iot_mqtt_client.h:83
ClientState aws_iot_mqtt_get_client_state(AWS_IoT_Client *pClient)
Get the current state of the client.
Definition: aws_iot_mqtt_client.c:48
MQTT_Ver_t
MQTT Version Type.
Definition: aws_iot_mqtt_client.h:97
void(* iot_disconnect_handler)(AWS_IoT_Client *, void *)
Disconnect Callback Handler Type.
Definition: aws_iot_mqtt_client.h:152
uint16_t clientIDLen
Client Id Length. 16 bit unsigned integer.
Definition: aws_iot_mqtt_client.h:131
uint16_t passwordLen
Password Length. 16 bit unsigned integer.
Definition: aws_iot_mqtt_client.h:139
void(* pApplicationHandler_t)(AWS_IoT_Client *pClient, char *pTopicName, uint16_t topicNameLen, IoT_Publish_Message_Params *pParams, void *pClientData)
Application Callback Handler Type.
Definition: aws_iot_mqtt_client.h:209
uint32_t mqttCommandTimeout_ms
Timeout for MQTT blocking calls. In milliseconds.
Definition: aws_iot_mqtt_client.h:168
MQTT Connection Parameters.
Definition: aws_iot_mqtt_client.h:127
MQTT_Ver_t MQTTVersion
Desired MQTT version used during connection.
Definition: aws_iot_mqtt_client.h:129
void * payload
Pointer to MQTT message payload (bytes).
Definition: aws_iot_mqtt_client.h:87
IoT_Error_t
IoT Error enum.
Definition: aws_iot_error.h:36
iot_disconnect_handler disconnectHandler
Callback to be invoked upon connection loss.
Definition: aws_iot_mqtt_client.h:174
size_t payloadLen
Length of MQTT payload.
Definition: aws_iot_mqtt_client.h:88
Thread interface definition for MQTT client.
bool aws_iot_is_autoreconnect_enabled(AWS_IoT_Client *pClient)
Is the MQTT client set to reconnect automatically?
Definition: aws_iot_mqtt_client.c:259
bool enableAutoReconnect
Set to true to enable auto reconnect.
Definition: aws_iot_mqtt_client.h:162
Definition: timer_platform.h:29
uint8_t isDup
Is this message a duplicate QoS > 0 message? Handled automatically by the MQTT client.
Definition: aws_iot_mqtt_client.h:85
QoS qos
QoS of LWT message.
Definition: aws_iot_mqtt_client.h:115
_ClientState
MQTT Client State Type.
Definition: aws_iot_mqtt_client.h:185
enum _ClientState ClientState
MQTT Client State Type.
Network Structure.
Definition: network_interface.h:61
Publish Message Parameters Type.
Definition: aws_iot_mqtt_client.h:82
struct _MessageHandlers MessageHandlers
MQTT Message Handler.
uint16_t port
MQTT service listening port.
Definition: aws_iot_mqtt_client.h:164
uint32_t aws_iot_mqtt_get_network_disconnected_count(AWS_IoT_Client *pClient)
Get count of Network Disconnects.
Definition: aws_iot_mqtt_client.c:290
uint16_t usernameLen
Username Length. 16 bit unsigned integer.
Definition: aws_iot_mqtt_client.h:137
MQTT 3.1.1 (protocol message byte = 4)
Definition: aws_iot_mqtt_client.h:98
char * pTopicName
The LWT topic to which the LWT message will be published.
Definition: aws_iot_mqtt_client.h:110
uint16_t topicNameLen
The length of the LWT topic, 16 bit unsinged integer.
Definition: aws_iot_mqtt_client.h:111
bool isCleanSession
MQTT clean session. True = this session is to be treated as clean. Previous server state is cleared a...
Definition: aws_iot_mqtt_client.h:133
IoT_Error_t aws_iot_mqtt_set_connect_params(AWS_IoT_Client *pClient, IoT_Client_Connect_Params *pNewConnectParams)
Set the connection parameters for the IoT Client.
Definition: aws_iot_mqtt_client.c:124
struct _ClientStatus ClientStatus
MQTT Client Status.
void * disconnectHandlerData
Data to pass as argument when disconnect handler is called.
Definition: aws_iot_mqtt_client.h:175
char * pUsername
Not used in the AWS IoT Service, will need to be cstring if used.
Definition: aws_iot_mqtt_client.h:136
char * pDevicePrivateKeyLocation
Pointer to a string defining the device private key file (full file, not path)
Definition: aws_iot_mqtt_client.h:167
uint16_t keepAliveIntervalInSec
MQTT keep alive interval in seconds. Defines inactivity time allowed before determining the connectio...
Definition: aws_iot_mqtt_client.h:132
char * pPassword
Not used in the AWS IoT Service, will need to be cstring if used.
Definition: aws_iot_mqtt_client.h:138
MQTT Client Data.
Definition: aws_iot_mqtt_client.h:247
MQTT Initialization Parameters.
Definition: aws_iot_mqtt_client.h:161
IoT_MQTT_Will_Options will
MQTT LWT parameters.
Definition: aws_iot_mqtt_client.h:135
IoT_Error_t aws_iot_mqtt_autoreconnect_set_status(AWS_IoT_Client *pClient, bool newStatus)
Enable or Disable AutoReconnect on Network Disconnect.
Definition: aws_iot_mqtt_client.c:269
uint32_t tlsHandshakeTimeout_ms
TLS handshake timeout. In milliseconds.
Definition: aws_iot_mqtt_client.h:172
void aws_iot_mqtt_reset_network_disconnected_count(AWS_IoT_Client *pClient)
Reset Network Disconnect conter.
Definition: aws_iot_mqtt_client.c:294
MQTT Message Handler.
Definition: aws_iot_mqtt_client.h:219
bool isRetained
NOT supported. The retained flag for the LWT message (see MQTTAsync_message.retained) ...
Definition: aws_iot_mqtt_client.h:114
struct _ClientData ClientData
MQTT Client Data.
char * pClientID
Pointer to a string defining the MQTT client ID (this needs to be unique per device across your AWS a...
Definition: aws_iot_mqtt_client.h:130
char * pDeviceCertLocation
Pointer to a string defining the device identity certificate file (full file, not path) ...
Definition: aws_iot_mqtt_client.h:166
char * pRootCALocation
Pointer to a string defining the Root CA file (full file, not path)
Definition: aws_iot_mqtt_client.h:165
Last Will and Testament Definition.
Definition: aws_iot_mqtt_client.h:108
MQTT Client Status.
Definition: aws_iot_mqtt_client.h:234
char * pHostURL
Pointer to a string defining the endpoint for the MQTT service.
Definition: aws_iot_mqtt_client.h:163
uint16_t id
Message sequence identifier. Handled automatically by the MQTT client.
Definition: aws_iot_mqtt_client.h:86
Network interface definition for MQTT client.
QoS
Quality of Service Type.
Definition: aws_iot_mqtt_client.h:71
uint16_t aws_iot_mqtt_get_next_packet_id(AWS_IoT_Client *pClient)
What is the next available packet Id.
Definition: aws_iot_mqtt_client.c:217
uint8_t isRetained
Retained messages are NOT supported by the AWS IoT Service at the time of this SDK release...
Definition: aws_iot_mqtt_client.h:84