Network Services API  2.75.00.17
mqttclient.h
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2015-2019, 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
145 //*****************************************************************************
146 // typedefs
147 //*****************************************************************************
148 
149 typedef enum
150 {
159 
160 /* callbacks */
161 
162 typedef enum
163 {
168 
170 {
171  uint32_t messageType;
173 
175 {
176  const char *topic;
177  int32_t topLen;
178  bool dup;
179  uint8_t qos;
180  bool retain;
182 
183 
185 /*
186  Note: value of n_files can vary from 1 to 4, with corresponding pointers to
187  the files in files field. Value of 1(n_files) will assume the corresponding
188  pointer is for CA File Name. Any other value of n_files expects the files to
189  be in following order:
190  1. Private Key File
191  2. Certificate File Name
192  3. CA File Name
193  4. DH Key File Name
194 
195  example:
196  If you want to provide only CA File Name, following are the two way of doing it:
197  for n_files = 1
198  char *security_file_list[] = {"/cert/testcacert.der"};
199  for n_files = 4
200  char *security_file_list[] = {NULL, NULL, "/cert/testcacert.der", NULL};
201 
202  where secure_files = security_file_list
203  */
204 
205 typedef struct MQTTClient_ConnParams
206 {
207  uint32_t netconnFlags;
208  const char *serverAddr;
209  uint16_t port;
210  uint8_t method;
211  uint32_t cipher;
212  uint32_t nFiles;
213  char * const *secureFiles; /* SL needs 4 files*/
215 
216 typedef struct MQTTClient_Params
217 {
219  char *clientId;
220 
227 
232 
233 typedef void (*MQTTClient_CallBack)(int32_t event, void *metaData, uint32_t metaDateLen, void *data, uint32_t dataLen);
234 typedef void *MQTTClient_Handle;
235 
237 {
238  char *topic;
239  MQTTClient_CallBack callback; // optional - if NULL use the default callback
240  uint8_t qos;
241  uint8_t persistent;
243 
245 {
246  char* topic;
247  uint8_t persistent;
249 
250 /* Data structure which holds a will data message. */
251 
252 typedef struct MQTTClient_Will
253 {
254  const char *willTopic;
255  const char *willMsg;
256  int8_t willQos;
257  bool retain;
259 
260 //*****************************************************************************
261 // function prototypes
262 //*****************************************************************************
263 
274 MQTTClient_Handle MQTTClient_create(MQTTClient_CallBack defaultCallback,
275  MQTTClient_Params *params);
276 
289 int16_t MQTTClient_delete(MQTTClient_Handle handle);
290 
301 int16_t MQTTClient_run(MQTTClient_Handle handle);
302 
310 int16_t MQTTClient_connect(MQTTClient_Handle handle);
311 
319 int16_t MQTTClient_disconnect(MQTTClient_Handle handle);
320 
342 int16_t MQTTClient_publish(MQTTClient_Handle handle, char *topic, uint16_t topicLen, char *msg, uint16_t msgLen, uint32_t flags);
343 
366 int16_t MQTTClient_subscribe(MQTTClient_Handle handle, MQTTClient_SubscribeParams *value, uint8_t numberOfTopics);
367 
381 int16_t MQTTClient_unsubscribe(MQTTClient_Handle handle, MQTTClient_UnsubscribeParams *value, uint8_t numberOfTopics);
382 
404 int16_t MQTTClient_set(MQTTClient_Handle handle, uint16_t option, void *value, uint16_t valueLength);
405 
427 int16_t MQTTClient_get(MQTTClient_Handle handle, uint16_t option, void *value, uint16_t valueLength);
428 
430 #ifdef __cplusplus
431 }
432 #endif
433 
434 #endif
bool retain
Definition: mqttclient.h:257
struct MQTTClient_Params MQTTClient_Params
Definition: mqttclient.h:154
Definition: mqttclient.h:157
Definition: mqttclient.h:164
char * topic
Definition: mqttclient.h:246
int32_t topLen
Definition: mqttclient.h:177
uint32_t netconnFlags
Definition: mqttclient.h:207
const char * willMsg
Definition: mqttclient.h:255
bool dup
Definition: mqttclient.h:178
uint8_t qos
Definition: mqttclient.h:179
Definition: mqttclient.h:153
Definition: mqttclient.h:174
struct MQTTClient_SubscribeParams MQTTClient_SubscribeParams
const char * willTopic
Definition: mqttclient.h:254
char * topic
Definition: mqttclient.h:238
int16_t MQTTClient_set(MQTTClient_Handle handle, uint16_t option, void *value, uint16_t valueLength)
Set client parameters.
char * clientId
Definition: mqttclient.h:219
Definition: mqttclient.h:156
int16_t MQTTClient_get(MQTTClient_Handle handle, uint16_t option, void *value, uint16_t valueLength)
Get client parameters.
bool blockingSend
Definition: mqttclient.h:228
void(* MQTTClient_CallBack)(int32_t event, void *metaData, uint32_t metaDateLen, void *data, uint32_t dataLen)
Definition: mqttclient.h:233
struct MQTTClient_Will MQTTClient_Will
Definition: mqttclient.h:165
uint8_t persistent
Definition: mqttclient.h:241
int16_t MQTTClient_publish(MQTTClient_Handle handle, char *topic, uint16_t topicLen, char *msg, uint16_t msgLen, uint32_t flags)
Publish a named message to the broker.
uint32_t messageType
Definition: mqttclient.h:171
int16_t MQTTClient_connect(MQTTClient_Handle handle)
Connect to a broker.
struct MQTTClient_OperationMetaDataCB MQTTClient_OperationMetaDataCB
uint8_t qos
Definition: mqttclient.h:240
int8_t willQos
Definition: mqttclient.h:256
Definition: mqttclient.h:155
int16_t MQTTClient_run(MQTTClient_Handle handle)
MQTTClient state machine.
Definition: mqttclient.h:244
uint32_t cipher
Definition: mqttclient.h:211
struct MQTTClient_ConnParams MQTTClient_ConnParams
Definition: mqttclient.h:166
Definition: mqttclient.h:152
struct MQTTClient_UnsubscribeParams MQTTClient_UnsubscribeParams
MQTTClient_ConnParams * connParams
Definition: mqttclient.h:229
const char * serverAddr
Definition: mqttclient.h:208
int16_t MQTTClient_unsubscribe(MQTTClient_Handle handle, MQTTClient_UnsubscribeParams *value, uint8_t numberOfTopics)
Unsubscribe from a set of topics.
const char * topic
Definition: mqttclient.h:176
Definition: mqttclient.h:236
uint8_t method
Definition: mqttclient.h:210
char *const * secureFiles
Definition: mqttclient.h:213
uint32_t nFiles
Definition: mqttclient.h:212
Definition: mqttclient.h:169
void * MQTTClient_Handle
Definition: mqttclient.h:234
int16_t MQTTClient_disconnect(MQTTClient_Handle handle)
Disconnect from a broker.
Definition: mqttclient.h:216
struct MQTTClient_RecvMetaDataCB MQTTClient_RecvMetaDataCB
MQTTClient_CallBack callback
Definition: mqttclient.h:239
MQTTClient_Option
Definition: mqttclient.h:149
Definition: mqttclient.h:151
MQTTClient_EventCB
Definition: mqttclient.h:162
int16_t MQTTClient_subscribe(MQTTClient_Handle handle, MQTTClient_SubscribeParams *value, uint8_t numberOfTopics)
Subscribe to a set of topics.
int16_t MQTTClient_delete(MQTTClient_Handle handle)
Delete an MQTTClient instance.
uint8_t persistent
Definition: mqttclient.h:247
uint16_t port
Definition: mqttclient.h:209
Definition: mqttclient.h:252
bool retain
Definition: mqttclient.h:180
MQTTClient_Handle MQTTClient_create(MQTTClient_CallBack defaultCallback, MQTTClient_Params *params)
Create an MQTTClient instance.
bool mqttMode31
Definition: mqttclient.h:226
Definition: mqttclient.h:205
© Copyright 1995-2020, Texas Instruments Incorporated. All rights reserved.
Trademarks | Privacy policy | Terms of use | Terms of sale