AWS IoT Embedded C Device SDK
aws_iot_mqtt_interface.h
Go to the documentation of this file.
1 /*
2  * Copyright 2010-2015 Amazon.com, Inc. or its affiliates. All Rights Reserved.
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License").
5  * You may not use this file except in compliance with the License.
6  * A copy of the License is located at
7  *
8  * http://aws.amazon.com/apache2.0
9  *
10  * or in the "license" file accompanying this file. This file is distributed
11  * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
12  * express or implied. See the License for the specific language governing
13  * permissions and limitations under the License.
14  */
15 
21 #ifndef AWS_IOT_SDK_SRC_IOT_MQTT_INTERFACE_H_
22 #define AWS_IOT_SDK_SRC_IOT_MQTT_INTERFACE_H_
23 
24 #include "stddef.h"
25 #include "stdbool.h"
26 #include "stdint.h"
27 #include "aws_iot_error.h"
28 
35 typedef enum {
36  MQTT_3_1 = 3,
38 } MQTT_Ver_t;
39 
47 typedef enum {
51 } QoSLevel;
52 
60 typedef struct {
61  const char *pTopicName;
62  const char *pMessage;
63  bool isRetained;
66 extern const MQTTwillOptions MQTTwillOptionsDefault;
67 
74 typedef void (*iot_disconnect_handler)(void);
75 
82 typedef struct {
84  char *pHostURL;
85  uint16_t port;
89  char *pClientID;
90  char *pUserName;
91  char *pPassword;
102 extern const MQTTConnectParams MQTTConnectParamsDefault;
103 
110 typedef struct {
112  bool isRetained;
113  bool isDuplicate;
114  uint16_t id;
115  void *pPayload;
116  uint32_t PayloadLen;
118 extern const MQTTMessageParams MQTTMessageParamsDefault;
125 typedef struct {
126  char *pTopicName;
127  uint16_t TopicNameLen;
130 extern const MQTTCallbackParams MQTTCallbackParamsDefault;
131 
140 typedef int32_t (*iot_message_handler)(MQTTCallbackParams params);
141 
148 typedef struct {
149  char *pTopic;
153 extern const MQTTSubscribeParams MQTTSubscribeParamsDefault;
154 
161 typedef struct {
162  char *pTopic;
165 extern const MQTTPublishParams MQTTPublishParamsDefault;
166 
176 
189 
201 
213 
225 
234 
250 IoT_Error_t aws_iot_mqtt_yield(int timeout);
251 
260 bool aws_iot_is_mqtt_connected(void);
261 
271 
282 
283 typedef IoT_Error_t (*pConnectFunc_t)(MQTTConnectParams *pParams);
284 typedef IoT_Error_t (*pPublishFunc_t)(MQTTPublishParams *pParams);
285 typedef IoT_Error_t (*pSubscribeFunc_t)(MQTTSubscribeParams *pParams);
286 typedef IoT_Error_t (*pUnsubscribeFunc_t)(char *pTopic);
287 typedef IoT_Error_t (*pDisconnectFunc_t)(void);
288 typedef IoT_Error_t (*pYieldFunc_t)(int timeout);
289 typedef bool (*pIsConnectedFunc_t)(void);
290 typedef bool (*pIsAutoReconnectEnabledFunc_t)(void);
291 typedef IoT_Error_t (*pReconnectFunc_t)();
292 typedef IoT_Error_t (*pSetAutoReconnectStatusFunc_t)(bool);
301 typedef struct{
302  pConnectFunc_t connect;
303  pPublishFunc_t publish;
304  pSubscribeFunc_t subscribe;
305  pUnsubscribeFunc_t unsubscribe;
306  pDisconnectFunc_t disconnect;
307  pYieldFunc_t yield;
308  pIsConnectedFunc_t isConnected;
309  pReconnectFunc_t reconnect;
310  pIsAutoReconnectEnabledFunc_t isAutoReconnectEnabled;
311  pSetAutoReconnectStatusFunc_t setAutoReconnectStatus;
312 }MQTTClient_t;
313 
314 
323 void aws_iot_mqtt_init(MQTTClient_t *pClient);
324 
325 
326 #endif /* AWS_IOT_SDK_SRC_IOT_MQTT_INTERFACE_H_ */
bool isCleansession
MQTT clean session. True = this session is to be treated as clean. Previous server state is cleared a...
Definition: aws_iot_mqtt_interface.h:94
uint16_t id
Message sequence identifier. Handled automatically by the MQTT client.
Definition: aws_iot_mqtt_interface.h:114
void(* iot_disconnect_handler)(void)
Disconnect Callback Handler Type.
Definition: aws_iot_mqtt_interface.h:74
MQTTMessageParams MessageParams
Parameters defining the message to be published.
Definition: aws_iot_mqtt_interface.h:163
const char * pMessage
Message to be delivered as LWT.
Definition: aws_iot_mqtt_interface.h:62
char * pDeviceCertLocation
Pointer to a string defining the device identity certificate file (full file, not path) ...
Definition: aws_iot_mqtt_interface.h:87
char * pHostURL
Pointer to a string defining the endpoint for the MQTT service.
Definition: aws_iot_mqtt_interface.h:84
iot_message_handler mHandler
Callback to be invoked upon receipt of a message on the subscribed topic.
Definition: aws_iot_mqtt_interface.h:151
QoSLevel
Quality of Service Type.
Definition: aws_iot_mqtt_interface.h:47
IoT_Error_t aws_iot_mqtt_yield(int timeout)
Yield to the MQTT client.
Definition: aws_iot_mqtt_embedded_client_wrapper.c:227
MQTT Callback Function Parameters.
Definition: aws_iot_mqtt_interface.h:125
Definition of error types for the SDK.
pConnectFunc_t connect
function implementing the iot_mqtt_connect function
Definition: aws_iot_mqtt_interface.h:302
MQTTwillOptions will
MQTT LWT parameters.
Definition: aws_iot_mqtt_interface.h:96
char * pTopicName
Pointer to the topic string on which the message was delivered. In the case of a wildcard subscriptio...
Definition: aws_iot_mqtt_interface.h:126
MQTTMessageParams MessageParams
Message parameters structure.
Definition: aws_iot_mqtt_interface.h:128
bool isWillMsgPresent
Is there a LWT associated with this connection?
Definition: aws_iot_mqtt_interface.h:95
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_interface.h:89
bool isDuplicate
Is this message a duplicate QoS > 0 message? Handled automatically by the MQTT client.
Definition: aws_iot_mqtt_interface.h:113
IoT_Error_t aws_iot_mqtt_autoreconnect_set_status(bool value)
Enable or Disable AutoReconnect on Network Disconnect.
Definition: aws_iot_mqtt_embedded_client_wrapper.c:273
IoT_Error_t aws_iot_mqtt_disconnect(void)
Disconnect an MQTT Connection.
Definition: aws_iot_mqtt_embedded_client_wrapper.c:217
uint32_t PayloadLen
Length of MQTT payload.
Definition: aws_iot_mqtt_interface.h:116
MQTT Message Parameters.
Definition: aws_iot_mqtt_interface.h:110
MQTT Client Type Definition.
Definition: aws_iot_mqtt_interface.h:301
pDisconnectFunc_t disconnect
function implementing the iot_mqtt_disconnect function
Definition: aws_iot_mqtt_interface.h:306
bool aws_iot_is_mqtt_connected(void)
Is the MQTT client currently connected?
Definition: aws_iot_mqtt_embedded_client_wrapper.c:283
void aws_iot_mqtt_init(MQTTClient_t *pClient)
Set the MQTT client.
Definition: aws_iot_mqtt_embedded_client_wrapper.c:291
uint16_t TopicNameLen
Length of the topic string.
Definition: aws_iot_mqtt_interface.h:127
MQTT 3.1.1 (protocol message byte = 4)
Definition: aws_iot_mqtt_interface.h:37
uint16_t port
MQTT service listening port.
Definition: aws_iot_mqtt_interface.h:85
char * pDevicePrivateKeyLocation
Pointer to a string defining the device private key file (full file, not path)
Definition: aws_iot_mqtt_interface.h:88
int32_t(* iot_message_handler)(MQTTCallbackParams params)
MQTT Callback Function.
Definition: aws_iot_mqtt_interface.h:140
uint32_t mqttCommandTimeout_ms
Timeout for MQTT blocking calls. In milliseconds.
Definition: aws_iot_mqtt_interface.h:97
pPublishFunc_t publish
function implementing the iot_mqtt_publish function
Definition: aws_iot_mqtt_interface.h:303
IoT_Error_t
IoT Error enum.
Definition: aws_iot_error.h:30
QoS 0 = at most once delivery.
Definition: aws_iot_mqtt_interface.h:48
IoT_Error_t aws_iot_mqtt_unsubscribe(char *pTopic)
Unsubscribe to an MQTT topic.
Definition: aws_iot_mqtt_embedded_client_wrapper.c:208
MQTT Subscription Parameters.
Definition: aws_iot_mqtt_interface.h:148
bool aws_iot_is_autoreconnect_enabled(void)
Is the MQTT client set to reconnect automatically?
Definition: aws_iot_mqtt_embedded_client_wrapper.c:287
pIsAutoReconnectEnabledFunc_t isAutoReconnectEnabled
function implementing the iot_is_autoreconnect_enabled function
Definition: aws_iot_mqtt_interface.h:310
pSubscribeFunc_t subscribe
function implementing the iot_mqtt_subscribe function
Definition: aws_iot_mqtt_interface.h:304
pUnsubscribeFunc_t unsubscribe
function implementing the iot_mqtt_unsubscribe function
Definition: aws_iot_mqtt_interface.h:305
MQTT 3.1 (protocol message byte = 3)
Definition: aws_iot_mqtt_interface.h:36
pIsConnectedFunc_t isConnected
function implementing the iot_is_mqtt_connected function
Definition: aws_iot_mqtt_interface.h:308
QoS 2 is NOT supported.
Definition: aws_iot_mqtt_interface.h:50
QoS 1 = at least once delivery.
Definition: aws_iot_mqtt_interface.h:49
uint16_t KeepAliveInterval_sec
MQTT keep alive interval in seconds. Defines inactivity time allowed before determining the connectio...
Definition: aws_iot_mqtt_interface.h:93
char * pTopic
Pointer to the string defining the desired publishing topic.
Definition: aws_iot_mqtt_interface.h:162
MQTT Publish Parameters.
Definition: aws_iot_mqtt_interface.h:161
Last Will and Testament Definition.
Definition: aws_iot_mqtt_interface.h:60
pYieldFunc_t yield
function implementing the iot_mqtt_yield function
Definition: aws_iot_mqtt_interface.h:307
char * pRootCALocation
Pointer to a string defining the Root CA file (full file, not path)
Definition: aws_iot_mqtt_interface.h:86
bool isSSLHostnameVerify
Client should perform server certificate hostname validation.
Definition: aws_iot_mqtt_interface.h:99
IoT_Error_t aws_iot_mqtt_publish(MQTTPublishParams *pParams)
Publish an MQTT message on a topic.
Definition: aws_iot_mqtt_embedded_client_wrapper.c:190
MQTT Connection Parameters.
Definition: aws_iot_mqtt_interface.h:82
QoSLevel qos
Message Quality of Service.
Definition: aws_iot_mqtt_interface.h:111
QoSLevel qos
QoS of LWT message.
Definition: aws_iot_mqtt_interface.h:64
pSetAutoReconnectStatusFunc_t setAutoReconnectStatus
function implementing the iot_mqtt_autoreconnect_set_status function
Definition: aws_iot_mqtt_interface.h:311
char * pTopic
Pointer to the string defining the desired subscription topic.
Definition: aws_iot_mqtt_interface.h:149
IoT_Error_t aws_iot_mqtt_subscribe(MQTTSubscribeParams *pParams)
Subscribe to an MQTT topic.
Definition: aws_iot_mqtt_embedded_client_wrapper.c:181
pReconnectFunc_t reconnect
function implementing the iot_mqtt_reconnect function
Definition: aws_iot_mqtt_interface.h:309
bool isRetained
NOT supported.
Definition: aws_iot_mqtt_interface.h:63
QoSLevel qos
Quality of service of the subscription.
Definition: aws_iot_mqtt_interface.h:150
IoT_Error_t aws_iot_mqtt_connect(MQTTConnectParams *pParams)
MQTT Connection Function.
Definition: aws_iot_mqtt_embedded_client_wrapper.c:112
MQTT_Ver_t MQTTVersion
Desired MQTT version used during connection.
Definition: aws_iot_mqtt_interface.h:92
iot_disconnect_handler disconnectHandler
Callback to be invoked upon connection loss.
Definition: aws_iot_mqtt_interface.h:100
const char * pTopicName
LWT Topic.
Definition: aws_iot_mqtt_interface.h:61
bool isRetained
Retained messages are NOT supported by the AWS IoT Service at the time of this SDK release...
Definition: aws_iot_mqtt_interface.h:112
IoT_Error_t aws_iot_mqtt_attempt_reconnect(void)
MQTT Manual Re-Connection Function.
Definition: aws_iot_mqtt_embedded_client_wrapper.c:253
char * pPassword
Not used in the AWS IoT Service.
Definition: aws_iot_mqtt_interface.h:91
uint32_t tlsHandshakeTimeout_ms
TLS handshake timeout. In milliseconds.
Definition: aws_iot_mqtt_interface.h:98
void * pPayload
Pointer to MQTT message payload (bytes).
Definition: aws_iot_mqtt_interface.h:115
char * pUserName
Not used in the AWS IoT Service.
Definition: aws_iot_mqtt_interface.h:90
uint8_t enableAutoReconnect
Set to true to enable auto reconnect.
Definition: aws_iot_mqtt_interface.h:83
MQTT_Ver_t
MQTT Version Type.
Definition: aws_iot_mqtt_interface.h:35