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-2019 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 1.9.6
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 //TLS supported?
130 #if (MQTT_CLIENT_TLS_SUPPORT == ENABLED)
131  #include "core/crypto.h"
132  #include "tls.h"
133 #endif
134 
135 //WebSocket supported?
136 #if (MQTT_CLIENT_WS_SUPPORT == ENABLED)
137  #include "web_socket/web_socket.h"
138 #endif
139 
140 //Forward declaration of MqttClientContext structure
141 struct _MqttClientContext;
142 #define MqttClientContext struct _MqttClientContext
143 
144 //C++ guard
145 #ifdef __cplusplus
146 extern "C" {
147 #endif
148 
149 
150 /**
151  * @brief MQTT client states
152  **/
153 
154 typedef enum
155 {
168 
169 
170 /**
171  * @brief CONNACK message received callback
172  **/
173 
175  uint8_t connectAckFlags, uint8_t connectReturnCode);
176 
177 
178 /**
179  * @brief PUBLISH message received callback
180  **/
181 
183  const char_t *topic, const uint8_t *message, size_t length,
185 
186 
187 /**
188  * @brief PUBACK message received callback
189  **/
190 
192  uint16_t packetId);
193 
194 
195 /**
196  * @brief PUBREC message received callback
197  **/
198 
200  uint16_t packetId);
201 
202 
203 /**
204  * @brief PUBREL message received callback
205  **/
206 
208  uint16_t packetId);
209 
210 
211 /**
212  * @brief PUBCOMP message received callback
213  **/
214 
216  uint16_t packetId);
217 
218 
219 /**
220  * @brief SUBACK message received callback
221  **/
222 
224  uint16_t packetId);
225 
226 
227 /**
228  * @brief UNSUBACK message received callback
229  **/
230 
232  uint16_t packetId);
233 
234 
235 /**
236  * @brief PINGRESP message received callback
237  **/
238 
240 
241 
242 //TLS supported?
243 #if (MQTT_CLIENT_TLS_SUPPORT == ENABLED)
244 
245 /**
246  * @brief TLS initialization callback
247  **/
248 
251 
252 #endif
253 
254 
255 /**
256  * @brief Will message
257  **/
258 
259 typedef struct
260 {
261  char_t topic[MQTT_CLIENT_MAX_WILL_TOPIC_LEN + 1]; ///<Will topic name
262  uint8_t payload[MQTT_CLIENT_MAX_WILL_PAYLOAD_LEN]; ///<Will message payload
263  size_t length; ///<Length of the Will message payload
264  MqttQosLevel qos; ///<QoS level to be used when publishing the Will message
265  bool_t retain; ///<Specifies if the Will message is to be retained
267 
268 
269 /**
270  * @brief MQTT client callback functions
271  **/
272 
273 typedef struct
274 {
275  MqttClientConnAckCallback connAckCallback; ///<CONNACK message received callback
276  MqttClientPublishCallback publishCallback; ///<PUBLISH message received callback
277  MqttClientPubAckCallback pubAckCallback; ///<PUBACK message received callback
278  MqttClientPubAckCallback pubRecCallback; ///<PUBREC message received callback
279  MqttClientPubAckCallback pubRelCallback; ///<PUBREL message received callback
280  MqttClientPubAckCallback pubCompCallback; ///<PUBCOMP message received callback
281  MqttClientPubAckCallback subAckCallback; ///<SUBACK message received callback
282  MqttClientPubAckCallback unsubAckCallback; ///<UNSUBACK message received callback
283  MqttClientPingRespCallback pingRespCallback; ///<PINGRESP message received callback
284 #if (MQTT_CLIENT_TLS_SUPPORT == ENABLED)
285  MqttClientTlsInitCallback tlsInitCallback; ///<TLS initialization callback
286 #endif
288 
289 
290 /**
291  * @brief MQTT client settings
292  **/
293 
294 typedef struct
295 {
296  MqttVersion version; ///<MQTT protocol version
297  MqttTransportProtocol transportProtocol; ///<Transport protocol
298  uint16_t keepAlive; ///<Keep-alive time interval
299  systime_t timeout; ///<Communication timeout
300 #if (MQTT_CLIENT_WS_SUPPORT == ENABLED)
301  char_t host[MQTT_CLIENT_MAX_HOST_LEN + 1]; ///<Domain name of the server (for virtual hosting)
302  char_t uri[MQTT_CLIENT_MAX_URI_LEN + 1]; ///<Resource name
303 #endif
304  char_t clientId[MQTT_CLIENT_MAX_ID_LEN + 1]; ///<Client identifier
305  char_t username[MQTT_CLIENT_MAX_USERNAME_LEN + 1]; ///<User name
306  char_t password[MQTT_CLIENT_MAX_PASSWORD_LEN + 1]; ///<Password
309 
310 
311 /**
312  * @brief MQTT client context
313  **/
314 
316 {
317  MqttClientSettings settings; ///<MQTT client settings
318  MqttClientCallbacks callbacks; ///<MQTT client callback functions
319  MqttClientState state; ///<MQTT client state
320  systime_t keepAliveTimestamp; ///<Timestamp used to manage keep-alive
321  systime_t pingTimestamp; ///<Timestamp used to measure round-trip time
322  NetInterface *interface; ///<Underlying network interface
323  Socket *socket; ///<Underlying TCP socket
324 #if (MQTT_CLIENT_TLS_SUPPORT == ENABLED)
325  TlsContext *tlsContext; ///<TLS context
326  TlsSessionState tlsSession; ///<TLS session state
327 #endif
328 #if (MQTT_CLIENT_WS_SUPPORT == ENABLED)
329  WebSocket *webSocket; ///<Underlying WebSocket
330 #endif
331  uint8_t buffer[MQTT_CLIENT_BUFFER_SIZE]; ///<Internal buffer
332  uint8_t *packet; ///<Pointer to the incoming/outgoing MQTT packet
333  size_t packetPos; ///<Current position
334  size_t packetLen; ///<Length of the entire MQTT packet
335  MqttPacketType packetType; ///<Control packet type
336  uint16_t packetId; ///<Packet identifier
337  size_t remainingLen; ///<Length of the variable header and payload
338 };
339 
340 
341 //MQTT client related functions
344 
346  const MqttClientCallbacks *callbacks);
347 
349 
351  MqttTransportProtocol transportProtocol);
352 
353 #if (MQTT_CLIENT_TLS_SUPPORT == ENABLED)
354 
356  MqttClientTlsInitCallback callback);
357 
358 #endif
359 
361  MqttClientPublishCallback callback);
362 
364 error_t mqttClientSetKeepAlive(MqttClientContext *context, uint16_t keepAlive);
365 
366 error_t mqttClientSetHost(MqttClientContext *context, const char_t *host);
367 error_t mqttClientSetUri(MqttClientContext *context, const char_t *uri);
368 
370  const char_t *clientId);
371 
373  const char_t *username, const char_t *password);
374 
376  const void *message, size_t length, MqttQosLevel qos, bool_t retain);
377 
379  NetInterface *interface);
380 
382  const IpAddr *serverIpAddr, uint16_t serverPort, bool_t cleanSession);
383 
385  const char_t *topic, const void *message, size_t length,
386  MqttQosLevel qos, bool_t retain, uint16_t *packetId);
387 
389  const char_t *topic, MqttQosLevel qos, uint16_t *packetId);
390 
392  const char_t *topic, uint16_t *packetId);
393 
395 
397 
400 
401 void mqttClientDeinit(MqttClientContext *context);
402 
403 //Deprecated functions
405 
406 //C++ guard
407 #ifdef __cplusplus
408 }
409 #endif
410 
411 #endif
MqttClientPublishCallback publishCallback
PUBLISH message received callback.
Definition: mqtt_client.h:276
void(* MqttClientPubAckCallback)(MqttClientContext *context, uint16_t packetId)
PUBACK message received callback.
Definition: mqtt_client.h:191
uint8_t length
Definition: dtls_misc.h:149
int bool_t
Definition: compiler_port.h:49
MQTT client context.
Definition: mqtt_client.h:315
MqttClientPubAckCallback pubAckCallback
PUBACK message received callback.
Definition: mqtt_client.h:277
error_t(* MqttClientTlsInitCallback)(MqttClientContext *context, TlsContext *tlsContext)
TLS initialization callback.
Definition: mqtt_client.h:249
error_t mqttClientTask(MqttClientContext *context, systime_t timeout)
Process MQTT client events.
Definition: mqtt_client.c:1044
MqttTransportProtocol transportProtocol
Transport protocol.
Definition: mqtt_client.h:297
WebSocket * webSocket
Underlying WebSocket.
Definition: mqtt_client.h:329
IP network address.
Definition: ip.h:71
MqttTransportProtocol
Transport protocol.
Definition: mqtt_common.h:73
uint16_t packetId
Packet identifier.
Definition: mqtt_client.h:336
void mqttClientDeinit(MqttClientContext *context)
Release MQTT client context.
Definition: mqtt_client.c:1178
MqttPacketType packetType
Control packet type.
Definition: mqtt_client.h:335
MqttVersion version
MQTT protocol version.
Definition: mqtt_client.h:296
WebSocket API (client and server)
error_t mqttClientInit(MqttClientContext *context)
Initialize MQTT client context.
Definition: mqtt_client.c:52
MqttClientState state
MQTT client state.
Definition: mqtt_client.h:319
MqttClientPubAckCallback subAckCallback
SUBACK message received callback.
Definition: mqtt_client.h:281
uint16_t version
Definition: dtls_misc.h:172
TlsContext * tlsContext
TLS context.
Definition: mqtt_client.h:325
void(* MqttClientPubRelCallback)(MqttClientContext *context, uint16_t packetId)
PUBREL message received callback.
Definition: mqtt_client.h:207
systime_t pingTimestamp
Timestamp used to measure round-trip time.
Definition: mqtt_client.h:321
MqttClientPubAckCallback unsubAckCallback
UNSUBACK message received callback.
Definition: mqtt_client.h:282
@ MQTT_CLIENT_STATE_DISCONNECTED
Definition: mqtt_client.h:166
error_t mqttClientSetIdentifier(MqttClientContext *context, const char_t *clientId)
Set client identifier.
Definition: mqtt_client.c:330
uint8_t qos
Definition: mqtt_common.h:179
MqttClientPubAckCallback pubRecCallback
PUBREC message received callback.
Definition: mqtt_client.h:278
@ MQTT_CLIENT_STATE_WAITING_PACKET
Definition: mqtt_client.h:162
void(* MqttClientPubRecCallback)(MqttClientContext *context, uint16_t packetId)
PUBREC message received callback.
Definition: mqtt_client.h:199
size_t packetLen
Length of the entire MQTT packet.
Definition: mqtt_client.h:334
@ MQTT_CLIENT_STATE_SENDING_PACKET
Definition: mqtt_client.h:160
error_t mqttClientSetTimeout(MqttClientContext *context, systime_t timeout)
Set communication timeout.
Definition: mqtt_client.c:232
MQTT client callback functions.
Definition: mqtt_client.h:273
error_t mqttClientUnsubscribe(MqttClientContext *context, const char_t *topic, uint16_t *packetId)
Unsubscribe from topic.
Definition: mqtt_client.c:832
void(* MqttClientConnAckCallback)(MqttClientContext *context, uint8_t connectAckFlags, uint8_t connectReturnCode)
CONNACK message received callback.
Definition: mqtt_client.h:174
MqttClientWillMessage willMessage
Will message.
Definition: mqtt_client.h:307
@ MQTT_CLIENT_STATE_PACKET_RECEIVED
Definition: mqtt_client.h:164
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:473
#define MQTT_CLIENT_MAX_USERNAME_LEN
Definition: mqtt_client.h:96
MqttClientSettings settings
MQTT client settings.
Definition: mqtt_client.h:317
error_t mqttClientClose(MqttClientContext *context)
Close the connection with the MQTT server.
Definition: mqtt_client.c:1157
#define TlsContext
Definition: tls.h:36
error_t
Error codes.
Definition: error.h:42
void(* MqttClientSubAckCallback)(MqttClientContext *context, uint16_t packetId)
SUBACK message received callback.
Definition: mqtt_client.h:223
error_t mqttClientRegisterTlsInitCallback(MqttClientContext *context, MqttClientTlsInitCallback callback)
Register TLS initialization callback function.
Definition: mqtt_client.c:185
uint16_t keepAlive
Keep-alive time interval.
Definition: mqtt_client.h:298
error_t mqttClientSetVersion(MqttClientContext *context, MqttVersion version)
Set the MQTT protocol version to be used.
Definition: mqtt_client.c:139
@ MQTT_CLIENT_STATE_PACKET_SENT
Definition: mqtt_client.h:161
MqttQosLevel
Quality of service level.
Definition: mqtt_common.h:86
uint8_t retain
Definition: mqtt_common.h:178
#define MQTT_CLIENT_MAX_WILL_TOPIC_LEN
Definition: mqtt_client.h:110
MqttClientPingRespCallback pingRespCallback
PINGRESP message received callback.
Definition: mqtt_client.h:283
MqttClientConnAckCallback connAckCallback
CONNACK message received callback.
Definition: mqtt_client.h:275
uint8_t * packet
Pointer to the incoming/outgoing MQTT packet.
Definition: mqtt_client.h:332
#define NetInterface
Definition: net.h:36
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:609
MqttClientPubAckCallback pubRelCallback
PUBREL message received callback.
Definition: mqtt_client.h:279
General definitions for cryptographic algorithms.
MQTT client settings.
Definition: mqtt_client.h:294
error_t mqttClientSetTransportProtocol(MqttClientContext *context, MqttTransportProtocol transportProtocol)
Set the transport protocol to be used.
Definition: mqtt_client.c:161
systime_t keepAliveTimestamp
Timestamp used to manage keep-alive.
Definition: mqtt_client.h:320
error_t mqttClientPing(MqttClientContext *context, systime_t *rtt)
Send ping request.
Definition: mqtt_client.c:935
TlsSessionState tlsSession
TLS session state.
Definition: mqtt_client.h:326
#define MQTT_CLIENT_MAX_URI_LEN
Definition: mqtt_client.h:82
size_t remainingLen
Length of the variable header and payload.
Definition: mqtt_client.h:337
MqttVersion
MQTT protocol level.
Definition: mqtt_common.h:62
#define WebSocket
Definition: web_socket.h:177
bool_t retain
Specifies if the Will message is to be retained.
Definition: mqtt_client.h:265
@ MQTT_CLIENT_STATE_RECEIVING_PACKET
Definition: mqtt_client.h:163
error_t mqttClientSetUri(MqttClientContext *context, const char_t *uri)
Set the name of the resource being requested.
Definition: mqtt_client.c:303
Definitions common to MQTT client and server.
NetInterface * interface
Underlying network interface.
Definition: mqtt_client.h:322
size_t length
Length of the Will message payload.
Definition: mqtt_client.h:263
@ MQTT_CLIENT_STATE_IDLE
Definition: mqtt_client.h:159
char char_t
Definition: compiler_port.h:43
@ MQTT_CLIENT_STATE_CLOSED
Definition: mqtt_client.h:156
MqttClientCallbacks callbacks
MQTT client callback functions.
Definition: mqtt_client.h:318
TLS session state.
Definition: tls.h:1834
MqttClientTlsInitCallback tlsInitCallback
TLS initialization callback.
Definition: mqtt_client.h:285
@ MQTT_CLIENT_STATE_CONNECTING
Definition: mqtt_client.h:157
#define MQTT_CLIENT_MAX_ID_LEN
Definition: mqtt_client.h:89
void(* MqttClientPingRespCallback)(MqttClientContext *context)
PINGRESP message received callback.
Definition: mqtt_client.h:239
error_t mqttClientSetAuthInfo(MqttClientContext *context, const char_t *username, const char_t *password)
Set authentication information.
Definition: mqtt_client.c:357
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:394
void mqttClientInitCallbacks(MqttClientCallbacks *callbacks)
Initialize callback structure.
Definition: mqtt_client.c:103
error_t mqttClientRegisterPublishCallback(MqttClientContext *context, MqttClientPublishCallback callback)
Register publish callback function.
Definition: mqtt_client.c:210
Socket * socket
Underlying TCP socket.
Definition: mqtt_client.h:323
error_t mqttClientSetKeepAlive(MqttClientContext *context, uint16_t keepAlive)
Set keep-alive value.
Definition: mqtt_client.c:255
error_t mqttClientBindToInterface(MqttClientContext *context, NetInterface *interface)
Bind the MQTT client to a particular network interface.
Definition: mqtt_client.c:447
MqttClientPubAckCallback pubCompCallback
PUBCOMP message received callback.
Definition: mqtt_client.h:280
uint8_t cleanSession
#define Socket
Definition: socket.h:36
MqttClientState
MQTT client states.
Definition: mqtt_client.h:154
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:182
systime_t timeout
Communication timeout.
Definition: mqtt_client.h:299
void(* MqttClientUnsubAckCallback)(MqttClientContext *context, uint16_t packetId)
UNSUBACK message received callback.
Definition: mqtt_client.h:231
uint8_t message[]
Definition: chap.h:152
uint8_t buffer[MQTT_CLIENT_BUFFER_SIZE]
Internal buffer.
Definition: mqtt_client.h:331
TLS (Transport Layer Security)
uint8_t dup
Definition: mqtt_common.h:180
@ MQTT_CLIENT_STATE_DISCONNECTING
Definition: mqtt_client.h:165
void(* MqttClientPubCompCallback)(MqttClientContext *context, uint16_t packetId)
PUBCOMP message received callback.
Definition: mqtt_client.h:215
@ MQTT_CLIENT_STATE_CONNECTED
Definition: mqtt_client.h:158
#define MQTT_CLIENT_MAX_PASSWORD_LEN
Definition: mqtt_client.h:103
#define MqttClientContext
Definition: mqtt_client.h:142
MqttQosLevel qos
QoS level to be used when publishing the Will message.
Definition: mqtt_client.h:264
error_t mqttClientSubscribe(MqttClientContext *context, const char_t *topic, MqttQosLevel qos, uint16_t *packetId)
Subscribe to topic.
Definition: mqtt_client.c:728
char_t clientId[]
#define MQTT_CLIENT_MAX_WILL_PAYLOAD_LEN
Definition: mqtt_client.h:117
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:276
#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:1073
size_t packetPos
Current position.
Definition: mqtt_client.h:333
uint32_t systime_t
Definition: compiler_port.h:46
MqttPacketType
MQTT control packet type.
Definition: mqtt_common.h:98
error_t mqttClientRegisterCallbacks(MqttClientContext *context, const MqttClientCallbacks *callbacks)
Register MQTT client callbacks.
Definition: mqtt_client.c:117