MQTT-C
mqtt.h
Go to the documentation of this file.
1 #ifndef __MQTT_H__
2 #define __MQTT_H__
3 
4 /*
5 MIT License
6 
7 Copyright(c) 2018 Liam Bindle
8 
9 Permission is hereby granted, free of charge, to any person obtaining a copy
10 of this software and associated documentation files(the "Software"), to deal
11 in the Software without restriction, including without limitation the rights
12 to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
13 copies of the Software, and to permit persons to whom the Software is
14 furnished to do so, subject to the following conditions :
15 
16 The above copyright notice and this permission notice shall be included in all
17 copies or substantial portions of the Software.
18 
19 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
20 IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
21 FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.IN NO EVENT SHALL THE
22 AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
23 LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
24 OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
25 SOFTWARE.
26 */
27 
28 #include <mqtt_pal.h>
29 
116  MQTT_CONTROL_CONNECT=1u,
117  MQTT_CONTROL_CONNACK=2u,
118  MQTT_CONTROL_PUBLISH=3u,
119  MQTT_CONTROL_PUBACK=4u,
120  MQTT_CONTROL_PUBREC=5u,
121  MQTT_CONTROL_PUBREL=6u,
122  MQTT_CONTROL_PUBCOMP=7u,
123  MQTT_CONTROL_SUBSCRIBE=8u,
124  MQTT_CONTROL_SUBACK=9u,
125  MQTT_CONTROL_UNSUBSCRIBE=10u,
126  MQTT_CONTROL_UNSUBACK=11u,
127  MQTT_CONTROL_PINGREQ=12u,
128  MQTT_CONTROL_PINGRESP=13u,
129  MQTT_CONTROL_DISCONNECT=14u
130 };
131 
143 
145  uint32_t control_flags: 4;
146 
149 };
150 
159 #define MQTT_PROTOCOL_LEVEL 0x04
160 
165 #define __ALL_MQTT_ERRORS(MQTT_ERROR) \
166  MQTT_ERROR(MQTT_ERROR_NULLPTR) \
167  MQTT_ERROR(MQTT_ERROR_CONTROL_FORBIDDEN_TYPE) \
168  MQTT_ERROR(MQTT_ERROR_CONTROL_INVALID_FLAGS) \
169  MQTT_ERROR(MQTT_ERROR_CONTROL_WRONG_TYPE) \
170  MQTT_ERROR(MQTT_ERROR_CONNECT_NULL_CLIENT_ID) \
171  MQTT_ERROR(MQTT_ERROR_CONNECT_NULL_WILL_MESSAGE) \
172  MQTT_ERROR(MQTT_ERROR_CONNECT_FORBIDDEN_WILL_QOS) \
173  MQTT_ERROR(MQTT_ERROR_CONNACK_FORBIDDEN_FLAGS) \
174  MQTT_ERROR(MQTT_ERROR_CONNACK_FORBIDDEN_CODE) \
175  MQTT_ERROR(MQTT_ERROR_PUBLISH_FORBIDDEN_QOS) \
176  MQTT_ERROR(MQTT_ERROR_SUBSCRIBE_TOO_MANY_TOPICS) \
177  MQTT_ERROR(MQTT_ERROR_MALFORMED_RESPONSE) \
178  MQTT_ERROR(MQTT_ERROR_UNSUBSCRIBE_TOO_MANY_TOPICS) \
179  MQTT_ERROR(MQTT_ERROR_RESPONSE_INVALID_CONTROL_TYPE) \
180  MQTT_ERROR(MQTT_ERROR_CONNECT_NOT_CALLED) \
181  MQTT_ERROR(MQTT_ERROR_SEND_BUFFER_IS_FULL) \
182  MQTT_ERROR(MQTT_ERROR_SOCKET_ERROR) \
183  MQTT_ERROR(MQTT_ERROR_MALFORMED_REQUEST) \
184  MQTT_ERROR(MQTT_ERROR_RECV_BUFFER_TOO_SMALL) \
185  MQTT_ERROR(MQTT_ERROR_ACK_OF_UNKNOWN) \
186  MQTT_ERROR(MQTT_ERROR_NOT_IMPLEMENTED) \
187  MQTT_ERROR(MQTT_ERROR_CONNECTION_REFUSED) \
188  MQTT_ERROR(MQTT_ERROR_SUBSCRIBE_FAILED) \
189  MQTT_ERROR(MQTT_ERROR_CONNECTION_CLOSED) \
190  MQTT_ERROR(MQTT_ERROR_INITIAL_RECONNECT) \
191  MQTT_ERROR(MQTT_ERROR_INVALID_REMAINING_LENGTH)
192 
193 /* todo: add more connection refused errors */
194 
200 #define GENERATE_ENUM(ENUM) ENUM,
201 
207 #define GENERATE_STRING(STRING) #STRING,
208 
209 
217  MQTT_ERROR_UNKNOWN=INT_MIN,
219  MQTT_OK = 1
220 };
221 
230 const char* mqtt_error_str(enum MQTTErrors error);
231 
242 ssize_t __mqtt_pack_uint16(uint8_t *buf, uint16_t integer);
243 
253 uint16_t __mqtt_unpack_uint16(const uint8_t *buf);
254 
265 ssize_t __mqtt_pack_str(uint8_t *buf, const char* str);
266 
268 #define __mqtt_packed_cstrlen(x) (2 + strlen(x))
269 
270 /* RESPONSES */
271 
281  MQTT_CONNACK_ACCEPTED = 0u,
282  MQTT_CONNACK_REFUSED_PROTOCOL_VERSION = 1u,
283  MQTT_CONNACK_REFUSED_IDENTIFIER_REJECTED = 2u,
284  MQTT_CONNACK_REFUSED_SERVER_UNAVAILABLE = 3u,
285  MQTT_CONNACK_REFUSED_BAD_USER_NAME_OR_PASSWORD = 4u,
286  MQTT_CONNACK_REFUSED_NOT_AUTHORIZED = 5u
287 };
288 
297 struct mqtt_response_connack {
302  uint8_t session_present_flag;
303 
309  enum MQTTConnackReturnCode return_code;
310 };
311 
323 struct mqtt_response_publish {
328  uint8_t dup_flag;
329 
337  uint8_t qos_level;
338 
340  uint8_t retain_flag;
341 
343  uint16_t topic_name_size;
344 
350  const void* topic_name;
351 
353  uint16_t packet_id;
354 
356  const void* application_message;
357 
359  size_t application_message_size;
360 };
361 
371 struct mqtt_response_puback {
373  uint16_t packet_id;
374 };
375 
385 struct mqtt_response_pubrec {
387  uint16_t packet_id;
388 };
389 
399 struct mqtt_response_pubrel {
401  uint16_t packet_id;
402 };
403 
413 struct mqtt_response_pubcomp {
415  uint16_t packet_id;
416 };
417 
427  MQTT_SUBACK_SUCCESS_MAX_QOS_0 = 0u,
428  MQTT_SUBACK_SUCCESS_MAX_QOS_1 = 1u,
429  MQTT_SUBACK_SUCCESS_MAX_QOS_2 = 2u,
430  MQTT_SUBACK_FAILURE = 128u
431 };
432 
441 struct mqtt_response_suback {
443  uint16_t packet_id;
444 
450  const uint8_t *return_codes;
451 
453  size_t num_return_codes;
454 };
455 
464 struct mqtt_response_unsuback {
466  uint16_t packet_id;
467 };
468 
479 struct mqtt_response_pingresp {
480  int dummy;
481 };
482 
487 struct mqtt_response {
489  struct mqtt_fixed_header fixed_header;
490 
499  union {
500  struct mqtt_response_connack connack;
501  struct mqtt_response_publish publish;
502  struct mqtt_response_puback puback;
503  struct mqtt_response_pubrec pubrec;
504  struct mqtt_response_pubrel pubrel;
505  struct mqtt_response_pubcomp pubcomp;
506  struct mqtt_response_suback suback;
507  struct mqtt_response_unsuback unsuback;
508  struct mqtt_response_pingresp pingresp;
509  } decoded;
510 };
511 
526 ssize_t mqtt_unpack_fixed_header(struct mqtt_response *response, const uint8_t *buf, size_t bufsz);
527 
544 ssize_t mqtt_unpack_connack_response (struct mqtt_response *mqtt_response, const uint8_t *buf);
545 
561 ssize_t mqtt_unpack_publish_response (struct mqtt_response *mqtt_response, const uint8_t *buf);
562 
579 ssize_t mqtt_unpack_pubxxx_response(struct mqtt_response *mqtt_response, const uint8_t *buf);
580 
596 ssize_t mqtt_unpack_suback_response(struct mqtt_response *mqtt_response, const uint8_t *buf);
597 
613 ssize_t mqtt_unpack_unsuback_response(struct mqtt_response *mqtt_response, const uint8_t *buf);
614 
628 ssize_t mqtt_unpack_response(struct mqtt_response* response, const uint8_t *buf, size_t bufsz);
629 
630 /* REQUESTS */
631 
646 ssize_t mqtt_pack_fixed_header(uint8_t *buf, size_t bufsz, const struct mqtt_fixed_header *fixed_header);
647 
656 enum MQTTConnectFlags {
657  MQTT_CONNECT_RESERVED = 1u,
658  MQTT_CONNECT_CLEAN_SESSION = 2u,
659  MQTT_CONNECT_WILL_FLAG = 4u,
660  MQTT_CONNECT_WILL_QOS_0 = (0u & 0x03) << 3,
661  MQTT_CONNECT_WILL_QOS_1 = (1u & 0x03) << 3,
662  MQTT_CONNECT_WILL_QOS_2 = (2u & 0x03) << 3,
663  MQTT_CONNECT_WILL_RETAIN = 32u,
664  MQTT_CONNECT_PASSWORD = 64u,
665  MQTT_CONNECT_USER_NAME = 128u
666 };
667 
706 ssize_t mqtt_pack_connection_request(uint8_t* buf, size_t bufsz,
707  const char* client_id,
708  const char* will_topic,
709  const void* will_message,
710  size_t will_message_size,
711  const char* user_name,
712  const char* password,
713  uint8_t connect_flags,
714  uint16_t keep_alive);
715 
724 enum MQTTPublishFlags {
725  MQTT_PUBLISH_DUP = 8u,
726  MQTT_PUBLISH_QOS_0 = ((0u << 1) & 0x06),
727  MQTT_PUBLISH_QOS_1 = ((1u << 1) & 0x06),
728  MQTT_PUBLISH_QOS_2 = ((2u << 1) & 0x06),
729  MQTT_PUBLISH_QOS_MASK = ((3u << 1) & 0x06),
730  MQTT_PUBLISH_RETAIN = 0x01
731 };
732 
756 ssize_t mqtt_pack_publish_request(uint8_t *buf, size_t bufsz,
757  const char* topic_name,
758  uint16_t packet_id,
759  void* application_message,
760  size_t application_message_size,
761  uint8_t publish_flags);
762 
791 ssize_t mqtt_pack_pubxxx_request(uint8_t *buf, size_t bufsz,
793  uint16_t packet_id);
794 
802 #define MQTT_SUBSCRIBE_REQUEST_MAX_NUM_TOPICS 8
803 
826 ssize_t mqtt_pack_subscribe_request(uint8_t *buf, size_t bufsz,
827  unsigned int packet_id,
828  ...); /* null terminated */
829 
837 #define MQTT_UNSUBSCRIBE_REQUEST_MAX_NUM_TOPICS 8
838 
860 ssize_t mqtt_pack_unsubscribe_request(uint8_t *buf, size_t bufsz,
861  unsigned int packet_id,
862  ...); /* null terminated */
863 
878 ssize_t mqtt_pack_ping_request(uint8_t *buf, size_t bufsz);
879 
894 ssize_t mqtt_pack_disconnect(uint8_t *buf, size_t bufsz);
895 
896 
902  MQTT_QUEUED_UNSENT,
903  MQTT_QUEUED_AWAITING_ACK,
904  MQTT_QUEUED_COMPLETE
905 };
906 
911 struct mqtt_queued_message {
913  uint8_t *start;
914 
916  size_t size;
917 
919  enum MQTTQueuedMessageState state;
920 
927  mqtt_pal_time_t time_sent;
928 
933 
940  uint16_t packet_id;
941 };
942 
950 struct mqtt_message_queue {
956  void *mem_start;
957 
959  void *mem_end;
960 
967  uint8_t *curr;
968 
977  size_t curr_sz;
978 
984  struct mqtt_queued_message *queue_tail;
985 };
986 
997 void mqtt_mq_init(struct mqtt_message_queue *mq, void *buf, size_t bufsz);
998 
1009 void mqtt_mq_clean(struct mqtt_message_queue *mq);
1010 
1027 struct mqtt_queued_message* mqtt_mq_register(struct mqtt_message_queue *mq, size_t nbytes);
1028 
1041 struct mqtt_queued_message* mqtt_mq_find(struct mqtt_message_queue *mq, enum MQTTControlPacketType control_type, uint16_t *packet_id);
1042 
1052 #define mqtt_mq_get(mq_ptr, index) (((struct mqtt_queued_message*) ((mq_ptr)->mem_end)) - 1 - index)
1053 
1058 #define mqtt_mq_length(mq_ptr) (((struct mqtt_queued_message*) ((mq_ptr)->mem_end)) - (mq_ptr)->queue_tail)
1059 
1064 #define mqtt_mq_currsz(mq_ptr) (mq_ptr->curr >= (uint8_t*) ((mq_ptr)->queue_tail - 1)) ? 0 : ((uint8_t*) ((mq_ptr)->queue_tail - 1)) - (mq_ptr)->curr
1065 
1066 /* CLIENT */
1067 
1074 struct mqtt_client {
1076  mqtt_pal_socket_handle socketfd;
1077 
1079  uint16_t pid_lfsr;
1080 
1082  uint16_t keep_alive;
1083 
1088  int number_of_keep_alives;
1089 
1097  mqtt_pal_time_t time_of_last_send;
1098 
1107  enum MQTTErrors error;
1108 
1117  int response_timeout;
1118 
1120  int number_of_timeouts;
1121 
1128  double typical_response_time;
1129 
1141  void (*publish_response_callback)(void** state, struct mqtt_response_publish *publish);
1142 
1149  void* publish_response_callback_state;
1150 
1166  enum MQTTErrors (*inspector_callback)(struct mqtt_client*);
1167 
1175  void (*reconnect_callback)(struct mqtt_client*, void**);
1176 
1181  void* reconnect_state;
1182 
1186  struct {
1188  uint8_t *mem_start;
1189 
1191  size_t mem_size;
1192 
1194  uint8_t *curr;
1195 
1197  size_t curr_sz;
1198  } recv_buffer;
1199 
1206  mqtt_pal_mutex_t mutex;
1207 
1209  struct mqtt_message_queue mq;
1210 };
1211 
1222 uint16_t __mqtt_next_pid(struct mqtt_client *client);
1223 
1232 ssize_t __mqtt_send(struct mqtt_client *client);
1233 
1242 ssize_t __mqtt_recv(struct mqtt_client *client);
1243 
1270 enum MQTTErrors mqtt_sync(struct mqtt_client *client);
1271 
1305 enum MQTTErrors mqtt_init(struct mqtt_client *client,
1306  mqtt_pal_socket_handle sockfd,
1307  uint8_t *sendbuf, size_t sendbufsz,
1308  uint8_t *recvbuf, size_t recvbufsz,
1309  void (*publish_response_callback)(void** state, struct mqtt_response_publish *publish));
1310 
1355 void mqtt_init_reconnect(struct mqtt_client *client,
1356  void (*reconnect_callback)(struct mqtt_client *client, void** state),
1357  void *reconnect_state,
1358  void (*publish_response_callback)(void** state, struct mqtt_response_publish *publish));
1359 
1382 void mqtt_reinit(struct mqtt_client* client,
1383  mqtt_pal_socket_handle socketfd,
1384  uint8_t *sendbuf, size_t sendbufsz,
1385  uint8_t *recvbuf, size_t recvbufsz);
1386 
1413 enum MQTTErrors mqtt_connect(struct mqtt_client *client,
1414  const char* client_id,
1415  const char* will_topic,
1416  const void* will_message,
1417  size_t will_message_size,
1418  const char* user_name,
1419  const char* password,
1420  uint8_t connect_flags,
1421  uint16_t keep_alive);
1422 
1423 /*
1424  todo: will_message should be a void*
1425 */
1426 
1445 enum MQTTErrors mqtt_publish(struct mqtt_client *client,
1446  const char* topic_name,
1447  void* application_message,
1448  size_t application_message_size,
1449  uint8_t publish_flags);
1450 
1460 ssize_t __mqtt_puback(struct mqtt_client *client, uint16_t packet_id);
1461 
1471 ssize_t __mqtt_pubrec(struct mqtt_client *client, uint16_t packet_id);
1472 
1482 ssize_t __mqtt_pubrel(struct mqtt_client *client, uint16_t packet_id);
1483 
1493 ssize_t __mqtt_pubcomp(struct mqtt_client *client, uint16_t packet_id);
1494 
1495 
1509 enum MQTTErrors mqtt_subscribe(struct mqtt_client *client,
1510  const char* topic_name,
1511  int max_qos_level);
1512 
1524 enum MQTTErrors mqtt_unsubscribe(struct mqtt_client *client,
1525  const char* topic_name);
1526 
1537 enum MQTTErrors mqtt_ping(struct mqtt_client *client);
1538 
1543 enum MQTTErrors __mqtt_ping(struct mqtt_client *client);
1544 
1557 enum MQTTErrors mqtt_disconnect(struct mqtt_client *client);
1558 
1559 #endif
MQTTConnackReturnCode
An enumeration of the return codes returned in a CONNACK packet.
Definition: mqtt.h:279
void * reconnect_state
A pointer to some state. A pointer to this member is passed to mqtt_client::reconnect_callback.
Definition: mqtt.h:1180
MQTTControlPacketType
An enumeration of the MQTT control packet types.
Definition: mqtt.h:115
MQTTQueuedMessageState
An enumeration of queued message states.
Definition: mqtt.h:900
void(* reconnect_callback)(struct mqtt_client *, void **)
A callback that is called whenever the client is in an error state.
Definition: mqtt.h:1174
void mqtt_reinit(struct mqtt_client *client, mqtt_pal_socket_handle socketfd, uint8_t *sendbuf, size_t sendbufsz, uint8_t *recvbuf, size_t recvbufsz)
Safely assign/reassign a socket and buffers to an new/existing client.This function also clears the c...
enum MQTTErrors __mqtt_ping(struct mqtt_client *client)
Ping the broker without locking/unlocking the mutex.
ssize_t __mqtt_recv(struct mqtt_client *client)
Handles ingress client traffic.
The brokers response to a UNSUBSCRIBE request.
Definition: mqtt.h:463
A connection response datastructure.
Definition: mqtt.h:296
enum MQTTErrors mqtt_init(struct mqtt_client *client, mqtt_pal_socket_handle sockfd, uint8_t *sendbuf, size_t sendbufsz, uint8_t *recvbuf, size_t recvbufsz, void(*publish_response_callback)(void **state, struct mqtt_response_publish *publish))
Initializes an MQTT client.This function must be called before any other API function calls...
uint16_t packet_id
The packet id of the message.
Definition: mqtt.h:939
ssize_t __mqtt_send(struct mqtt_client *client)
Handles egress client traffic.
ssize_t mqtt_pack_pubxxx_request(uint8_t *buf, size_t bufsz, enum MQTTControlPacketType control_type, uint16_t packet_id)
Serialize a PUBACK, PUBREC, PUBREL, or PUBCOMP packet and put it in buf.
The response to a ping request.
Definition: mqtt.h:478
uint16_t __mqtt_next_pid(struct mqtt_client *client)
Generate a new next packet ID.Packet ID&#39;s are generated using a max-length LFSR.
The response packet to a PUBLISH packet with QoS level 2.
Definition: mqtt.h:384
uint16_t __mqtt_unpack_uint16(const uint8_t *buf)
Unpack a MQTT 16 bit integer to a native 16 bit integer.
The response to a PUBREC packet.
Definition: mqtt.h:398
void mqtt_init_reconnect(struct mqtt_client *client, void(*reconnect_callback)(struct mqtt_client *client, void **state), void *reconnect_state, void(*publish_response_callback)(void **state, struct mqtt_response_publish *publish))
Initializes an MQTT client and enables automatic reconnections.An alternative to mqtt_init that allow...
#define __ALL_MQTT_ERRORS(MQTT_ERROR)
A macro used to declare the enum MQTTErrors and associated error messages (the members of the num) at...
Definition: mqtt.h:165
ssize_t __mqtt_pack_str(uint8_t *buf, const char *str)
Pack a MQTT string, given a c-string str.
enum MQTTErrors mqtt_ping(struct mqtt_client *client)
Ping the broker.
enum MQTTControlPacketType control_type
Definition: mqtt.h:142
enum MQTTErrors mqtt_unsubscribe(struct mqtt_client *client, const char *topic_name)
Unsubscribe from a topic.
ssize_t mqtt_pack_disconnect(uint8_t *buf, size_t bufsz)
Serialize a DISCONNECT and put it into buf.
A publish packet received from the broker.A publish packet is received from the broker when a client ...
Definition: mqtt.h:322
uint32_t remaining_length
Definition: mqtt.h:148
ssize_t __mqtt_pack_uint16(uint8_t *buf, uint16_t integer)
Pack a MQTT 16 bit integer, given a native 16 bit integer .
MQTTErrors
An enumeration of error codes. Error messages can be retrieved by calling mqtt_error_str.
Definition: mqtt.h:216
ssize_t mqtt_pack_subscribe_request(uint8_t *buf, size_t bufsz, unsigned int packet_id,...)
Serialize a SUBSCRIBE packet and put it in buf.
A publish acknowledgement for messages that were published with QoS level 1.
Definition: mqtt.h:370
ssize_t mqtt_pack_connection_request(uint8_t *buf, size_t bufsz, const char *client_id, const char *will_topic, const void *will_message, size_t will_message_size, const char *user_name, const char *password, uint8_t connect_flags, uint16_t keep_alive)
Serialize a connection request into a buffer.
ssize_t mqtt_pack_ping_request(uint8_t *buf, size_t bufsz)
Serialize a PINGREQ and put it into buf.
ssize_t __mqtt_pubrec(struct mqtt_client *client, uint16_t packet_id)
Acknowledge an ingree publish with QOS==2.
ssize_t mqtt_unpack_fixed_header(struct mqtt_response *response, const uint8_t *buf, size_t bufsz)
Deserialize the contents of buf into an mqtt_fixed_header object.
enum MQTTErrors mqtt_subscribe(struct mqtt_client *client, const char *topic_name, int max_qos_level)
Subscribe to a topic.
ssize_t __mqtt_pubcomp(struct mqtt_client *client, uint16_t packet_id)
Acknowledge an ingree PUBREL packet.
const char * mqtt_error_str(enum MQTTErrors error)
Returns an error message for error code, error.
#define GENERATE_ENUM(ENUM)
A macro used to generate the enum MQTTErrors from __ALL_MQTT_ERRORS.
Definition: mqtt.h:200
enum MQTTErrors mqtt_publish(struct mqtt_client *client, const char *topic_name, void *application_message, size_t application_message_size, uint8_t publish_flags)
Publish an application message.Publishes an application message to the MQTT broker.
ssize_t mqtt_pack_unsubscribe_request(uint8_t *buf, size_t bufsz, unsigned int packet_id,...)
Serialize a UNSUBSCRIBE packet and put it in buf.
ssize_t __mqtt_puback(struct mqtt_client *client, uint16_t packet_id)
Acknowledge an ingree publish with QOS==1.
uint32_t control_flags
Definition: mqtt.h:145
Includes/supports the types/calls required by the MQTT-C client.
MQTTPublishFlags
An enumeration of the PUBLISH flags.
Definition: mqtt.h:723
enum MQTTErrors mqtt_connect(struct mqtt_client *client, const char *client_id, const char *will_topic, const void *will_message, size_t will_message_size, const char *user_name, const char *password, uint8_t connect_flags, uint16_t keep_alive)
Establishes a session with the MQTT broker.
ssize_t mqtt_pack_fixed_header(uint8_t *buf, size_t bufsz, const struct mqtt_fixed_header *fixed_header)
Serialize an mqtt_fixed_header and write it to buf.
enum MQTTErrors mqtt_sync(struct mqtt_client *client)
Function that does the actual sending and receiving of traffic from the network.All the other functio...
The response to a subscription request.
Definition: mqtt.h:440
enum MQTTErrors mqtt_disconnect(struct mqtt_client *client)
Terminate the session with the MQTT broker.
ssize_t __mqtt_pubrel(struct mqtt_client *client, uint16_t packet_id)
Acknowledge an ingree PUBREC packet.
A message queue.
Definition: mqtt.h:949
MQTTSubackReturnCodes
An enumeration of subscription acknowledgement return codes.
Definition: mqtt.h:425
MQTTConnectFlags
An enumeration of CONNECT packet flags.
Definition: mqtt.h:655
A struct used to deserialize/interpret an incoming packet from the broker.
Definition: mqtt.h:486
ssize_t mqtt_pack_publish_request(uint8_t *buf, size_t bufsz, const char *topic_name, uint16_t packet_id, void *application_message, size_t application_message_size, uint8_t publish_flags)
Serialize a PUBLISH request and put it in buf.
The response to a PUBREL packet.
Definition: mqtt.h:412
An MQTT client.
Definition: mqtt.h:1073
A message in a mqtt_message_queue.
Definition: mqtt.h:910
The fixed header of an MQTT control packet.
Definition: mqtt.h:140