mqtt_client.h
Go to the documentation of this file.
1 /**
2  * @file mqtt_client.h
3  * @brief MQTT client
4  *
5  * @section License
6  *
7  * SPDX-License-Identifier: GPL-2.0-or-later
8  *
9  * Copyright (C) 2010-2026 Oryx Embedded SARL. All rights reserved.
10  *
11  * This file is part of CycloneTCP Open.
12  *
13  * This program is free software; you can redistribute it and/or
14  * modify it under the terms of the GNU General Public License
15  * as published by the Free Software Foundation; either version 2
16  * of the License, or (at your option) any later version.
17  *
18  * This program is distributed in the hope that it will be useful,
19  * but WITHOUT ANY WARRANTY; without even the implied warranty of
20  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21  * GNU General Public License for more details.
22  *
23  * You should have received a copy of the GNU General Public License
24  * along with this program; if not, write to the Free Software Foundation,
25  * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
26  *
27  * @author Oryx Embedded SARL (www.oryx-embedded.com)
28  * @version 2.6.4
29  **/
30 
31 #ifndef _MQTT_CLIENT_H
32 #define _MQTT_CLIENT_H
33 
34 //Dependencies
35 #include "core/net.h"
36 #include "mqtt/mqtt_common.h"
37 
38 //MQTT client support
39 #ifndef MQTT_CLIENT_SUPPORT
40  #define MQTT_CLIENT_SUPPORT ENABLED
41 #elif (MQTT_CLIENT_SUPPORT != ENABLED && MQTT_CLIENT_SUPPORT != DISABLED)
42  #error MQTT_CLIENT_SUPPORT parameter is not valid
43 #endif
44 
45 //MQTT over TLS
46 #ifndef MQTT_CLIENT_TLS_SUPPORT
47  #define MQTT_CLIENT_TLS_SUPPORT DISABLED
48 #elif (MQTT_CLIENT_TLS_SUPPORT != ENABLED && MQTT_CLIENT_TLS_SUPPORT != DISABLED)
49  #error MQTT_CLIENT_TLS_SUPPORT parameter is not valid
50 #endif
51 
52 //MQTT over WebSocket
53 #ifndef MQTT_CLIENT_WS_SUPPORT
54  #define MQTT_CLIENT_WS_SUPPORT DISABLED
55 #elif (MQTT_CLIENT_WS_SUPPORT != ENABLED && MQTT_CLIENT_WS_SUPPORT != DISABLED)
56  #error MQTT_CLIENT_WS_SUPPORT parameter is not valid
57 #endif
58 
59 //Default keep-alive time interval, in seconds
60 #ifndef MQTT_CLIENT_DEFAULT_KEEP_ALIVE
61  #define MQTT_CLIENT_DEFAULT_KEEP_ALIVE 0
62 #elif (MQTT_CLIENT_DEFAULT_KEEP_ALIVE < 0)
63  #error MQTT_CLIENT_DEFAULT_KEEP_ALIVE parameter is not valid
64 #endif
65 
66 //Default communication timeout, in milliseconds
67 #ifndef MQTT_CLIENT_DEFAULT_TIMEOUT
68  #define MQTT_CLIENT_DEFAULT_TIMEOUT 20000
69 #elif (MQTT_CLIENT_DEFAULT_TIMEOUT < 0)
70  #error MQTT_CLIENT_DEFAULT_TIMEOUT parameter is not valid
71 #endif
72 
73 //Maximum length of the hostname
74 #ifndef MQTT_CLIENT_MAX_HOST_LEN
75  #define MQTT_CLIENT_MAX_HOST_LEN 32
76 #elif (MQTT_CLIENT_MAX_HOST_LEN < 1)
77  #error MQTT_CLIENT_MAX_HOST_LEN parameter is not valid
78 #endif
79 
80 //Maximum length of the resource name
81 #ifndef MQTT_CLIENT_MAX_URI_LEN
82  #define MQTT_CLIENT_MAX_URI_LEN 16
83 #elif (MQTT_CLIENT_MAX_URI_LEN < 1)
84  #error MQTT_CLIENT_MAX_URI_LEN parameter is not valid
85 #endif
86 
87 //Maximum length of the client identifier
88 #ifndef MQTT_CLIENT_MAX_ID_LEN
89  #define MQTT_CLIENT_MAX_ID_LEN 23
90 #elif (MQTT_CLIENT_MAX_ID_LEN < 0)
91  #error MQTT_CLIENT_MAX_ID_LEN parameter is not valid
92 #endif
93 
94 //Maximum length of the user name
95 #ifndef MQTT_CLIENT_MAX_USERNAME_LEN
96  #define MQTT_CLIENT_MAX_USERNAME_LEN 16
97 #elif (MQTT_CLIENT_MAX_USERNAME_LEN < 0)
98  #error MQTT_CLIENT_MAX_USERNAME_LEN parameter is not valid
99 #endif
100 
101 //Maximum length of the password
102 #ifndef MQTT_CLIENT_MAX_PASSWORD_LEN
103  #define MQTT_CLIENT_MAX_PASSWORD_LEN 16
104 #elif (MQTT_CLIENT_MAX_PASSWORD_LEN < 0)
105  #error MQTT_CLIENT_MAX_PASSWORD_LEN parameter is not valid
106 #endif
107 
108 //Maximum length of the will topic
109 #ifndef MQTT_CLIENT_MAX_WILL_TOPIC_LEN
110  #define MQTT_CLIENT_MAX_WILL_TOPIC_LEN 16
111 #elif (MQTT_CLIENT_MAX_WILL_TOPIC_LEN < 0)
112  #error MQTT_CLIENT_MAX_WILL_TOPIC_LEN parameter is not valid
113 #endif
114 
115 //Maximum length of the will message payload
116 #ifndef MQTT_CLIENT_MAX_WILL_PAYLOAD_LEN
117  #define MQTT_CLIENT_MAX_WILL_PAYLOAD_LEN 16
118 #elif (MQTT_CLIENT_MAX_WILL_PAYLOAD_LEN < 0)
119  #error MQTT_CLIENT_MAX_WILL_PAYLOAD_LEN parameter is not valid
120 #endif
121 
122 //Size of the MQTT client buffer
123 #ifndef MQTT_CLIENT_BUFFER_SIZE
124  #define MQTT_CLIENT_BUFFER_SIZE 1024
125 #elif (MQTT_CLIENT_BUFFER_SIZE < 1)
126  #error MQTT_CLIENT_BUFFER_SIZE parameter is not valid
127 #endif
128 
129 //Application specific context
130 #ifndef MQTT_CLIENT_PRIVATE_CONTEXT
131  #define MQTT_CLIENT_PRIVATE_CONTEXT
132 #endif
133 
134 //TLS supported?
135 #if (MQTT_CLIENT_TLS_SUPPORT == ENABLED)
136  #include "core/crypto.h"
137  #include "tls/tls.h"
138 #endif
139 
140 //WebSocket supported?
141 #if (MQTT_CLIENT_WS_SUPPORT == ENABLED)
142  #include "web_socket/web_socket.h"
143 #endif
144 
145 //Forward declaration of MqttClientContext structure
146 struct _MqttClientContext;
147 #define MqttClientContext struct _MqttClientContext
148 
149 //C++ guard
150 #ifdef __cplusplus
151 extern "C" {
152 #endif
153 
154 
155 /**
156  * @brief MQTT client states
157  **/
158 
159 typedef enum
160 {
173 
174 
175 /**
176  * @brief CONNACK message received callback
177  **/
178 
180  uint8_t connectAckFlags, uint8_t connectReturnCode);
181 
182 
183 /**
184  * @brief PUBLISH message received callback
185  **/
186 
188  const char_t *topic, const uint8_t *message, size_t length,
189  bool_t dup, MqttQosLevel qos, bool_t retain, uint16_t packetId);
190 
191 
192 /**
193  * @brief PUBACK message received callback
194  **/
195 
197  uint16_t packetId);
198 
199 
200 /**
201  * @brief PUBREC message received callback
202  **/
203 
205  uint16_t packetId);
206 
207 
208 /**
209  * @brief PUBREL message received callback
210  **/
211 
213  uint16_t packetId);
214 
215 
216 /**
217  * @brief PUBCOMP message received callback
218  **/
219 
221  uint16_t packetId);
222 
223 
224 /**
225  * @brief SUBACK message received callback
226  **/
227 
229  uint16_t packetId);
230 
231 
232 /**
233  * @brief UNSUBACK message received callback
234  **/
235 
237  uint16_t packetId);
238 
239 
240 /**
241  * @brief PINGRESP message received callback
242  **/
243 
245 
246 
247 //TLS supported?
248 #if (MQTT_CLIENT_TLS_SUPPORT == ENABLED)
249 
250 /**
251  * @brief TLS initialization callback
252  **/
253 
256 
257 #endif
258 
259 
260 /**
261  * @brief Will message
262  **/
263 
264 typedef struct
265 {
266  char_t topic[MQTT_CLIENT_MAX_WILL_TOPIC_LEN + 1]; ///<Will topic name
267  uint8_t payload[MQTT_CLIENT_MAX_WILL_PAYLOAD_LEN]; ///<Will message payload
268  size_t length; ///<Length of the Will message payload
269  MqttQosLevel qos; ///<QoS level to be used when publishing the Will message
270  bool_t retain; ///<Specifies if the Will message is to be retained
272 
273 
274 /**
275  * @brief MQTT client callback functions
276  **/
277 
278 typedef struct
279 {
280  MqttClientConnAckCallback connAckCallback; ///<CONNACK message received callback
281  MqttClientPublishCallback publishCallback; ///<PUBLISH message received callback
282  MqttClientPubAckCallback pubAckCallback; ///<PUBACK message received callback
283  MqttClientPubAckCallback pubRecCallback; ///<PUBREC message received callback
284  MqttClientPubAckCallback pubRelCallback; ///<PUBREL message received callback
285  MqttClientPubAckCallback pubCompCallback; ///<PUBCOMP message received callback
286  MqttClientPubAckCallback subAckCallback; ///<SUBACK message received callback
287  MqttClientPubAckCallback unsubAckCallback; ///<UNSUBACK message received callback
288  MqttClientPingRespCallback pingRespCallback; ///<PINGRESP message received callback
289 #if (MQTT_CLIENT_TLS_SUPPORT == ENABLED)
290  MqttClientTlsInitCallback tlsInitCallback; ///<TLS initialization callback
291 #endif
293 
294 
295 /**
296  * @brief MQTT client settings
297  **/
298 
299 typedef struct
300 {
301  MqttVersion version; ///<MQTT protocol version
302  MqttTransportProtocol transportProtocol; ///<Transport protocol
303  uint16_t keepAlive; ///<Keep-alive time interval
304  systime_t timeout; ///<Communication timeout
305 #if (MQTT_CLIENT_WS_SUPPORT == ENABLED)
306  char_t host[MQTT_CLIENT_MAX_HOST_LEN + 1]; ///<Domain name of the server (for virtual hosting)
307  char_t uri[MQTT_CLIENT_MAX_URI_LEN + 1]; ///<Resource name
308 #endif
309  char_t clientId[MQTT_CLIENT_MAX_ID_LEN + 1]; ///<Client identifier
310  char_t username[MQTT_CLIENT_MAX_USERNAME_LEN + 1]; ///<User name
311  char_t password[MQTT_CLIENT_MAX_PASSWORD_LEN + 1]; ///<Password
314 
315 
316 /**
317  * @brief MQTT client context
318  **/
319 
321 {
322  MqttClientSettings settings; ///<MQTT client settings
323  MqttClientCallbacks callbacks; ///<MQTT client callback functions
324  MqttClientState state; ///<MQTT client state
325  NetInterface *interface; ///<Underlying network interface
326  Socket *socket; ///<Underlying TCP socket
327 #if (MQTT_CLIENT_TLS_SUPPORT == ENABLED)
328  TlsContext *tlsContext; ///<TLS context
329  TlsSessionState tlsSession; ///<TLS session state
330 #endif
331 #if (MQTT_CLIENT_WS_SUPPORT == ENABLED)
332  WebSocket *webSocket; ///<Underlying WebSocket
333 #endif
334  systime_t startTime; ///<Start time
335  systime_t keepAliveTimestamp; ///<Timestamp used to manage keep-alive
336  uint8_t buffer[MQTT_CLIENT_BUFFER_SIZE]; ///<Internal buffer
337  uint8_t *packet; ///<Pointer to the incoming/outgoing MQTT packet
338  size_t packetPos; ///<Current position
339  size_t packetLen; ///<Length of the entire MQTT packet
340  MqttPacketType packetType; ///<Control packet type
341  uint16_t packetId; ///<Packet identifier
342  size_t remainingLen; ///<Length of the variable header and payload
343  size_t payloadPos; ///<Current position within the payload
344  size_t fragPos; ///<Current position within the current fragment
345  MQTT_CLIENT_PRIVATE_CONTEXT ///<Application specific context
346 };
347 
348 
349 /**
350  * @brief PUBLISH packet parameters
351  **/
352 
353 typedef struct
354 {
359  const void *payload;
360  size_t payloadLen;
361  size_t fragOffset;
362  size_t fragLen;
363  uint16_t *packetId;
365 
366 
367 //MQTT client related constants
369 
370 //MQTT client related functions
373 
375  const MqttClientCallbacks *callbacks);
376 
378 
380  MqttTransportProtocol transportProtocol);
381 
382 #if (MQTT_CLIENT_TLS_SUPPORT == ENABLED)
383 
385  MqttClientTlsInitCallback callback);
386 
387 #endif
388 
390  MqttClientPublishCallback callback);
391 
393 error_t mqttClientSetKeepAlive(MqttClientContext *context, uint16_t keepAlive);
394 
395 error_t mqttClientSetHost(MqttClientContext *context, const char_t *host);
396 error_t mqttClientSetUri(MqttClientContext *context, const char_t *uri);
397 
399  const char_t *clientId);
400 
402  const char_t *username, const char_t *password);
403 
405  const void *message, size_t length, MqttQosLevel qos, bool_t retain);
406 
408  NetInterface *interface);
409 
411  const IpAddr *serverIpAddr, uint16_t serverPort, bool_t cleanSession);
412 
413 error_t mqttClientSetPacketId(MqttClientContext *context, uint16_t packetId);
414 
415 error_t mqttClientPublish(MqttClientContext *context, const char_t *topic,
416  const void *message, size_t length, MqttQosLevel qos, bool_t retain,
417  uint16_t *packetId);
418 
420  MqttPublishInfo *publishInfo);
421 
422 error_t mqttClientSubscribe(MqttClientContext *context, const char_t *topic,
423  MqttQosLevel qos, uint16_t *packetId);
424 
426  uint16_t *packetId);
427 
429 
431 
434 
435 void mqttClientDeinit(MqttClientContext *context);
436 
437 //Deprecated functions
439 
440 //C++ guard
441 #ifdef __cplusplus
442 }
443 #endif
444 
445 #endif
MqttClientPublishCallback publishCallback
PUBLISH message received callback.
Definition: mqtt_client.h:281
void(* MqttClientPubAckCallback)(MqttClientContext *context, uint16_t packetId)
PUBACK message received callback.
Definition: mqtt_client.h:196
error_t mqttClientSetPacketId(MqttClientContext *context, uint16_t packetId)
Set packet identifier.
Definition: mqtt_client.c:614
const void * payload
Definition: mqtt_client.h:359
int bool_t
Definition: compiler_port.h:63
MQTT client context.
Definition: mqtt_client.h:321
MqttClientPubAckCallback pubAckCallback
PUBACK message received callback.
Definition: mqtt_client.h:282
error_t(* MqttClientTlsInitCallback)(MqttClientContext *context, TlsContext *tlsContext)
TLS initialization callback.
Definition: mqtt_client.h:254
error_t mqttClientTask(MqttClientContext *context, systime_t timeout)
Process MQTT client events.
Definition: mqtt_client.c:1241
MqttTransportProtocol transportProtocol
Transport protocol.
Definition: mqtt_client.h:302
WebSocket * webSocket
Underlying WebSocket.
Definition: mqtt_client.h:332
IP network address.
Definition: ip.h:90
MqttTransportProtocol
Transport protocol.
Definition: mqtt_common.h:74
uint16_t packetId
Packet identifier.
Definition: mqtt_client.h:341
void mqttClientDeinit(MqttClientContext *context)
Release MQTT client context.
Definition: mqtt_client.c:1394
MqttPacketType packetType
Control packet type.
Definition: mqtt_client.h:340
MqttVersion version
MQTT protocol version.
Definition: mqtt_client.h:301
WebSocket API (client and server)
uint8_t message[]
Definition: chap.h:154
error_t mqttClientInit(MqttClientContext *context)
Initialize MQTT client context.
Definition: mqtt_client.c:55
MqttClientState state
MQTT client state.
Definition: mqtt_client.h:324
MqttClientPubAckCallback subAckCallback
SUBACK message received callback.
Definition: mqtt_client.h:286
TlsContext * tlsContext
TLS context.
Definition: mqtt_client.h:328
void(* MqttClientPubRelCallback)(MqttClientContext *context, uint16_t packetId)
PUBREL message received callback.
Definition: mqtt_client.h:212
MqttClientPubAckCallback unsubAckCallback
UNSUBACK message received callback.
Definition: mqtt_client.h:287
@ MQTT_CLIENT_STATE_DISCONNECTED
Definition: mqtt_client.h:161
error_t mqttClientSetIdentifier(MqttClientContext *context, const char_t *clientId)
Set client identifier.
Definition: mqtt_client.c:332
uint8_t qos
Definition: mqtt_common.h:181
#define MQTT_CLIENT_PRIVATE_CONTEXT
Definition: mqtt_client.h:131
uint8_t version
Definition: coap_common.h:177
MqttClientPubAckCallback pubRecCallback
PUBREC message received callback.
Definition: mqtt_client.h:283
@ MQTT_CLIENT_STATE_WAITING_PACKET
Definition: mqtt_client.h:168
void(* MqttClientPubRecCallback)(MqttClientContext *context, uint16_t packetId)
PUBREC message received callback.
Definition: mqtt_client.h:204
size_t packetLen
Length of the entire MQTT packet.
Definition: mqtt_client.h:339
@ MQTT_CLIENT_STATE_SENDING_PACKET
Definition: mqtt_client.h:165
error_t mqttClientSetTimeout(MqttClientContext *context, systime_t timeout)
Set communication timeout.
Definition: mqtt_client.c:234
MQTT client callback functions.
Definition: mqtt_client.h:279
error_t mqttClientUnsubscribe(MqttClientContext *context, const char_t *topic, uint16_t *packetId)
Unsubscribe from topic.
Definition: mqtt_client.c:1013
void(* MqttClientConnAckCallback)(MqttClientContext *context, uint8_t connectAckFlags, uint8_t connectReturnCode)
CONNACK message received callback.
Definition: mqtt_client.h:179
MqttClientWillMessage willMessage
Will message.
Definition: mqtt_client.h:312
@ MQTT_CLIENT_STATE_PACKET_RECEIVED
Definition: mqtt_client.h:170
error_t mqttClientPublishEx(MqttClientContext *context, MqttPublishInfo *publishInfo)
Publish message.
Definition: mqtt_client.c:680
error_t mqttClientProcessEvents(MqttClientContext *context, systime_t timeout)
Process MQTT client events.
error_t mqttClientConnect(MqttClientContext *context, const IpAddr *serverIpAddr, uint16_t serverPort, bool_t cleanSession)
Establish connection with the MQTT server.
Definition: mqtt_client.c:474
#define MQTT_CLIENT_MAX_USERNAME_LEN
Definition: mqtt_client.h:96
MqttClientSettings settings
MQTT client settings.
Definition: mqtt_client.h:322
error_t mqttClientClose(MqttClientContext *context)
Close the connection with the MQTT server.
Definition: mqtt_client.c:1373
#define TlsContext
Definition: tls.h:36
error_t
Error codes.
Definition: error.h:43
void(* MqttClientSubAckCallback)(MqttClientContext *context, uint16_t packetId)
SUBACK message received callback.
Definition: mqtt_client.h:228
error_t mqttClientRegisterTlsInitCallback(MqttClientContext *context, MqttClientTlsInitCallback callback)
Register TLS initialization callback function.
Definition: mqtt_client.c:187
uint16_t keepAlive
Keep-alive time interval.
Definition: mqtt_client.h:303
error_t mqttClientSetVersion(MqttClientContext *context, MqttVersion version)
Set the MQTT protocol version to be used.
Definition: mqtt_client.c:141
@ MQTT_CLIENT_STATE_PACKET_SENT
Definition: mqtt_client.h:167
MqttQosLevel
Quality of service level.
Definition: mqtt_common.h:87
#define MQTT_CLIENT_MAX_WILL_TOPIC_LEN
Definition: mqtt_client.h:110
MqttClientPingRespCallback pingRespCallback
PINGRESP message received callback.
Definition: mqtt_client.h:288
MqttClientConnAckCallback connAckCallback
CONNACK message received callback.
Definition: mqtt_client.h:280
uint8_t * packet
Pointer to the incoming/outgoing MQTT packet.
Definition: mqtt_client.h:337
#define NetInterface
Definition: net.h:40
error_t mqttClientPublish(MqttClientContext *context, const char_t *topic, const void *message, size_t length, MqttQosLevel qos, bool_t retain, uint16_t *packetId)
Publish message.
Definition: mqtt_client.c:647
MqttClientPubAckCallback pubRelCallback
PUBREL message received callback.
Definition: mqtt_client.h:284
General definitions for cryptographic algorithms.
MQTT client settings.
Definition: mqtt_client.h:300
error_t mqttClientSetTransportProtocol(MqttClientContext *context, MqttTransportProtocol transportProtocol)
Set the transport protocol to be used.
Definition: mqtt_client.c:163
systime_t keepAliveTimestamp
Timestamp used to manage keep-alive.
Definition: mqtt_client.h:335
error_t mqttClientPing(MqttClientContext *context, systime_t *rtt)
Send ping request.
Definition: mqtt_client.c:1127
TlsSessionState tlsSession
TLS session state.
Definition: mqtt_client.h:329
systime_t startTime
Start time.
Definition: mqtt_client.h:334
#define MQTT_CLIENT_MAX_URI_LEN
Definition: mqtt_client.h:82
size_t fragPos
Current position within the current fragment.
Definition: mqtt_client.h:344
uint8_t length
Definition: tcp.h:375
size_t remainingLen
Length of the variable header and payload.
Definition: mqtt_client.h:342
MqttVersion
MQTT protocol level.
Definition: mqtt_common.h:63
#define WebSocket
Definition: web_socket.h:177
bool_t retain
Specifies if the Will message is to be retained.
Definition: mqtt_client.h:270
@ MQTT_CLIENT_STATE_RECEIVING_PACKET
Definition: mqtt_client.h:169
error_t mqttClientSetUri(MqttClientContext *context, const char_t *uri)
Set the name of the resource being requested.
Definition: mqtt_client.c:305
Definitions common to MQTT client and server.
NetInterface * interface
Underlying network interface.
Definition: mqtt_client.h:325
size_t length
Length of the Will message payload.
Definition: mqtt_client.h:268
uint32_t systime_t
System time.
@ MQTT_CLIENT_STATE_IDLE
Definition: mqtt_client.h:164
char char_t
Definition: compiler_port.h:55
MqttClientCallbacks callbacks
MQTT client callback functions.
Definition: mqtt_client.h:323
TLS session state.
Definition: tls.h:2243
MqttClientTlsInitCallback tlsInitCallback
TLS initialization callback.
Definition: mqtt_client.h:290
@ MQTT_CLIENT_STATE_CONNECTING
Definition: mqtt_client.h:162
#define MQTT_CLIENT_MAX_ID_LEN
Definition: mqtt_client.h:89
void(* MqttClientPingRespCallback)(MqttClientContext *context)
PINGRESP message received callback.
Definition: mqtt_client.h:244
@ MQTT_CLIENT_STATE_SENDING_PAYLOAD
Definition: mqtt_client.h:166
error_t mqttClientSetAuthInfo(MqttClientContext *context, const char_t *username, const char_t *password)
Set authentication information.
Definition: mqtt_client.c:359
uint8_t payload[]
Definition: ipv6.h:306
error_t mqttClientSetWillMessage(MqttClientContext *context, const char_t *topic, const void *message, size_t length, MqttQosLevel qos, bool_t retain)
Specify the Will message.
Definition: mqtt_client.c:395
void mqttClientInitCallbacks(MqttClientCallbacks *callbacks)
Initialize callback structure.
Definition: mqtt_client.c:105
error_t mqttClientRegisterPublishCallback(MqttClientContext *context, MqttClientPublishCallback callback)
Register publish callback function.
Definition: mqtt_client.c:212
Socket * socket
Underlying TCP socket.
Definition: mqtt_client.h:326
error_t mqttClientSetKeepAlive(MqttClientContext *context, uint16_t keepAlive)
Set keep-alive value.
Definition: mqtt_client.c:257
error_t mqttClientBindToInterface(MqttClientContext *context, NetInterface *interface)
Bind the MQTT client to a particular network interface.
Definition: mqtt_client.c:448
MqttClientPubAckCallback pubCompCallback
PUBCOMP message received callback.
Definition: mqtt_client.h:285
#define Socket
Definition: socket.h:36
MqttClientState
MQTT client states.
Definition: mqtt_client.h:160
void(* MqttClientPublishCallback)(MqttClientContext *context, const char_t *topic, const uint8_t *message, size_t length, bool_t dup, MqttQosLevel qos, bool_t retain, uint16_t packetId)
PUBLISH message received callback.
Definition: mqtt_client.h:187
systime_t timeout
Communication timeout.
Definition: mqtt_client.h:304
void(* MqttClientUnsubAckCallback)(MqttClientContext *context, uint16_t packetId)
UNSUBACK message received callback.
Definition: mqtt_client.h:236
size_t payloadPos
Current position within the payload.
Definition: mqtt_client.h:343
uint8_t buffer[MQTT_CLIENT_BUFFER_SIZE]
Internal buffer.
Definition: mqtt_client.h:336
TLS (Transport Layer Security)
uint8_t dup
Definition: mqtt_common.h:182
@ MQTT_CLIENT_STATE_DISCONNECTING
Definition: mqtt_client.h:171
const MqttPublishInfo MQTT_DEFAULT_PUBLISH_INFO
Definition: mqtt_client.c:46
void(* MqttClientPubCompCallback)(MqttClientContext *context, uint16_t packetId)
PUBCOMP message received callback.
Definition: mqtt_client.h:220
@ MQTT_CLIENT_STATE_CONNECTED
Definition: mqtt_client.h:163
PUBLISH packet parameters.
Definition: mqtt_client.h:354
#define MQTT_CLIENT_MAX_PASSWORD_LEN
Definition: mqtt_client.h:103
#define MqttClientContext
Definition: mqtt_client.h:147
MqttQosLevel qos
QoS level to be used when publishing the Will message.
Definition: mqtt_client.h:269
error_t mqttClientSubscribe(MqttClientContext *context, const char_t *topic, MqttQosLevel qos, uint16_t *packetId)
Subscribe to topic.
Definition: mqtt_client.c:898
char_t clientId[]
#define MQTT_CLIENT_MAX_WILL_PAYLOAD_LEN
Definition: mqtt_client.h:117
uint16_t * packetId
Definition: mqtt_client.h:363
TCP/IP stack core.
#define MQTT_CLIENT_MAX_HOST_LEN
Definition: mqtt_client.h:75
error_t mqttClientSetHost(MqttClientContext *context, const char_t *host)
Set the domain name of the server (for virtual hosting)
Definition: mqtt_client.c:278
#define MQTT_CLIENT_BUFFER_SIZE
Definition: mqtt_client.h:124
error_t mqttClientDisconnect(MqttClientContext *context)
Gracefully disconnect from the MQTT server.
Definition: mqtt_client.c:1270
MqttQosLevel qos
Definition: mqtt_client.h:356
size_t packetPos
Current position.
Definition: mqtt_client.h:338
const char_t * topicName
Definition: mqtt_client.h:358
MqttPacketType
MQTT control packet type.
Definition: mqtt_common.h:99
error_t mqttClientRegisterCallbacks(MqttClientContext *context, const MqttClientCallbacks *callbacks)
Register MQTT client callbacks.
Definition: mqtt_client.c:119