Changes to enabled on-line compiler

Committer:
JMF
Date:
Wed May 30 20:59:51 2018 +0000
Revision:
0:082731ede69f
Initial commit

Who changed what in which revision?

UserRevisionLine numberNew contents of line
JMF 0:082731ede69f 1 /*
JMF 0:082731ede69f 2 * Copyright 2010-2015 Amazon.com, Inc. or its affiliates. All Rights Reserved.
JMF 0:082731ede69f 3 *
JMF 0:082731ede69f 4 * Licensed under the Apache License, Version 2.0 (the "License").
JMF 0:082731ede69f 5 * You may not use this file except in compliance with the License.
JMF 0:082731ede69f 6 * A copy of the License is located at
JMF 0:082731ede69f 7 *
JMF 0:082731ede69f 8 * http://aws.amazon.com/apache2.0
JMF 0:082731ede69f 9 *
JMF 0:082731ede69f 10 * or in the "license" file accompanying this file. This file is distributed
JMF 0:082731ede69f 11 * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
JMF 0:082731ede69f 12 * express or implied. See the License for the specific language governing
JMF 0:082731ede69f 13 * permissions and limitations under the License.
JMF 0:082731ede69f 14 */
JMF 0:082731ede69f 15
JMF 0:082731ede69f 16 // Based on Eclipse Paho.
JMF 0:082731ede69f 17 /*******************************************************************************
JMF 0:082731ede69f 18 * Copyright (c) 2014 IBM Corp.
JMF 0:082731ede69f 19 *
JMF 0:082731ede69f 20 * All rights reserved. This program and the accompanying materials
JMF 0:082731ede69f 21 * are made available under the terms of the Eclipse Public License v1.0
JMF 0:082731ede69f 22 * and Eclipse Distribution License v1.0 which accompany this distribution.
JMF 0:082731ede69f 23 *
JMF 0:082731ede69f 24 * The Eclipse Public License is available at
JMF 0:082731ede69f 25 * http://www.eclipse.org/legal/epl-v10.html
JMF 0:082731ede69f 26 * and the Eclipse Distribution License is available at
JMF 0:082731ede69f 27 * http://www.eclipse.org/org/documents/edl-v10.php.
JMF 0:082731ede69f 28 *
JMF 0:082731ede69f 29 * Contributors:
JMF 0:082731ede69f 30 * Ian Craggs - initial API and implementation and/or initial documentation
JMF 0:082731ede69f 31 * Xiang Rong - 442039 Add makefile to Embedded C client
JMF 0:082731ede69f 32 *******************************************************************************/
JMF 0:082731ede69f 33
JMF 0:082731ede69f 34 /**
JMF 0:082731ede69f 35 * @file aws_iot_mqtt_client.h
JMF 0:082731ede69f 36 * @brief Client definition for MQTT
JMF 0:082731ede69f 37 */
JMF 0:082731ede69f 38
JMF 0:082731ede69f 39 #ifndef AWS_IOT_SDK_SRC_IOT_MQTT_CLIENT_H
JMF 0:082731ede69f 40 #define AWS_IOT_SDK_SRC_IOT_MQTT_CLIENT_H
JMF 0:082731ede69f 41
JMF 0:082731ede69f 42 #ifdef __cplusplus
JMF 0:082731ede69f 43 extern "C" {
JMF 0:082731ede69f 44 #endif
JMF 0:082731ede69f 45
JMF 0:082731ede69f 46 /* Library Header files */
JMF 0:082731ede69f 47 #include "stdio.h"
JMF 0:082731ede69f 48 #include "stdbool.h"
JMF 0:082731ede69f 49 #include "stdint.h"
JMF 0:082731ede69f 50 #include "stddef.h"
JMF 0:082731ede69f 51
JMF 0:082731ede69f 52 /* AWS Specific header files */
JMF 0:082731ede69f 53 #include "aws_iot_error.h"
JMF 0:082731ede69f 54 #include "aws_iot_config.h"
JMF 0:082731ede69f 55
JMF 0:082731ede69f 56 /* Platform specific implementation header files */
JMF 0:082731ede69f 57 #include "network_interface.h"
JMF 0:082731ede69f 58 #include "timer_interface.h"
JMF 0:082731ede69f 59
JMF 0:082731ede69f 60 #ifdef _ENABLE_THREAD_SUPPORT_
JMF 0:082731ede69f 61 #include "threads_interface.h"
JMF 0:082731ede69f 62 #endif
JMF 0:082731ede69f 63
JMF 0:082731ede69f 64 #define MAX_PACKET_ID 65535
JMF 0:082731ede69f 65
JMF 0:082731ede69f 66 typedef struct _Client AWS_IoT_Client;
JMF 0:082731ede69f 67
JMF 0:082731ede69f 68 /**
JMF 0:082731ede69f 69 * @brief Quality of Service Type
JMF 0:082731ede69f 70 *
JMF 0:082731ede69f 71 * Defining a QoS type.
JMF 0:082731ede69f 72 * @note QoS 2 is \b NOT supported by the AWS IoT Service at the time of this SDK release.
JMF 0:082731ede69f 73 *
JMF 0:082731ede69f 74 */
JMF 0:082731ede69f 75 typedef enum QoS {
JMF 0:082731ede69f 76 QOS0 = 0,
JMF 0:082731ede69f 77 QOS1 = 1
JMF 0:082731ede69f 78 } QoS;
JMF 0:082731ede69f 79
JMF 0:082731ede69f 80 /**
JMF 0:082731ede69f 81 * @brief Publish Message Parameters Type
JMF 0:082731ede69f 82 *
JMF 0:082731ede69f 83 * Defines a type for MQTT Publish messages. Used for both incoming and out going messages
JMF 0:082731ede69f 84 *
JMF 0:082731ede69f 85 */
JMF 0:082731ede69f 86 typedef struct {
JMF 0:082731ede69f 87 QoS qos; ///< Message Quality of Service
JMF 0:082731ede69f 88 uint8_t isRetained; ///< Retained messages are \b NOT supported by the AWS IoT Service at the time of this SDK release.
JMF 0:082731ede69f 89 uint8_t isDup; ///< Is this message a duplicate QoS > 0 message? Handled automatically by the MQTT client.
JMF 0:082731ede69f 90 uint16_t id; ///< Message sequence identifier. Handled automatically by the MQTT client.
JMF 0:082731ede69f 91 void *payload; ///< Pointer to MQTT message payload (bytes).
JMF 0:082731ede69f 92 size_t payloadLen; ///< Length of MQTT payload.
JMF 0:082731ede69f 93 } IoT_Publish_Message_Params;
JMF 0:082731ede69f 94
JMF 0:082731ede69f 95 /**
JMF 0:082731ede69f 96 * @brief MQTT Version Type
JMF 0:082731ede69f 97 *
JMF 0:082731ede69f 98 * Defining an MQTT version type. Only 3.1.1 is supported at this time
JMF 0:082731ede69f 99 *
JMF 0:082731ede69f 100 */
JMF 0:082731ede69f 101 typedef enum {
JMF 0:082731ede69f 102 MQTT_3_1_1 = 4 ///< MQTT 3.1.1 (protocol message byte = 4)
JMF 0:082731ede69f 103 } MQTT_Ver_t;
JMF 0:082731ede69f 104
JMF 0:082731ede69f 105 /**
JMF 0:082731ede69f 106 * @brief Last Will and Testament Definition
JMF 0:082731ede69f 107 *
JMF 0:082731ede69f 108 * Defining a type for the MQTT "Last Will and Testament" (LWT) parameters.
JMF 0:082731ede69f 109 * @note Retained messages are \b NOT supported by the AWS IoT Service at the time of this SDK release.
JMF 0:082731ede69f 110 *
JMF 0:082731ede69f 111 */
JMF 0:082731ede69f 112 typedef struct {
JMF 0:082731ede69f 113 char struct_id[4]; ///< The eyecatcher for this structure. must be MQTW
JMF 0:082731ede69f 114 char *pTopicName; ///< The LWT topic to which the LWT message will be published
JMF 0:082731ede69f 115 uint16_t topicNameLen; ///< The length of the LWT topic, 16 bit unsinged integer
JMF 0:082731ede69f 116 char *pMessage; ///< Message to be delivered as LWT
JMF 0:082731ede69f 117 uint16_t msgLen; ///< The length of the Message, 16 bit unsinged integer
JMF 0:082731ede69f 118 bool isRetained; ///< NOT supported. The retained flag for the LWT message (see MQTTAsync_message.retained)
JMF 0:082731ede69f 119 QoS qos; ///< QoS of LWT message
JMF 0:082731ede69f 120 } IoT_MQTT_Will_Options;
JMF 0:082731ede69f 121 extern const IoT_MQTT_Will_Options iotMqttWillOptionsDefault;
JMF 0:082731ede69f 122
JMF 0:082731ede69f 123 #define IoT_MQTT_Will_Options_Initializer { {'M', 'Q', 'T', 'W'}, NULL, 0, NULL, 0, false, QOS0 }
JMF 0:082731ede69f 124
JMF 0:082731ede69f 125 /**
JMF 0:082731ede69f 126 * @brief MQTT Connection Parameters
JMF 0:082731ede69f 127 *
JMF 0:082731ede69f 128 * Defining a type for MQTT connection parameters. Passed into client when establishing a connection.
JMF 0:082731ede69f 129 *
JMF 0:082731ede69f 130 */
JMF 0:082731ede69f 131 typedef struct {
JMF 0:082731ede69f 132 char struct_id[4]; ///< The eyecatcher for this structure. must be MQTC
JMF 0:082731ede69f 133 MQTT_Ver_t MQTTVersion; ///< Desired MQTT version used during connection
JMF 0:082731ede69f 134 char *pClientID; ///< Pointer to a string defining the MQTT client ID (this needs to be unique \b per \b device across your AWS account)
JMF 0:082731ede69f 135 uint16_t clientIDLen; ///< Client Id Length. 16 bit unsigned integer
JMF 0:082731ede69f 136 uint16_t keepAliveIntervalInSec; ///< MQTT keep alive interval in seconds. Defines inactivity time allowed before determining the connection has been lost.
JMF 0:082731ede69f 137 bool isCleanSession; ///< MQTT clean session. True = this session is to be treated as clean. Previous server state is cleared and no stated is retained from this connection.
JMF 0:082731ede69f 138 bool isWillMsgPresent; ///< Is there a LWT associated with this connection?
JMF 0:082731ede69f 139 IoT_MQTT_Will_Options will; ///< MQTT LWT parameters.
JMF 0:082731ede69f 140 char *pUsername; ///< Not used in the AWS IoT Service, will need to be cstring if used
JMF 0:082731ede69f 141 uint16_t usernameLen; ///< Username Length. 16 bit unsigned integer
JMF 0:082731ede69f 142 char *pPassword; ///< Not used in the AWS IoT Service, will need to be cstring if used
JMF 0:082731ede69f 143 uint16_t passwordLen; ///< Password Length. 16 bit unsigned integer
JMF 0:082731ede69f 144 } IoT_Client_Connect_Params;
JMF 0:082731ede69f 145 extern const IoT_Client_Connect_Params iotClientConnectParamsDefault;
JMF 0:082731ede69f 146
JMF 0:082731ede69f 147 #define IoT_Client_Connect_Params_initializer { {'M', 'Q', 'T', 'C'}, MQTT_3_1_1, NULL, 0, 60, true, false, \
JMF 0:082731ede69f 148 IoT_MQTT_Will_Options_Initializer, NULL, 0, NULL, 0 }
JMF 0:082731ede69f 149
JMF 0:082731ede69f 150 /**
JMF 0:082731ede69f 151 * @brief Disconnect Callback Handler Type
JMF 0:082731ede69f 152 *
JMF 0:082731ede69f 153 * Defining a TYPE for definition of disconnect callback function pointers.
JMF 0:082731ede69f 154 *
JMF 0:082731ede69f 155 */
JMF 0:082731ede69f 156 typedef void (*iot_disconnect_handler)(AWS_IoT_Client *, void *);
JMF 0:082731ede69f 157
JMF 0:082731ede69f 158 /**
JMF 0:082731ede69f 159 * @brief MQTT Initialization Parameters
JMF 0:082731ede69f 160 *
JMF 0:082731ede69f 161 * Defining a type for MQTT initialization parameters.
JMF 0:082731ede69f 162 * Passed into client when to initialize the client
JMF 0:082731ede69f 163 *
JMF 0:082731ede69f 164 */
JMF 0:082731ede69f 165 typedef struct {
JMF 0:082731ede69f 166 bool enableAutoReconnect; ///< Set to true to enable auto reconnect
JMF 0:082731ede69f 167 char *pHostURL; ///< Pointer to a string defining the endpoint for the MQTT service
JMF 0:082731ede69f 168 uint16_t port; ///< MQTT service listening port
JMF 0:082731ede69f 169 char *pRootCALocation; ///< Pointer to a string defining the Root CA file (full file, not path)
JMF 0:082731ede69f 170 char *pDeviceCertLocation; ///< Pointer to a string defining the device identity certificate file (full file, not path)
JMF 0:082731ede69f 171 char *pDevicePrivateKeyLocation; ///< Pointer to a string defining the device private key file (full file, not path)
JMF 0:082731ede69f 172 uint32_t mqttPacketTimeout_ms; ///< Timeout for reading a complete MQTT packet. In milliseconds
JMF 0:082731ede69f 173 uint32_t mqttCommandTimeout_ms; ///< Timeout for MQTT blocking calls. In milliseconds
JMF 0:082731ede69f 174 uint32_t tlsHandshakeTimeout_ms; ///< TLS handshake timeout. In milliseconds
JMF 0:082731ede69f 175 bool isSSLHostnameVerify; ///< Client should perform server certificate hostname validation
JMF 0:082731ede69f 176 iot_disconnect_handler disconnectHandler; ///< Callback to be invoked upon connection loss
JMF 0:082731ede69f 177 void *disconnectHandlerData; ///< Data to pass as argument when disconnect handler is called
JMF 0:082731ede69f 178 #ifdef _ENABLE_THREAD_SUPPORT_
JMF 0:082731ede69f 179 bool isBlockOnThreadLockEnabled; ///< Timeout for Thread blocking calls. Set to 0 to block until lock is obtained. In milliseconds
JMF 0:082731ede69f 180 #endif
JMF 0:082731ede69f 181 } IoT_Client_Init_Params;
JMF 0:082731ede69f 182 extern const IoT_Client_Init_Params iotClientInitParamsDefault;
JMF 0:082731ede69f 183
JMF 0:082731ede69f 184 #ifdef _ENABLE_THREAD_SUPPORT_
JMF 0:082731ede69f 185 #define IoT_Client_Init_Params_initializer { true, NULL, 0, NULL, NULL, NULL, 2000, 20000, 5000, true, NULL, NULL, false }
JMF 0:082731ede69f 186 #else
JMF 0:082731ede69f 187 #define IoT_Client_Init_Params_initializer { true, NULL, 0, NULL, NULL, NULL, 2000, 20000, 5000, true, NULL, NULL }
JMF 0:082731ede69f 188 #endif
JMF 0:082731ede69f 189
JMF 0:082731ede69f 190 /**
JMF 0:082731ede69f 191 * @brief MQTT Client State Type
JMF 0:082731ede69f 192 *
JMF 0:082731ede69f 193 * Defining a type for MQTT Client State
JMF 0:082731ede69f 194 *
JMF 0:082731ede69f 195 */
JMF 0:082731ede69f 196 typedef enum _ClientState {
JMF 0:082731ede69f 197 CLIENT_STATE_INVALID = 0,
JMF 0:082731ede69f 198 CLIENT_STATE_INITIALIZED = 1,
JMF 0:082731ede69f 199 CLIENT_STATE_CONNECTING = 2,
JMF 0:082731ede69f 200 CLIENT_STATE_CONNECTED_IDLE = 3,
JMF 0:082731ede69f 201 CLIENT_STATE_CONNECTED_YIELD_IN_PROGRESS = 4,
JMF 0:082731ede69f 202 CLIENT_STATE_CONNECTED_PUBLISH_IN_PROGRESS = 5,
JMF 0:082731ede69f 203 CLIENT_STATE_CONNECTED_SUBSCRIBE_IN_PROGRESS = 6,
JMF 0:082731ede69f 204 CLIENT_STATE_CONNECTED_UNSUBSCRIBE_IN_PROGRESS = 7,
JMF 0:082731ede69f 205 CLIENT_STATE_CONNECTED_RESUBSCRIBE_IN_PROGRESS = 8,
JMF 0:082731ede69f 206 CLIENT_STATE_CONNECTED_WAIT_FOR_CB_RETURN = 9,
JMF 0:082731ede69f 207 CLIENT_STATE_DISCONNECTING = 10,
JMF 0:082731ede69f 208 CLIENT_STATE_DISCONNECTED_ERROR = 11,
JMF 0:082731ede69f 209 CLIENT_STATE_DISCONNECTED_MANUALLY = 12,
JMF 0:082731ede69f 210 CLIENT_STATE_PENDING_RECONNECT = 13
JMF 0:082731ede69f 211 } ClientState;
JMF 0:082731ede69f 212
JMF 0:082731ede69f 213 /**
JMF 0:082731ede69f 214 * @brief Application Callback Handler Type
JMF 0:082731ede69f 215 *
JMF 0:082731ede69f 216 * Defining a TYPE for definition of application callback function pointers.
JMF 0:082731ede69f 217 * Used to send incoming data to the application
JMF 0:082731ede69f 218 *
JMF 0:082731ede69f 219 */
JMF 0:082731ede69f 220 typedef void (*pApplicationHandler_t)(AWS_IoT_Client *pClient, char *pTopicName, uint16_t topicNameLen,
JMF 0:082731ede69f 221 IoT_Publish_Message_Params *pParams, void *pClientData);
JMF 0:082731ede69f 222
JMF 0:082731ede69f 223 /**
JMF 0:082731ede69f 224 * @brief MQTT Message Handler
JMF 0:082731ede69f 225 *
JMF 0:082731ede69f 226 * Defining a type for MQTT Message Handlers.
JMF 0:082731ede69f 227 * Used to pass incoming data back to the application
JMF 0:082731ede69f 228 *
JMF 0:082731ede69f 229 */
JMF 0:082731ede69f 230 typedef struct _MessageHandlers {
JMF 0:082731ede69f 231 const char *topicName;
JMF 0:082731ede69f 232 uint16_t topicNameLen;
JMF 0:082731ede69f 233 QoS qos;
JMF 0:082731ede69f 234 pApplicationHandler_t pApplicationHandler;
JMF 0:082731ede69f 235 void *pApplicationHandlerData;
JMF 0:082731ede69f 236 } MessageHandlers; /* Message handlers are indexed by subscription topic */
JMF 0:082731ede69f 237
JMF 0:082731ede69f 238 /**
JMF 0:082731ede69f 239 * @brief MQTT Client Status
JMF 0:082731ede69f 240 *
JMF 0:082731ede69f 241 * Defining a type for MQTT Client Status
JMF 0:082731ede69f 242 * Contains information about the state of the MQTT Client
JMF 0:082731ede69f 243 *
JMF 0:082731ede69f 244 */
JMF 0:082731ede69f 245 typedef struct _ClientStatus {
JMF 0:082731ede69f 246 ClientState clientState;
JMF 0:082731ede69f 247 bool isPingOutstanding;
JMF 0:082731ede69f 248 bool isAutoReconnectEnabled;
JMF 0:082731ede69f 249 } ClientStatus;
JMF 0:082731ede69f 250
JMF 0:082731ede69f 251 /**
JMF 0:082731ede69f 252 * @brief MQTT Client Data
JMF 0:082731ede69f 253 *
JMF 0:082731ede69f 254 * Defining a type for MQTT Client Data
JMF 0:082731ede69f 255 * Contains data used by the MQTT Client
JMF 0:082731ede69f 256 *
JMF 0:082731ede69f 257 */
JMF 0:082731ede69f 258 typedef struct _ClientData {
JMF 0:082731ede69f 259 uint16_t nextPacketId;
JMF 0:082731ede69f 260
JMF 0:082731ede69f 261 uint32_t packetTimeoutMs;
JMF 0:082731ede69f 262 uint32_t commandTimeoutMs;
JMF 0:082731ede69f 263 uint16_t keepAliveInterval;
JMF 0:082731ede69f 264 uint32_t currentReconnectWaitInterval;
JMF 0:082731ede69f 265 uint32_t counterNetworkDisconnected;
JMF 0:082731ede69f 266
JMF 0:082731ede69f 267 /* The below values are initialized with the
JMF 0:082731ede69f 268 * lengths of the TX/RX buffers and never modified
JMF 0:082731ede69f 269 * afterwards */
JMF 0:082731ede69f 270 size_t writeBufSize;
JMF 0:082731ede69f 271 size_t readBufSize;
JMF 0:082731ede69f 272
JMF 0:082731ede69f 273 unsigned char writeBuf[AWS_IOT_MQTT_TX_BUF_LEN];
JMF 0:082731ede69f 274 unsigned char readBuf[AWS_IOT_MQTT_RX_BUF_LEN];
JMF 0:082731ede69f 275
JMF 0:082731ede69f 276 #ifdef _ENABLE_THREAD_SUPPORT_
JMF 0:082731ede69f 277 bool isBlockOnThreadLockEnabled;
JMF 0:082731ede69f 278 IoT_Mutex_t state_change_mutex;
JMF 0:082731ede69f 279 IoT_Mutex_t tls_read_mutex;
JMF 0:082731ede69f 280 IoT_Mutex_t tls_write_mutex;
JMF 0:082731ede69f 281 #endif
JMF 0:082731ede69f 282
JMF 0:082731ede69f 283 IoT_Client_Connect_Params options;
JMF 0:082731ede69f 284
JMF 0:082731ede69f 285 MessageHandlers messageHandlers[AWS_IOT_MQTT_NUM_SUBSCRIBE_HANDLERS];
JMF 0:082731ede69f 286 iot_disconnect_handler disconnectHandler;
JMF 0:082731ede69f 287
JMF 0:082731ede69f 288 void *disconnectHandlerData;
JMF 0:082731ede69f 289 } ClientData;
JMF 0:082731ede69f 290
JMF 0:082731ede69f 291 /**
JMF 0:082731ede69f 292 * @brief MQTT Client
JMF 0:082731ede69f 293 *
JMF 0:082731ede69f 294 * Defining a type for MQTT Client
JMF 0:082731ede69f 295 *
JMF 0:082731ede69f 296 */
JMF 0:082731ede69f 297 struct _Client {
JMF 0:082731ede69f 298 awsTimer pingTimer;
JMF 0:082731ede69f 299 awsTimer reconnectDelayTimer;
JMF 0:082731ede69f 300
JMF 0:082731ede69f 301 ClientStatus clientStatus;
JMF 0:082731ede69f 302 ClientData clientData;
JMF 0:082731ede69f 303 Network networkStack;
JMF 0:082731ede69f 304 };
JMF 0:082731ede69f 305
JMF 0:082731ede69f 306 /**
JMF 0:082731ede69f 307 * @brief What is the next available packet Id
JMF 0:082731ede69f 308 *
JMF 0:082731ede69f 309 * Called to retrieve the next packet id to be used for outgoing packets.
JMF 0:082731ede69f 310 * Automatically increments the last sent packet id variable
JMF 0:082731ede69f 311 *
JMF 0:082731ede69f 312 * @param pClient Reference to the IoT Client
JMF 0:082731ede69f 313 *
JMF 0:082731ede69f 314 * @return next packet id as a 16 bit unsigned integer
JMF 0:082731ede69f 315 */
JMF 0:082731ede69f 316 uint16_t aws_iot_mqtt_get_next_packet_id(AWS_IoT_Client *pClient);
JMF 0:082731ede69f 317
JMF 0:082731ede69f 318 /**
JMF 0:082731ede69f 319 * @brief Set the connection parameters for the IoT Client
JMF 0:082731ede69f 320 *
JMF 0:082731ede69f 321 * Called to set the connection parameters for the IoT Client.
JMF 0:082731ede69f 322 * Used to update the connection parameters provided before the last connect.
JMF 0:082731ede69f 323 * Won't take effect until the next time connect is called
JMF 0:082731ede69f 324 *
JMF 0:082731ede69f 325 * @param pClient Reference to the IoT Client
JMF 0:082731ede69f 326 * @param pNewConnectParams Reference to the new Connection Parameters structure
JMF 0:082731ede69f 327 *
JMF 0:082731ede69f 328 * @return IoT_Error_t Type defining successful/failed API call
JMF 0:082731ede69f 329 */
JMF 0:082731ede69f 330 IoT_Error_t aws_iot_mqtt_set_connect_params(AWS_IoT_Client *pClient, IoT_Client_Connect_Params *pNewConnectParams);
JMF 0:082731ede69f 331
JMF 0:082731ede69f 332 /**
JMF 0:082731ede69f 333 * @brief Is the MQTT client currently connected?
JMF 0:082731ede69f 334 *
JMF 0:082731ede69f 335 * Called to determine if the MQTT client is currently connected. Used to support logic
JMF 0:082731ede69f 336 * in the device application around reconnecting and managing offline state.
JMF 0:082731ede69f 337 *
JMF 0:082731ede69f 338 * @param pClient Reference to the IoT Client
JMF 0:082731ede69f 339 *
JMF 0:082731ede69f 340 * @return true = connected, false = not currently connected
JMF 0:082731ede69f 341 */
JMF 0:082731ede69f 342 bool aws_iot_mqtt_is_client_connected(AWS_IoT_Client *pClient);
JMF 0:082731ede69f 343
JMF 0:082731ede69f 344 /**
JMF 0:082731ede69f 345 * @brief Get the current state of the client
JMF 0:082731ede69f 346 *
JMF 0:082731ede69f 347 * Called to get the current state of the client
JMF 0:082731ede69f 348 *
JMF 0:082731ede69f 349 * @param pClient Reference to the IoT Client
JMF 0:082731ede69f 350 *
JMF 0:082731ede69f 351 * @return ClientState value equal to the current state of the client
JMF 0:082731ede69f 352 */
JMF 0:082731ede69f 353 ClientState aws_iot_mqtt_get_client_state(AWS_IoT_Client *pClient);
JMF 0:082731ede69f 354
JMF 0:082731ede69f 355 /**
JMF 0:082731ede69f 356 * @brief Is the MQTT client set to reconnect automatically?
JMF 0:082731ede69f 357 *
JMF 0:082731ede69f 358 * Called to determine if the MQTT client is set to reconnect automatically.
JMF 0:082731ede69f 359 * Used to support logic in the device application around reconnecting
JMF 0:082731ede69f 360 *
JMF 0:082731ede69f 361 * @param pClient Reference to the IoT Client
JMF 0:082731ede69f 362 *
JMF 0:082731ede69f 363 * @return true = enabled, false = disabled
JMF 0:082731ede69f 364 */
JMF 0:082731ede69f 365 bool aws_iot_is_autoreconnect_enabled(AWS_IoT_Client *pClient);
JMF 0:082731ede69f 366
JMF 0:082731ede69f 367 /**
JMF 0:082731ede69f 368 * @brief Set the IoT Client disconnect handler
JMF 0:082731ede69f 369 *
JMF 0:082731ede69f 370 * Called to set the IoT Client disconnect handler
JMF 0:082731ede69f 371 * The disconnect handler is called whenever the client disconnects with error
JMF 0:082731ede69f 372 *
JMF 0:082731ede69f 373 * @param pClient Reference to the IoT Client
JMF 0:082731ede69f 374 * @param pConnectHandler Reference to the new Disconnect Handler
JMF 0:082731ede69f 375 * @param pDisconnectHandlerData Reference to the data to be passed as argument when disconnect handler is called
JMF 0:082731ede69f 376 *
JMF 0:082731ede69f 377 * @return IoT_Error_t Type defining successful/failed API call
JMF 0:082731ede69f 378 */
JMF 0:082731ede69f 379 IoT_Error_t aws_iot_mqtt_set_disconnect_handler(AWS_IoT_Client *pClient, iot_disconnect_handler pDisconnectHandler,
JMF 0:082731ede69f 380 void *pDisconnectHandlerData);
JMF 0:082731ede69f 381
JMF 0:082731ede69f 382 /**
JMF 0:082731ede69f 383 * @brief Enable or Disable AutoReconnect on Network Disconnect
JMF 0:082731ede69f 384 *
JMF 0:082731ede69f 385 * Called to enable or disabled the auto reconnect features provided with the SDK
JMF 0:082731ede69f 386 *
JMF 0:082731ede69f 387 * @param pClient Reference to the IoT Client
JMF 0:082731ede69f 388 * @param newStatus set to true for enabling and false for disabling
JMF 0:082731ede69f 389 *
JMF 0:082731ede69f 390 * @return IoT_Error_t Type defining successful/failed API call
JMF 0:082731ede69f 391 */
JMF 0:082731ede69f 392 IoT_Error_t aws_iot_mqtt_autoreconnect_set_status(AWS_IoT_Client *pClient, bool newStatus);
JMF 0:082731ede69f 393
JMF 0:082731ede69f 394 /**
JMF 0:082731ede69f 395 * @brief Get count of Network Disconnects
JMF 0:082731ede69f 396 *
JMF 0:082731ede69f 397 * Called to get the number of times a network disconnect occurred due to errors
JMF 0:082731ede69f 398 *
JMF 0:082731ede69f 399 * @param pClient Reference to the IoT Client
JMF 0:082731ede69f 400 *
JMF 0:082731ede69f 401 * @return uint32_t the disconnect count
JMF 0:082731ede69f 402 */
JMF 0:082731ede69f 403 uint32_t aws_iot_mqtt_get_network_disconnected_count(AWS_IoT_Client *pClient);
JMF 0:082731ede69f 404
JMF 0:082731ede69f 405 /**
JMF 0:082731ede69f 406 * @brief Reset Network Disconnect conter
JMF 0:082731ede69f 407 *
JMF 0:082731ede69f 408 * Called to reset the Network Disconnect counter to zero
JMF 0:082731ede69f 409 *
JMF 0:082731ede69f 410 * @param pClient Reference to the IoT Client
JMF 0:082731ede69f 411 */
JMF 0:082731ede69f 412 void aws_iot_mqtt_reset_network_disconnected_count(AWS_IoT_Client *pClient);
JMF 0:082731ede69f 413
JMF 0:082731ede69f 414 #ifdef __cplusplus
JMF 0:082731ede69f 415 }
JMF 0:082731ede69f 416 #endif
JMF 0:082731ede69f 417
JMF 0:082731ede69f 418 #endif