Network Services API  2.30.00.10
mqttclient.h
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2015-2018, Texas Instruments Incorporated
3  * All rights reserved.
4  *
5  * Redistribution and use in source and binary forms, with or without
6  * modification, are permitted provided that the following conditions
7  * are met:
8  *
9  * * Redistributions of source code must retain the above copyright
10  * notice, this list of conditions and the following disclaimer.
11  *
12  * * Redistributions in binary form must reproduce the above copyright
13  * notice, this list of conditions and the following disclaimer in the
14  * documentation and/or other materials provided with the distribution.
15  *
16  * * Neither the name of Texas Instruments Incorporated nor the names of
17  * its contributors may be used to endorse or promote products derived
18  * from this software without specific prior written permission.
19  *
20  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
21  * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
22  * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
23  * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
24  * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
25  * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
26  * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
27  * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
28  * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
29  * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
30  * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
31  */
32 
98 #ifndef ti_net_mqtt_MQTTClient__include
99 #define ti_net_mqtt_MQTTClient__include
100 
103 
104 //*****************************************************************************
105 // includes
106 //*****************************************************************************
107 #include <string.h>
108 #include <stdbool.h>
109 #include <ti/net/mqtt/common/mqtt_common.h>
110 
111 #ifdef __cplusplus
112 extern "C" {
113 #endif
114 
115 //*****************************************************************************
116 // defines
117 //*****************************************************************************
118 
119 #define MQTTCLIENT_ERR_NETWORK MQTT_PACKET_ERR_NETWORK
120 #define MQTTCLIENT_ERR_TIMEOUT MQTT_PACKET_ERR_TIMEOUT
121 #define MQTTCLIENT_ERR_NET_OPS MQTT_PACKET_ERR_NET_OPS
122 #define MQTTCLIENT_ERR_FNPARAM MQTT_PACKET_ERR_FNPARAM
123 #define MQTTCLIENT_ERR_PKT_AVL MQTT_PACKET_ERR_PKT_AVL
124 #define MQTTCLIENT_ERR_PKT_LEN MQTT_PACKET_ERR_PKT_LEN
125 #define MQTTCLIENT_ERR_NOTCONN MQTT_PACKET_ERR_NOTCONN
126 #define MQTTCLIENT_ERR_BADCALL MQTT_PACKET_ERR_BADCALL
127 #define MQTTCLIENT_ERR_CONTENT MQTT_PACKET_ERR_CONTENT
128 #define MQTTCLIENT_ERR_LIBQUIT MQTT_PACKET_ERR_LIBQUIT
129 #define MQTTCLIENT_ERR_REMLSTN MQTT_PACKET_ERR_REMLSTN
130 #define MQTTCLIENT_OPERATION_CONNACK MQTT_CONNACK
131 #define MQTTCLIENT_OPERATION_EVT_PUBACK MQTT_PUBACK
132 #define MQTTCLIENT_OPERATION_PUBCOMP MQTT_PUBCOMP
133 #define MQTTCLIENT_OPERATION_SUBACK MQTT_SUBACK
134 #define MQTTCLIENT_OPERATION_UNSUBACK MQTT_UNSUBACK
136 #define MQTTCLIENT_NETCONN_IP4 MQTT_DEV_NETCONN_OPT_IP4
137 #define MQTTCLIENT_NETCONN_IP6 MQTT_DEV_NETCONN_OPT_IP6
138 #define MQTTCLIENT_NETCONN_URL MQTT_DEV_NETCONN_OPT_URL
139 #define MQTTCLIENT_NETCONN_SEC MQTT_DEV_NETCONN_OPT_SEC
141 #define MQTTCLIENT_NETCONN_SKIP_DOMAIN_NAME_VERIFICATION MQTT_DEV_NETCONN_OPT_SKIP_DOMAIN_NAME_VERIFICATION
142 #define MQTTCLIENT_NETCONN_SKIP_CERTIFICATE_CATALOG_VERIFICATION MQTT_DEV_NETCONN_OPT_SKIP_CERTIFICATE_CATALOG_VERIFICATION
143 #define MQTTCLIENT_NETCONN_SKIP_DATE_VERIFICATION MQTT_DEV_NETCONN_OPT_SKIP_DATE_VERIFICATION
146 //*****************************************************************************
147 // typedefs
148 //*****************************************************************************
149 
150 typedef enum
151 {
160 
161 /* callbacks */
162 
163 typedef enum
164 {
169 
171 {
172  uint32_t messageType;
174 
176 {
177  const char *topic;
178  int32_t topLen;
179  bool dup;
180  uint8_t qos;
181  bool retain;
183 
184 
186 /*
187  Note: value of n_files can vary from 1 to 4, with corresponding pointers to
188  the files in files field. Value of 1(n_files) will assume the corresponding
189  pointer is for CA File Name. Any other value of n_files expects the files to
190  be in following order:
191  1. Private Key File
192  2. Certificate File Name
193  3. CA File Name
194  4. DH Key File Name
195 
196  example:
197  If you want to provide only CA File Name, following are the two way of doing it:
198  for n_files = 1
199  char *security_file_list[] = {"/cert/testcacert.der"};
200  for n_files = 4
201  char *security_file_list[] = {NULL, NULL, "/cert/testcacert.der", NULL};
202 
203  where secure_files = security_file_list
204  */
205 
206 typedef struct MQTTClient_ConnParams
207 {
208  uint32_t netconnFlags;
209  const char *serverAddr;
210  uint16_t port;
211  uint8_t method;
212  uint32_t cipher;
213  uint32_t nFiles;
214  char * const *secureFiles; /* SL needs 4 files*/
216 
217 typedef struct MQTTClient_Params
218 {
220  char *clientId;
221 
228 
230  MQTTClient_ConnParams *connParams; // pointer to connection param
231 
233 
234 typedef void (*MQTTClient_CallBack)(int32_t event, void *metaData, uint32_t metaDateLen, void *data, uint32_t dataLen);
235 typedef void *MQTTClient_Handle;
236 
238 {
239  char *topic;
240  MQTTClient_CallBack callback; // optional - if NULL use the default callback
241  uint8_t qos;
242  uint8_t persistent;
244 
246 {
247  char* topic;
248  uint8_t persistent;
250 
251 /* Data structure which holds a will data message. */
252 
253 typedef struct MQTTClient_Will
254 {
255  const char *willTopic;
256  const char *willMsg;
257  int8_t willQos;
258  bool retain;
260 
261 //*****************************************************************************
262 // function prototypes
263 //*****************************************************************************
264 
275 MQTTClient_Handle MQTTClient_create(MQTTClient_CallBack defaultCallback,
276  MQTTClient_Params *params);
277 
286 int16_t MQTTClient_delete(MQTTClient_Handle handle);
287 
297 int16_t MQTTClient_run(MQTTClient_Handle handle);
298 
306 int16_t MQTTClient_connect(MQTTClient_Handle handle);
307 
317 int16_t MQTTClient_disconnect(MQTTClient_Handle handle);
318 
339 int16_t MQTTClient_publish(MQTTClient_Handle handle, char *topic, uint16_t topicLen, char *msg, uint16_t msgLen, uint32_t flags);
340 
362 int16_t MQTTClient_subscribe(MQTTClient_Handle handle, MQTTClient_SubscribeParams *value, uint8_t numberOfTopics);
363 
376 int16_t MQTTClient_unsubscribe(MQTTClient_Handle handle, MQTTClient_UnsubscribeParams *value, uint8_t numberOfTopics);
377 
398 int16_t MQTTClient_set(MQTTClient_Handle handle, uint16_t option, void *value, uint16_t valueLength);
399 
420 int16_t MQTTClient_get(MQTTClient_Handle handle, uint16_t option, void *value, uint16_t valueLength);
421 
423 #ifdef __cplusplus
424 }
425 #endif
426 
427 #endif
Definition: mqttclient.h:167
bool retain
Definition: mqttclient.h:258
int16_t MQTTClient_unsubscribe(MQTTClient_Handle handle, MQTTClient_UnsubscribeParams *value, uint8_t numberOfTopics)
MQTTClient_Handle MQTTClient_create(MQTTClient_CallBack defaultCallback, MQTTClient_Params *params)
char * topic
Definition: mqttclient.h:247
void * MQTTClient_Handle
Definition: mqttclient.h:235
int32_t topLen
Definition: mqttclient.h:178
int16_t MQTTClient_subscribe(MQTTClient_Handle handle, MQTTClient_SubscribeParams *value, uint8_t numberOfTopics)
uint32_t netconnFlags
Definition: mqttclient.h:208
const char * willMsg
Definition: mqttclient.h:256
bool dup
Definition: mqttclient.h:179
Definition: mqttclient.h:154
uint8_t qos
Definition: mqttclient.h:180
Definition: mqttclient.h:152
struct MQTTClient_UnsubscribeParams MQTTClient_UnsubscribeParams
Definition: mqttclient.h:175
const char * willTopic
Definition: mqttclient.h:255
char * topic
Definition: mqttclient.h:239
int16_t MQTTClient_delete(MQTTClient_Handle handle)
char * clientId
Definition: mqttclient.h:220
Definition: mqttclient.h:155
int16_t MQTTClient_run(MQTTClient_Handle handle)
int16_t MQTTClient_get(MQTTClient_Handle handle, uint16_t option, void *value, uint16_t valueLength)
bool blockingSend
Definition: mqttclient.h:229
MQTTClient_Option
Definition: mqttclient.h:150
Definition: mqttclient.h:153
Definition: mqttclient.h:166
uint8_t persistent
Definition: mqttclient.h:242
Definition: mqttclient.h:157
uint32_t messageType
Definition: mqttclient.h:172
uint8_t qos
Definition: mqttclient.h:241
int8_t willQos
Definition: mqttclient.h:257
int16_t MQTTClient_disconnect(MQTTClient_Handle handle)
Definition: mqttclient.h:245
uint32_t cipher
Definition: mqttclient.h:212
Definition: mqttclient.h:165
struct MQTTClient_OperationMetaDataCB MQTTClient_OperationMetaDataCB
Definition: mqttclient.h:158
MQTTClient_ConnParams * connParams
Definition: mqttclient.h:230
const char * serverAddr
Definition: mqttclient.h:209
const char * topic
Definition: mqttclient.h:177
Definition: mqttclient.h:237
uint8_t method
Definition: mqttclient.h:211
char *const * secureFiles
Definition: mqttclient.h:214
uint32_t nFiles
Definition: mqttclient.h:213
Definition: mqttclient.h:170
Definition: mqttclient.h:217
MQTTClient_CallBack callback
Definition: mqttclient.h:240
int16_t MQTTClient_publish(MQTTClient_Handle handle, char *topic, uint16_t topicLen, char *msg, uint16_t msgLen, uint32_t flags)
void(* MQTTClient_CallBack)(int32_t event, void *metaData, uint32_t metaDateLen, void *data, uint32_t dataLen)
Definition: mqttclient.h:234
int16_t MQTTClient_connect(MQTTClient_Handle handle)
uint8_t persistent
Definition: mqttclient.h:248
uint16_t port
Definition: mqttclient.h:210
struct MQTTClient_Params MQTTClient_Params
Definition: mqttclient.h:253
bool retain
Definition: mqttclient.h:181
struct MQTTClient_ConnParams MQTTClient_ConnParams
struct MQTTClient_SubscribeParams MQTTClient_SubscribeParams
bool mqttMode31
Definition: mqttclient.h:227
Definition: mqttclient.h:206
int16_t MQTTClient_set(MQTTClient_Handle handle, uint16_t option, void *value, uint16_t valueLength)
struct MQTTClient_Will MQTTClient_Will
struct MQTTClient_RecvMetaDataCB MQTTClient_RecvMetaDataCB
Definition: mqttclient.h:156
MQTTClient_EventCB
Definition: mqttclient.h:163
© Copyright 1995-2018, Texas Instruments Incorporated. All rights reserved.
Trademarks | Privacy policy | Terms of use | Terms of sale