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