forked from LiamBindle/MQTT-C
-
Notifications
You must be signed in to change notification settings - Fork 0
/
group__api.html
726 lines (697 loc) · 48.5 KB
/
group__api.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/xhtml;charset=UTF-8"/>
<meta http-equiv="X-UA-Compatible" content="IE=9"/>
<meta name="generator" content="Doxygen 1.8.13"/>
<meta name="viewport" content="width=device-width, initial-scale=1"/>
<title>MQTT-C: API</title>
<link href="tabs.css" rel="stylesheet" type="text/css"/>
<script type="text/javascript" src="jquery.js"></script>
<script type="text/javascript" src="dynsections.js"></script>
<link href="doxygen.css" rel="stylesheet" type="text/css" />
</head>
<body>
<div id="top"><!-- do not remove this div, it is closed by doxygen! -->
<div id="titlearea">
<table cellspacing="0" cellpadding="0">
<tbody>
<tr style="height: 56px;">
<td id="projectalign" style="padding-left: 0.5em;">
<div id="projectname">MQTT-C
</div>
</td>
</tr>
</tbody>
</table>
</div>
<!-- end header part -->
<!-- Generated by Doxygen 1.8.13 -->
<script type="text/javascript" src="menudata.js"></script>
<script type="text/javascript" src="menu.js"></script>
<script type="text/javascript">
$(function() {
initMenu('',false,false,'search.php','Search');
});
</script>
<div id="main-nav"></div>
</div><!-- top -->
<div class="header">
<div class="summary">
<a href="#enum-members">Enumerations</a> |
<a href="#func-members">Functions</a> </div>
<div class="headertitle">
<div class="title">API</div> </div>
</div><!--header-->
<div class="contents">
<p>Documentation of everything you need to know to use the MQTT-C client.
<a href="#details">More...</a></p>
<table class="memberdecls">
<tr class="heading"><td colspan="2"><h2 class="groupheader"><a name="enum-members"></a>
Enumerations</h2></td></tr>
<tr class="memitem:gad0c901a8d30691ed0ca17915b691b7e7"><td class="memItemLeft" align="right" valign="top">enum  </td><td class="memItemRight" valign="bottom"><a class="el" href="group__api.html#gad0c901a8d30691ed0ca17915b691b7e7">MQTTErrors</a> { <br />
  <b>MQTT_ERROR_UNKNOWN</b> =INT_MIN,
<b>MQTT_ERROR_NULLPTR</b>,
<b>MQTT_ERROR_CONTROL_FORBIDDEN_TYPE</b>,
<b>MQTT_ERROR_CONTROL_INVALID_FLAGS</b>,
<br />
  <b>MQTT_ERROR_CONTROL_WRONG_TYPE</b>,
<b>MQTT_ERROR_CONNECT_NULL_CLIENT_ID</b>,
<b>MQTT_ERROR_CONNECT_NULL_WILL_MESSAGE</b>,
<b>MQTT_ERROR_CONNECT_FORBIDDEN_WILL_QOS</b>,
<br />
  <b>MQTT_ERROR_CONNACK_FORBIDDEN_FLAGS</b>,
<b>MQTT_ERROR_CONNACK_FORBIDDEN_CODE</b>,
<b>MQTT_ERROR_PUBLISH_FORBIDDEN_QOS</b>,
<b>MQTT_ERROR_SUBSCRIBE_TOO_MANY_TOPICS</b>,
<br />
  <b>MQTT_ERROR_MALFORMED_RESPONSE</b>,
<b>MQTT_ERROR_UNSUBSCRIBE_TOO_MANY_TOPICS</b>,
<b>MQTT_ERROR_RESPONSE_INVALID_CONTROL_TYPE</b>,
<b>MQTT_ERROR_CONNECT_NOT_CALLED</b>,
<br />
  <b>MQTT_ERROR_SEND_BUFFER_IS_FULL</b>,
<b>MQTT_ERROR_SOCKET_ERROR</b>,
<b>MQTT_ERROR_MALFORMED_REQUEST</b>,
<b>MQTT_ERROR_RECV_BUFFER_TOO_SMALL</b>,
<br />
  <b>MQTT_ERROR_ACK_OF_UNKNOWN</b>,
<b>MQTT_ERROR_NOT_IMPLEMENTED</b>,
<b>MQTT_ERROR_CONNECTION_REFUSED</b>,
<b>MQTT_ERROR_SUBSCRIBE_FAILED</b>,
<br />
  <b>MQTT_ERROR_CONNECTION_CLOSED</b>,
<b>MQTT_ERROR_INITIAL_RECONNECT</b>,
<b>MQTT_ERROR_INVALID_REMAINING_LENGTH</b>,
<b>MQTT_OK</b> = 1
<br />
}<tr class="memdesc:gad0c901a8d30691ed0ca17915b691b7e7"><td class="mdescLeft"> </td><td class="mdescRight">An enumeration of error codes. Error messages can be retrieved by calling <a class="el" href="group__api.html#ga47b62bdd24e8b05957825d2419d7c848">mqtt_error_str</a>. <a href="group__api.html#gad0c901a8d30691ed0ca17915b691b7e7">More...</a><br /></td></tr>
</td></tr>
<tr class="separator:gad0c901a8d30691ed0ca17915b691b7e7"><td class="memSeparator" colspan="2"> </td></tr>
</table><table class="memberdecls">
<tr class="heading"><td colspan="2"><h2 class="groupheader"><a name="func-members"></a>
Functions</h2></td></tr>
<tr class="memitem:ga47b62bdd24e8b05957825d2419d7c848"><td class="memItemLeft" align="right" valign="top">const char * </td><td class="memItemRight" valign="bottom"><a class="el" href="group__api.html#ga47b62bdd24e8b05957825d2419d7c848">mqtt_error_str</a> (enum <a class="el" href="group__api.html#gad0c901a8d30691ed0ca17915b691b7e7">MQTTErrors</a> error)</td></tr>
<tr class="memdesc:ga47b62bdd24e8b05957825d2419d7c848"><td class="mdescLeft"> </td><td class="mdescRight">Returns an error message for error code, <code>error</code>. <a href="#ga47b62bdd24e8b05957825d2419d7c848">More...</a><br /></td></tr>
<tr class="separator:ga47b62bdd24e8b05957825d2419d7c848"><td class="memSeparator" colspan="2"> </td></tr>
<tr class="memitem:gae3d3aafc7588ed53a90c9f66fc620a6e"><td class="memItemLeft" align="right" valign="top">enum <a class="el" href="group__api.html#gad0c901a8d30691ed0ca17915b691b7e7">MQTTErrors</a> </td><td class="memItemRight" valign="bottom"><a class="el" href="group__api.html#gae3d3aafc7588ed53a90c9f66fc620a6e">mqtt_sync</a> (struct <a class="el" href="structmqtt__client.html">mqtt_client</a> *client)</td></tr>
<tr class="memdesc:gae3d3aafc7588ed53a90c9f66fc620a6e"><td class="mdescLeft"> </td><td class="mdescRight">Function that does the actual sending and receiving of traffic from the network.All the other functions in the <a class="el" href="group__api.html">API</a> simply stage messages for being sent to the broker. This function does the actual sending of those messages. Additionally this function receives traffic (responses and acknowledgements) from the broker and responds to that traffic accordingly. Lastly this function also calls the <code>publish_response_callback</code> when any <code>MQTT_CONTROL_PUBLISH</code> messages are received. <a href="#gae3d3aafc7588ed53a90c9f66fc620a6e">More...</a><br /></td></tr>
<tr class="separator:gae3d3aafc7588ed53a90c9f66fc620a6e"><td class="memSeparator" colspan="2"> </td></tr>
<tr class="memitem:gaa5dab8a06f016b09c7a5259274b3b3ce"><td class="memItemLeft" align="right" valign="top">enum <a class="el" href="group__api.html#gad0c901a8d30691ed0ca17915b691b7e7">MQTTErrors</a> </td><td class="memItemRight" valign="bottom"><a class="el" href="group__api.html#gaa5dab8a06f016b09c7a5259274b3b3ce">mqtt_init</a> (struct <a class="el" href="structmqtt__client.html">mqtt_client</a> *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 <a class="el" href="structmqtt__response__publish.html">mqtt_response_publish</a> *publish))</td></tr>
<tr class="memdesc:gaa5dab8a06f016b09c7a5259274b3b3ce"><td class="mdescLeft"> </td><td class="mdescRight">Initializes an MQTT client.This function <em>must</em> be called before any other API function calls. <a href="#gaa5dab8a06f016b09c7a5259274b3b3ce">More...</a><br /></td></tr>
<tr class="separator:gaa5dab8a06f016b09c7a5259274b3b3ce"><td class="memSeparator" colspan="2"> </td></tr>
<tr class="memitem:ga4becaa66425469cf462b531aa7eb1ac9"><td class="memItemLeft" align="right" valign="top">void </td><td class="memItemRight" valign="bottom"><a class="el" href="group__api.html#ga4becaa66425469cf462b531aa7eb1ac9">mqtt_init_reconnect</a> (struct <a class="el" href="structmqtt__client.html">mqtt_client</a> *client, void(*reconnect_callback)(struct <a class="el" href="structmqtt__client.html">mqtt_client</a> *client, void **state), void *reconnect_state, void(*publish_response_callback)(void **state, struct <a class="el" href="structmqtt__response__publish.html">mqtt_response_publish</a> *publish))</td></tr>
<tr class="memdesc:ga4becaa66425469cf462b531aa7eb1ac9"><td class="mdescLeft"> </td><td class="mdescRight">Initializes an MQTT client and enables automatic reconnections.An alternative to <a class="el" href="group__api.html#gaa5dab8a06f016b09c7a5259274b3b3ce">mqtt_init</a> that allows the client to automatically reconnect to the broker after an error occurs (e.g. socket error or internal buffer overflows). <a href="#ga4becaa66425469cf462b531aa7eb1ac9">More...</a><br /></td></tr>
<tr class="separator:ga4becaa66425469cf462b531aa7eb1ac9"><td class="memSeparator" colspan="2"> </td></tr>
<tr class="memitem:gaf5ae4b5b880431ef1bcd72f343de9ac6"><td class="memItemLeft" align="right" valign="top">void </td><td class="memItemRight" valign="bottom"><a class="el" href="group__api.html#gaf5ae4b5b880431ef1bcd72f343de9ac6">mqtt_reinit</a> (struct <a class="el" href="structmqtt__client.html">mqtt_client</a> *client, mqtt_pal_socket_handle socketfd, uint8_t *sendbuf, size_t sendbufsz, uint8_t *recvbuf, size_t recvbufsz)</td></tr>
<tr class="memdesc:gaf5ae4b5b880431ef1bcd72f343de9ac6"><td class="mdescLeft"> </td><td class="mdescRight">Safely assign/reassign a socket and buffers to an new/existing client.This function also clears the <code>client</code> error state. Upon exiting this function <code>client->error</code> will be <code>MQTT_ERROR_CONNECT_NOT_CALLED</code> (which will be cleared) as soon as <a class="el" href="group__api.html#gadbe914e5a9d4f93314c4e7637cb4f7b3">mqtt_connect</a> is called. <a href="#gaf5ae4b5b880431ef1bcd72f343de9ac6">More...</a><br /></td></tr>
<tr class="separator:gaf5ae4b5b880431ef1bcd72f343de9ac6"><td class="memSeparator" colspan="2"> </td></tr>
<tr class="memitem:gadbe914e5a9d4f93314c4e7637cb4f7b3"><td class="memItemLeft" align="right" valign="top">enum <a class="el" href="group__api.html#gad0c901a8d30691ed0ca17915b691b7e7">MQTTErrors</a> </td><td class="memItemRight" valign="bottom"><a class="el" href="group__api.html#gadbe914e5a9d4f93314c4e7637cb4f7b3">mqtt_connect</a> (struct <a class="el" href="structmqtt__client.html">mqtt_client</a> *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)</td></tr>
<tr class="memdesc:gadbe914e5a9d4f93314c4e7637cb4f7b3"><td class="mdescLeft"> </td><td class="mdescRight">Establishes a session with the MQTT broker. <a href="#gadbe914e5a9d4f93314c4e7637cb4f7b3">More...</a><br /></td></tr>
<tr class="separator:gadbe914e5a9d4f93314c4e7637cb4f7b3"><td class="memSeparator" colspan="2"> </td></tr>
<tr class="memitem:ga0d8fed24a799ab9b55eeb28f3cd2d0a8"><td class="memItemLeft" align="right" valign="top">enum <a class="el" href="group__api.html#gad0c901a8d30691ed0ca17915b691b7e7">MQTTErrors</a> </td><td class="memItemRight" valign="bottom"><a class="el" href="group__api.html#ga0d8fed24a799ab9b55eeb28f3cd2d0a8">mqtt_publish</a> (struct <a class="el" href="structmqtt__client.html">mqtt_client</a> *client, const char *topic_name, void *application_message, size_t application_message_size, uint8_t publish_flags)</td></tr>
<tr class="memdesc:ga0d8fed24a799ab9b55eeb28f3cd2d0a8"><td class="mdescLeft"> </td><td class="mdescRight">Publish an application message.Publishes an application message to the MQTT broker. <a href="#ga0d8fed24a799ab9b55eeb28f3cd2d0a8">More...</a><br /></td></tr>
<tr class="separator:ga0d8fed24a799ab9b55eeb28f3cd2d0a8"><td class="memSeparator" colspan="2"> </td></tr>
<tr class="memitem:gaea5da9b546f6e91eb77c9eff9c478de5"><td class="memItemLeft" align="right" valign="top">enum <a class="el" href="group__api.html#gad0c901a8d30691ed0ca17915b691b7e7">MQTTErrors</a> </td><td class="memItemRight" valign="bottom"><a class="el" href="group__api.html#gaea5da9b546f6e91eb77c9eff9c478de5">mqtt_subscribe</a> (struct <a class="el" href="structmqtt__client.html">mqtt_client</a> *client, const char *topic_name, int max_qos_level)</td></tr>
<tr class="memdesc:gaea5da9b546f6e91eb77c9eff9c478de5"><td class="mdescLeft"> </td><td class="mdescRight">Subscribe to a topic. <a href="#gaea5da9b546f6e91eb77c9eff9c478de5">More...</a><br /></td></tr>
<tr class="separator:gaea5da9b546f6e91eb77c9eff9c478de5"><td class="memSeparator" colspan="2"> </td></tr>
<tr class="memitem:ga08d16571dfefa690698c0cca5cca7a1d"><td class="memItemLeft" align="right" valign="top">enum <a class="el" href="group__api.html#gad0c901a8d30691ed0ca17915b691b7e7">MQTTErrors</a> </td><td class="memItemRight" valign="bottom"><a class="el" href="group__api.html#ga08d16571dfefa690698c0cca5cca7a1d">mqtt_unsubscribe</a> (struct <a class="el" href="structmqtt__client.html">mqtt_client</a> *client, const char *topic_name)</td></tr>
<tr class="memdesc:ga08d16571dfefa690698c0cca5cca7a1d"><td class="mdescLeft"> </td><td class="mdescRight">Unsubscribe from a topic. <a href="#ga08d16571dfefa690698c0cca5cca7a1d">More...</a><br /></td></tr>
<tr class="separator:ga08d16571dfefa690698c0cca5cca7a1d"><td class="memSeparator" colspan="2"> </td></tr>
<tr class="memitem:gae472795684a1d973bfb89d075d17a29e"><td class="memItemLeft" align="right" valign="top">enum <a class="el" href="group__api.html#gad0c901a8d30691ed0ca17915b691b7e7">MQTTErrors</a> </td><td class="memItemRight" valign="bottom"><a class="el" href="group__api.html#gae472795684a1d973bfb89d075d17a29e">mqtt_ping</a> (struct <a class="el" href="structmqtt__client.html">mqtt_client</a> *client)</td></tr>
<tr class="memdesc:gae472795684a1d973bfb89d075d17a29e"><td class="mdescLeft"> </td><td class="mdescRight">Ping the broker. <a href="#gae472795684a1d973bfb89d075d17a29e">More...</a><br /></td></tr>
<tr class="separator:gae472795684a1d973bfb89d075d17a29e"><td class="memSeparator" colspan="2"> </td></tr>
<tr class="memitem:ga95d9981735ab4495d3d65e8056611126"><td class="memItemLeft" align="right" valign="top">enum <a class="el" href="group__api.html#gad0c901a8d30691ed0ca17915b691b7e7">MQTTErrors</a> </td><td class="memItemRight" valign="bottom"><a class="el" href="group__api.html#ga95d9981735ab4495d3d65e8056611126">mqtt_disconnect</a> (struct <a class="el" href="structmqtt__client.html">mqtt_client</a> *client)</td></tr>
<tr class="memdesc:ga95d9981735ab4495d3d65e8056611126"><td class="mdescLeft"> </td><td class="mdescRight">Terminate the session with the MQTT broker. <a href="#ga95d9981735ab4495d3d65e8056611126">More...</a><br /></td></tr>
<tr class="separator:ga95d9981735ab4495d3d65e8056611126"><td class="memSeparator" colspan="2"> </td></tr>
</table>
<a name="details" id="details"></a><h2 class="groupheader">Detailed Description</h2>
<p>Documentation of everything you need to know to use the MQTT-C client. </p>
<p>This module contains everything you need to know to use MQTT-C in your application. For usage examples see:</p><ul>
<li><a class="el" href="simple_publisher_8c-example.html">simple_publisher.c</a></li>
<li><a class="el" href="simple_subscriber_8c-example.html">simple_subscriber.c</a></li>
<li><a class="el" href="reconnect_subscriber_8c-example.html">reconnect_subscriber.c</a></li>
<li><a class="el" href="bio_publisher_8c-example.html">bio_publisher.c</a></li>
<li><a class="el" href="openssl_publisher_8c-example.html">openssl_publisher.c</a></li>
</ul>
<dl class="section note"><dt>Note</dt><dd>MQTT-C can be used in both single-threaded and multi-threaded applications. All the functions in <a class="el" href="group__api.html">API</a> are thread-safe. </dd></dl>
<h2 class="groupheader">Enumeration Type Documentation</h2>
<a id="gad0c901a8d30691ed0ca17915b691b7e7"></a>
<h2 class="memtitle"><span class="permalink"><a href="#gad0c901a8d30691ed0ca17915b691b7e7">◆ </a></span>MQTTErrors</h2>
<div class="memitem">
<div class="memproto">
<table class="memname">
<tr>
<td class="memname">enum <a class="el" href="group__api.html#gad0c901a8d30691ed0ca17915b691b7e7">MQTTErrors</a></td>
</tr>
</table>
</div><div class="memdoc">
<p>An enumeration of error codes. Error messages can be retrieved by calling <a class="el" href="group__api.html#ga47b62bdd24e8b05957825d2419d7c848">mqtt_error_str</a>. </p>
<dl class="section see"><dt>See also</dt><dd><a class="el" href="group__api.html#ga47b62bdd24e8b05957825d2419d7c848" title="Returns an error message for error code, error. ">mqtt_error_str</a> </dd></dl>
</div>
</div>
<h2 class="groupheader">Function Documentation</h2>
<a id="gadbe914e5a9d4f93314c4e7637cb4f7b3"></a>
<h2 class="memtitle"><span class="permalink"><a href="#gadbe914e5a9d4f93314c4e7637cb4f7b3">◆ </a></span>mqtt_connect()</h2>
<div class="memitem">
<div class="memproto">
<table class="memname">
<tr>
<td class="memname">enum <a class="el" href="group__api.html#gad0c901a8d30691ed0ca17915b691b7e7">MQTTErrors</a> mqtt_connect </td>
<td>(</td>
<td class="paramtype">struct <a class="el" href="structmqtt__client.html">mqtt_client</a> * </td>
<td class="paramname"><em>client</em>, </td>
</tr>
<tr>
<td class="paramkey"></td>
<td></td>
<td class="paramtype">const char * </td>
<td class="paramname"><em>client_id</em>, </td>
</tr>
<tr>
<td class="paramkey"></td>
<td></td>
<td class="paramtype">const char * </td>
<td class="paramname"><em>will_topic</em>, </td>
</tr>
<tr>
<td class="paramkey"></td>
<td></td>
<td class="paramtype">const void * </td>
<td class="paramname"><em>will_message</em>, </td>
</tr>
<tr>
<td class="paramkey"></td>
<td></td>
<td class="paramtype">size_t </td>
<td class="paramname"><em>will_message_size</em>, </td>
</tr>
<tr>
<td class="paramkey"></td>
<td></td>
<td class="paramtype">const char * </td>
<td class="paramname"><em>user_name</em>, </td>
</tr>
<tr>
<td class="paramkey"></td>
<td></td>
<td class="paramtype">const char * </td>
<td class="paramname"><em>password</em>, </td>
</tr>
<tr>
<td class="paramkey"></td>
<td></td>
<td class="paramtype">uint8_t </td>
<td class="paramname"><em>connect_flags</em>, </td>
</tr>
<tr>
<td class="paramkey"></td>
<td></td>
<td class="paramtype">uint16_t </td>
<td class="paramname"><em>keep_alive</em> </td>
</tr>
<tr>
<td></td>
<td>)</td>
<td></td><td></td>
</tr>
</table>
</div><div class="memdoc">
<p>Establishes a session with the MQTT broker. </p>
<dl class="section pre"><dt>Precondition</dt><dd>mqtt_init must have been called.</dd></dl>
<dl class="params"><dt>Parameters</dt><dd>
<table class="params">
<tr><td class="paramdir">[in,out]</td><td class="paramname">client</td><td>The MQTT client. </td></tr>
<tr><td class="paramdir">[in]</td><td class="paramname">client_id</td><td>The unique name identifying the client. </td></tr>
<tr><td class="paramdir">[in]</td><td class="paramname">will_topic</td><td>The topic name of client's <code>will_message</code>. If no will message is desired set to <code>NULL</code>. </td></tr>
<tr><td class="paramdir">[in]</td><td class="paramname">will_message</td><td>The application message (data) to be published in the event the client ungracefully disconnects. Set to <code>NULL</code> if <code>will_topic</code> is <code>NULL</code>. </td></tr>
<tr><td class="paramdir">[in]</td><td class="paramname">will_message_size</td><td>The size of <code>will_message</code> in bytes. </td></tr>
<tr><td class="paramdir">[in]</td><td class="paramname">user_name</td><td>The username to use when establishing the session with the MQTT broker. Set to <code>NULL</code> if a username is not required. </td></tr>
<tr><td class="paramdir">[in]</td><td class="paramname">password</td><td>The password to use when establishing the session with the MQTT broker. Set to <code>NULL</code> if a password is not required. </td></tr>
<tr><td class="paramdir">[in]</td><td class="paramname">connect_flags</td><td>Additional <a class="el" href="group__packers.html#gad6fa84a96a940fe4eae6ffca1a6d945f">MQTTConnectFlags</a> to use when establishing the connection. These flags are for forcing the session to start clean, <code>MQTT_CONNECT_CLEAN_SESSION</code>, the QOS level to publish the <code>will_message</code> with (provided <code>will_message</code> != <code>NULL</code>), MQTT_CONNECT_WILL_QOS_[0,1,2], and whether or not the broker should retain the <code>will_message</code>, MQTT_CONNECT_WILL_RETAIN. </td></tr>
<tr><td class="paramdir">[in]</td><td class="paramname">keep_alive</td><td>The keep-alive time in seconds. A reasonable value for this is 400 [seconds].</td></tr>
</table>
</dd>
</dl>
<dl class="section return"><dt>Returns</dt><dd><code>MQTT_OK</code> upon success, an <a class="el" href="group__api.html#gad0c901a8d30691ed0ca17915b691b7e7">MQTTErrors</a> otherwise. </dd></dl>
<dl><dt><b>Examples: </b></dt><dd><a class="el" href="bio_publisher_8c-example.html#a3">bio_publisher.c</a>, <a class="el" href="openssl_publisher_8c-example.html#a3">openssl_publisher.c</a>, <a class="el" href="reconnect_subscriber_8c-example.html#a7">reconnect_subscriber.c</a>, <a class="el" href="simple_publisher_8c-example.html#a3">simple_publisher.c</a>, and <a class="el" href="simple_subscriber_8c-example.html#a3">simple_subscriber.c</a>.</dd>
</dl>
</div>
</div>
<a id="ga95d9981735ab4495d3d65e8056611126"></a>
<h2 class="memtitle"><span class="permalink"><a href="#ga95d9981735ab4495d3d65e8056611126">◆ </a></span>mqtt_disconnect()</h2>
<div class="memitem">
<div class="memproto">
<table class="memname">
<tr>
<td class="memname">enum <a class="el" href="group__api.html#gad0c901a8d30691ed0ca17915b691b7e7">MQTTErrors</a> mqtt_disconnect </td>
<td>(</td>
<td class="paramtype">struct <a class="el" href="structmqtt__client.html">mqtt_client</a> * </td>
<td class="paramname"><em>client</em></td><td>)</td>
<td></td>
</tr>
</table>
</div><div class="memdoc">
<p>Terminate the session with the MQTT broker. </p>
<dl class="section pre"><dt>Precondition</dt><dd>mqtt_connect must have been called.</dd></dl>
<dl class="params"><dt>Parameters</dt><dd>
<table class="params">
<tr><td class="paramdir">[in,out]</td><td class="paramname">client</td><td>The MQTT client.</td></tr>
</table>
</dd>
</dl>
<dl class="section note"><dt>Note</dt><dd>To re-establish the session, mqtt_connect must be called.</dd></dl>
<dl class="section return"><dt>Returns</dt><dd><code>MQTT_OK</code> upon success, an <a class="el" href="group__api.html#gad0c901a8d30691ed0ca17915b691b7e7">MQTTErrors</a> otherwise. </dd></dl>
</div>
</div>
<a id="ga47b62bdd24e8b05957825d2419d7c848"></a>
<h2 class="memtitle"><span class="permalink"><a href="#ga47b62bdd24e8b05957825d2419d7c848">◆ </a></span>mqtt_error_str()</h2>
<div class="memitem">
<div class="memproto">
<table class="memname">
<tr>
<td class="memname">const char* mqtt_error_str </td>
<td>(</td>
<td class="paramtype">enum <a class="el" href="group__api.html#gad0c901a8d30691ed0ca17915b691b7e7">MQTTErrors</a> </td>
<td class="paramname"><em>error</em></td><td>)</td>
<td></td>
</tr>
</table>
</div><div class="memdoc">
<p>Returns an error message for error code, <code>error</code>. </p>
<dl class="params"><dt>Parameters</dt><dd>
<table class="params">
<tr><td class="paramdir">[in]</td><td class="paramname">error</td><td>the error code.</td></tr>
</table>
</dd>
</dl>
<dl class="section return"><dt>Returns</dt><dd>The associated error message. </dd></dl>
<dl><dt><b>Examples: </b></dt><dd><a class="el" href="bio_publisher_8c-example.html#a4">bio_publisher.c</a>, <a class="el" href="openssl_publisher_8c-example.html#a4">openssl_publisher.c</a>, <a class="el" href="reconnect_subscriber_8c-example.html#a5">reconnect_subscriber.c</a>, <a class="el" href="simple_publisher_8c-example.html#a4">simple_publisher.c</a>, and <a class="el" href="simple_subscriber_8c-example.html#a4">simple_subscriber.c</a>.</dd>
</dl>
</div>
</div>
<a id="gaa5dab8a06f016b09c7a5259274b3b3ce"></a>
<h2 class="memtitle"><span class="permalink"><a href="#gaa5dab8a06f016b09c7a5259274b3b3ce">◆ </a></span>mqtt_init()</h2>
<div class="memitem">
<div class="memproto">
<table class="memname">
<tr>
<td class="memname">enum <a class="el" href="group__api.html#gad0c901a8d30691ed0ca17915b691b7e7">MQTTErrors</a> mqtt_init </td>
<td>(</td>
<td class="paramtype">struct <a class="el" href="structmqtt__client.html">mqtt_client</a> * </td>
<td class="paramname"><em>client</em>, </td>
</tr>
<tr>
<td class="paramkey"></td>
<td></td>
<td class="paramtype">mqtt_pal_socket_handle </td>
<td class="paramname"><em>sockfd</em>, </td>
</tr>
<tr>
<td class="paramkey"></td>
<td></td>
<td class="paramtype">uint8_t * </td>
<td class="paramname"><em>sendbuf</em>, </td>
</tr>
<tr>
<td class="paramkey"></td>
<td></td>
<td class="paramtype">size_t </td>
<td class="paramname"><em>sendbufsz</em>, </td>
</tr>
<tr>
<td class="paramkey"></td>
<td></td>
<td class="paramtype">uint8_t * </td>
<td class="paramname"><em>recvbuf</em>, </td>
</tr>
<tr>
<td class="paramkey"></td>
<td></td>
<td class="paramtype">size_t </td>
<td class="paramname"><em>recvbufsz</em>, </td>
</tr>
<tr>
<td class="paramkey"></td>
<td></td>
<td class="paramtype">void(*)(void **state, struct <a class="el" href="structmqtt__response__publish.html">mqtt_response_publish</a> *publish) </td>
<td class="paramname"><em>publish_response_callback</em> </td>
</tr>
<tr>
<td></td>
<td>)</td>
<td></td><td></td>
</tr>
</table>
</div><div class="memdoc">
<p>Initializes an MQTT client.This function <em>must</em> be called before any other API function calls. </p>
<dl class="section pre"><dt>Precondition</dt><dd>None.</dd></dl>
<dl class="params"><dt>Parameters</dt><dd>
<table class="params">
<tr><td class="paramdir">[out]</td><td class="paramname">client</td><td>The MQTT client. </td></tr>
<tr><td class="paramdir">[in]</td><td class="paramname">sockfd</td><td>The socket file descriptor (or equivalent socket handle, e.g. BIO pointer for OpenSSL sockets) connected to the MQTT broker. </td></tr>
<tr><td class="paramdir">[in]</td><td class="paramname">sendbuf</td><td>A buffer that will be used for sending messages to the broker. </td></tr>
<tr><td class="paramdir">[in]</td><td class="paramname">sendbufsz</td><td>The size of <code>sendbuf</code> in bytes. </td></tr>
<tr><td class="paramdir">[in]</td><td class="paramname">recvbuf</td><td>A buffer that will be used for receiving messages from the broker. </td></tr>
<tr><td class="paramdir">[in]</td><td class="paramname">recvbufsz</td><td>The size of <code>recvbuf</code> in bytes. </td></tr>
<tr><td class="paramdir">[in]</td><td class="paramname">publish_response_callback</td><td>The callback to call whenever application messages are received from the broker.</td></tr>
</table>
</dd>
</dl>
<dl class="section post"><dt>Postcondition</dt><dd>mqtt_connect must be called.</dd></dl>
<dl class="section note"><dt>Note</dt><dd><code>sockfd</code> is a non-blocking TCP connection. </dd>
<dd>
If <code>sendbuf</code> fills up completely during runtime a <code>MQTT_ERROR_SEND_BUFFER_IS_FULL</code> error will be set. Similarly if <code>recvbuf</code> is ever to small to receive a message from the broker an MQTT_ERROR_RECV_BUFFER_TOO_SMALL error will be set. </dd>
<dd>
A pointer to <a class="el" href="structmqtt__client.html#a948d816462128ef2216c230644407f21">mqtt_client::publish_response_callback_state</a> is always passed as the <code>state</code> argument to <code>publish_response_callback</code>. Note that the second argument is the <a class="el" href="structmqtt__response__publish.html" title="A publish packet received from the broker.A publish packet is received from the broker when a client ...">mqtt_response_publish</a> that was received from the broker.</dd></dl>
<dl class="section attention"><dt>Attention</dt><dd>Only initialize an MQTT client once (i.e. don't call <a class="el" href="group__api.html#gaa5dab8a06f016b09c7a5259274b3b3ce">mqtt_init</a> or <a class="el" href="group__api.html#ga4becaa66425469cf462b531aa7eb1ac9">mqtt_init_reconnect</a> more than once per client).</dd></dl>
<dl class="section return"><dt>Returns</dt><dd><code>MQTT_OK</code> upon success, an <a class="el" href="group__api.html#gad0c901a8d30691ed0ca17915b691b7e7">MQTTErrors</a> otherwise. </dd></dl>
<dl><dt><b>Examples: </b></dt><dd><a class="el" href="bio_publisher_8c-example.html#a2">bio_publisher.c</a>, <a class="el" href="openssl_publisher_8c-example.html#a2">openssl_publisher.c</a>, <a class="el" href="simple_publisher_8c-example.html#a2">simple_publisher.c</a>, and <a class="el" href="simple_subscriber_8c-example.html#a2">simple_subscriber.c</a>.</dd>
</dl>
</div>
</div>
<a id="ga4becaa66425469cf462b531aa7eb1ac9"></a>
<h2 class="memtitle"><span class="permalink"><a href="#ga4becaa66425469cf462b531aa7eb1ac9">◆ </a></span>mqtt_init_reconnect()</h2>
<div class="memitem">
<div class="memproto">
<table class="memname">
<tr>
<td class="memname">void mqtt_init_reconnect </td>
<td>(</td>
<td class="paramtype">struct <a class="el" href="structmqtt__client.html">mqtt_client</a> * </td>
<td class="paramname"><em>client</em>, </td>
</tr>
<tr>
<td class="paramkey"></td>
<td></td>
<td class="paramtype">void(*)(struct <a class="el" href="structmqtt__client.html">mqtt_client</a> *client, void **state) </td>
<td class="paramname"><em>reconnect_callback</em>, </td>
</tr>
<tr>
<td class="paramkey"></td>
<td></td>
<td class="paramtype">void * </td>
<td class="paramname"><em>reconnect_state</em>, </td>
</tr>
<tr>
<td class="paramkey"></td>
<td></td>
<td class="paramtype">void(*)(void **state, struct <a class="el" href="structmqtt__response__publish.html">mqtt_response_publish</a> *publish) </td>
<td class="paramname"><em>publish_response_callback</em> </td>
</tr>
<tr>
<td></td>
<td>)</td>
<td></td><td></td>
</tr>
</table>
</div><div class="memdoc">
<p>Initializes an MQTT client and enables automatic reconnections.An alternative to <a class="el" href="group__api.html#gaa5dab8a06f016b09c7a5259274b3b3ce">mqtt_init</a> that allows the client to automatically reconnect to the broker after an error occurs (e.g. socket error or internal buffer overflows). </p>
<p>This is accomplished by calling the <code>reconnect_callback</code> whenever the client enters an error state. The job of the <code>reconnect_callback</code> is to: (1) perform error handling/logging, (2) clean up the old connection (i.e. close client->socketfd), (3) <a class="el" href="group__api.html#gaf5ae4b5b880431ef1bcd72f343de9ac6">mqtt_reinit</a> the client, and (4) reconfigure the MQTT session by calling <a class="el" href="group__api.html#gadbe914e5a9d4f93314c4e7637cb4f7b3">mqtt_connect</a> followed by other API calls such as <a class="el" href="group__api.html#gaea5da9b546f6e91eb77c9eff9c478de5">mqtt_subscribe</a>.</p>
<p>The first argument to the <code>reconnect_callback</code> is the client (which will be in an error state) and the second argument is a pointer to a void pointer where you can store some state information. Internally, MQTT-C calls the reconnect callback like so:</p>
<div class="fragment"><div class="line">client->reconnect_callback(client, &client->reconnect_state)</div></div><!-- fragment --><p>Note that the <code>reconnect_callback</code> is also called to setup the initial session. After calling <a class="el" href="group__api.html#ga4becaa66425469cf462b531aa7eb1ac9">mqtt_init_reconnect</a> the client will be in the error state <code>MQTT_ERROR_INITIAL_RECONNECT</code>.</p>
<dl class="section pre"><dt>Precondition</dt><dd>None.</dd></dl>
<dl class="params"><dt>Parameters</dt><dd>
<table class="params">
<tr><td class="paramdir">[in,out]</td><td class="paramname">client</td><td>The MQTT client that will be initialized. </td></tr>
<tr><td class="paramdir">[in]</td><td class="paramname">reconnect_callback</td><td>The callback that will be called to connect/reconnect the client to the broker and perform application level error handling. </td></tr>
<tr><td class="paramdir">[in]</td><td class="paramname">reconnect_state</td><td>A pointer to some state data for your <code>reconnect_callback</code>. If your <code>reconnect_callback</code> does not require any state information set this to NULL. A pointer to the memory address where the client stores a copy of this pointer is passed as the second argumnet to <code>reconnect_callback</code>. </td></tr>
<tr><td class="paramdir">[in]</td><td class="paramname">publish_response_callback</td><td>The callback to call whenever application messages are received from the broker.</td></tr>
</table>
</dd>
</dl>
<dl class="section post"><dt>Postcondition</dt><dd>Call <code>reconnect_callback</code> yourself, or call <a class="el" href="group__api.html#gae3d3aafc7588ed53a90c9f66fc620a6e">mqtt_sync</a> (which will trigger the call to <code>reconnect_callback</code>).</dd></dl>
<dl class="section attention"><dt>Attention</dt><dd>Only initialize an MQTT client once (i.e. don't call <a class="el" href="group__api.html#gaa5dab8a06f016b09c7a5259274b3b3ce">mqtt_init</a> or <a class="el" href="group__api.html#ga4becaa66425469cf462b531aa7eb1ac9">mqtt_init_reconnect</a> more than once per client). </dd></dl>
<dl><dt><b>Examples: </b></dt><dd><a class="el" href="reconnect_subscriber_8c-example.html#a2">reconnect_subscriber.c</a>.</dd>
</dl>
</div>
</div>
<a id="gae472795684a1d973bfb89d075d17a29e"></a>
<h2 class="memtitle"><span class="permalink"><a href="#gae472795684a1d973bfb89d075d17a29e">◆ </a></span>mqtt_ping()</h2>
<div class="memitem">
<div class="memproto">
<table class="memname">
<tr>
<td class="memname">enum <a class="el" href="group__api.html#gad0c901a8d30691ed0ca17915b691b7e7">MQTTErrors</a> mqtt_ping </td>
<td>(</td>
<td class="paramtype">struct <a class="el" href="structmqtt__client.html">mqtt_client</a> * </td>
<td class="paramname"><em>client</em></td><td>)</td>
<td></td>
</tr>
</table>
</div><div class="memdoc">
<p>Ping the broker. </p>
<dl class="section pre"><dt>Precondition</dt><dd>mqtt_connect must have been called.</dd></dl>
<dl class="params"><dt>Parameters</dt><dd>
<table class="params">
<tr><td class="paramdir">[in,out]</td><td class="paramname">client</td><td>The MQTT client.</td></tr>
</table>
</dd>
</dl>
<dl class="section return"><dt>Returns</dt><dd><code>MQTT_OK</code> upon success, an <a class="el" href="group__api.html#gad0c901a8d30691ed0ca17915b691b7e7">MQTTErrors</a> otherwise. </dd></dl>
</div>
</div>
<a id="ga0d8fed24a799ab9b55eeb28f3cd2d0a8"></a>
<h2 class="memtitle"><span class="permalink"><a href="#ga0d8fed24a799ab9b55eeb28f3cd2d0a8">◆ </a></span>mqtt_publish()</h2>
<div class="memitem">
<div class="memproto">
<table class="memname">
<tr>
<td class="memname">enum <a class="el" href="group__api.html#gad0c901a8d30691ed0ca17915b691b7e7">MQTTErrors</a> mqtt_publish </td>
<td>(</td>
<td class="paramtype">struct <a class="el" href="structmqtt__client.html">mqtt_client</a> * </td>
<td class="paramname"><em>client</em>, </td>
</tr>
<tr>
<td class="paramkey"></td>
<td></td>
<td class="paramtype">const char * </td>
<td class="paramname"><em>topic_name</em>, </td>
</tr>
<tr>
<td class="paramkey"></td>
<td></td>
<td class="paramtype">void * </td>
<td class="paramname"><em>application_message</em>, </td>
</tr>
<tr>
<td class="paramkey"></td>
<td></td>
<td class="paramtype">size_t </td>
<td class="paramname"><em>application_message_size</em>, </td>
</tr>
<tr>
<td class="paramkey"></td>
<td></td>
<td class="paramtype">uint8_t </td>
<td class="paramname"><em>publish_flags</em> </td>
</tr>
<tr>
<td></td>
<td>)</td>
<td></td><td></td>
</tr>
</table>
</div><div class="memdoc">
<p>Publish an application message.Publishes an application message to the MQTT broker. </p>
<dl class="section pre"><dt>Precondition</dt><dd>mqtt_connect must have been called.</dd></dl>
<dl class="params"><dt>Parameters</dt><dd>
<table class="params">
<tr><td class="paramdir">[in,out]</td><td class="paramname">client</td><td>The MQTT client. </td></tr>
<tr><td class="paramdir">[in]</td><td class="paramname">topic_name</td><td>The name of the topic. </td></tr>
<tr><td class="paramdir">[in]</td><td class="paramname">application_message</td><td>The data to be published. </td></tr>
<tr><td class="paramdir">[in]</td><td class="paramname">application_message_size</td><td>The size of <code>application_message</code> in bytes. </td></tr>
<tr><td class="paramdir">[in]</td><td class="paramname">publish_flags</td><td><a class="el" href="group__packers.html#gad38a41e1c497f9bcd2477c005f280b23">MQTTPublishFlags</a> to be used, namely the QOS level to publish at (MQTT_PUBLISH_QOS_[0,1,2]) or whether or not the broker should retain the publish (MQTT_PUBLISH_RETAIN).</td></tr>
</table>
</dd>
</dl>
<dl class="section return"><dt>Returns</dt><dd><code>MQTT_OK</code> upon success, an <a class="el" href="group__api.html#gad0c901a8d30691ed0ca17915b691b7e7">MQTTErrors</a> otherwise. </dd></dl>
<dl><dt><b>Examples: </b></dt><dd><a class="el" href="bio_publisher_8c-example.html#a5">bio_publisher.c</a>, <a class="el" href="openssl_publisher_8c-example.html#a5">openssl_publisher.c</a>, and <a class="el" href="simple_publisher_8c-example.html#a5">simple_publisher.c</a>.</dd>
</dl>
</div>
</div>
<a id="gaf5ae4b5b880431ef1bcd72f343de9ac6"></a>
<h2 class="memtitle"><span class="permalink"><a href="#gaf5ae4b5b880431ef1bcd72f343de9ac6">◆ </a></span>mqtt_reinit()</h2>
<div class="memitem">
<div class="memproto">
<table class="memname">
<tr>
<td class="memname">void mqtt_reinit </td>
<td>(</td>
<td class="paramtype">struct <a class="el" href="structmqtt__client.html">mqtt_client</a> * </td>
<td class="paramname"><em>client</em>, </td>
</tr>
<tr>
<td class="paramkey"></td>
<td></td>
<td class="paramtype">mqtt_pal_socket_handle </td>
<td class="paramname"><em>socketfd</em>, </td>
</tr>
<tr>
<td class="paramkey"></td>
<td></td>
<td class="paramtype">uint8_t * </td>
<td class="paramname"><em>sendbuf</em>, </td>
</tr>
<tr>
<td class="paramkey"></td>
<td></td>
<td class="paramtype">size_t </td>
<td class="paramname"><em>sendbufsz</em>, </td>
</tr>
<tr>
<td class="paramkey"></td>
<td></td>
<td class="paramtype">uint8_t * </td>
<td class="paramname"><em>recvbuf</em>, </td>
</tr>
<tr>
<td class="paramkey"></td>
<td></td>
<td class="paramtype">size_t </td>
<td class="paramname"><em>recvbufsz</em> </td>
</tr>
<tr>
<td></td>
<td>)</td>
<td></td><td></td>
</tr>
</table>
</div><div class="memdoc">
<p>Safely assign/reassign a socket and buffers to an new/existing client.This function also clears the <code>client</code> error state. Upon exiting this function <code>client->error</code> will be <code>MQTT_ERROR_CONNECT_NOT_CALLED</code> (which will be cleared) as soon as <a class="el" href="group__api.html#gadbe914e5a9d4f93314c4e7637cb4f7b3">mqtt_connect</a> is called. </p>
<dl class="section pre"><dt>Precondition</dt><dd>This function must be called BEFORE <a class="el" href="group__api.html#gadbe914e5a9d4f93314c4e7637cb4f7b3">mqtt_connect</a>.</dd></dl>
<dl class="params"><dt>Parameters</dt><dd>
<table class="params">
<tr><td class="paramdir">[in,out]</td><td class="paramname">client</td><td>The MQTT client. </td></tr>
<tr><td class="paramdir">[in]</td><td class="paramname">socketfd</td><td>The new socket connected to the broker. </td></tr>
<tr><td class="paramdir">[in]</td><td class="paramname">sendbuf</td><td>The buffer that will be used to buffer egress traffic to the broker. </td></tr>
<tr><td class="paramdir">[in]</td><td class="paramname">sendbufsz</td><td>The size of <code>sendbuf</code> in bytes. </td></tr>
<tr><td class="paramdir">[in]</td><td class="paramname">recvbuf</td><td>The buffer that will be used to buffer ingress traffic from the broker. </td></tr>
<tr><td class="paramdir">[in]</td><td class="paramname">recvbufsz</td><td>The size of <code>recvbuf</code> in bytes.</td></tr>
</table>
</dd>
</dl>
<dl class="section post"><dt>Postcondition</dt><dd>Call <a class="el" href="group__api.html#gadbe914e5a9d4f93314c4e7637cb4f7b3">mqtt_connect</a>.</dd></dl>
<dl class="section attention"><dt>Attention</dt><dd>This function should be used in conjunction with clients that have been initialzed with <a class="el" href="group__api.html#ga4becaa66425469cf462b531aa7eb1ac9">mqtt_init_reconnect</a>. </dd></dl>
<dl><dt><b>Examples: </b></dt><dd><a class="el" href="reconnect_subscriber_8c-example.html#a6">reconnect_subscriber.c</a>.</dd>
</dl>
</div>
</div>
<a id="gaea5da9b546f6e91eb77c9eff9c478de5"></a>
<h2 class="memtitle"><span class="permalink"><a href="#gaea5da9b546f6e91eb77c9eff9c478de5">◆ </a></span>mqtt_subscribe()</h2>
<div class="memitem">
<div class="memproto">
<table class="memname">
<tr>
<td class="memname">enum <a class="el" href="group__api.html#gad0c901a8d30691ed0ca17915b691b7e7">MQTTErrors</a> mqtt_subscribe </td>
<td>(</td>
<td class="paramtype">struct <a class="el" href="structmqtt__client.html">mqtt_client</a> * </td>
<td class="paramname"><em>client</em>, </td>
</tr>
<tr>
<td class="paramkey"></td>
<td></td>
<td class="paramtype">const char * </td>
<td class="paramname"><em>topic_name</em>, </td>
</tr>
<tr>
<td class="paramkey"></td>
<td></td>
<td class="paramtype">int </td>
<td class="paramname"><em>max_qos_level</em> </td>
</tr>
<tr>
<td></td>
<td>)</td>
<td></td><td></td>
</tr>
</table>
</div><div class="memdoc">
<p>Subscribe to a topic. </p>
<dl class="section pre"><dt>Precondition</dt><dd>mqtt_connect must have been called.</dd></dl>
<dl class="params"><dt>Parameters</dt><dd>
<table class="params">
<tr><td class="paramdir">[in,out]</td><td class="paramname">client</td><td>The MQTT client. </td></tr>
<tr><td class="paramdir">[in]</td><td class="paramname">topic_name</td><td>The name of the topic to subscribe to. </td></tr>
<tr><td class="paramdir">[in]</td><td class="paramname">max_qos_level</td><td>The maximum QOS level with which the broker can send application messages for this topic.</td></tr>
</table>
</dd>
</dl>
<dl class="section return"><dt>Returns</dt><dd><code>MQTT_OK</code> upon success, an <a class="el" href="group__api.html#gad0c901a8d30691ed0ca17915b691b7e7">MQTTErrors</a> otherwise. </dd></dl>
<dl><dt><b>Examples: </b></dt><dd><a class="el" href="reconnect_subscriber_8c-example.html#a8">reconnect_subscriber.c</a>, and <a class="el" href="simple_subscriber_8c-example.html#a5">simple_subscriber.c</a>.</dd>
</dl>
</div>
</div>
<a id="gae3d3aafc7588ed53a90c9f66fc620a6e"></a>
<h2 class="memtitle"><span class="permalink"><a href="#gae3d3aafc7588ed53a90c9f66fc620a6e">◆ </a></span>mqtt_sync()</h2>
<div class="memitem">
<div class="memproto">
<table class="memname">
<tr>
<td class="memname">enum <a class="el" href="group__api.html#gad0c901a8d30691ed0ca17915b691b7e7">MQTTErrors</a> mqtt_sync </td>
<td>(</td>
<td class="paramtype">struct <a class="el" href="structmqtt__client.html">mqtt_client</a> * </td>
<td class="paramname"><em>client</em></td><td>)</td>
<td></td>
</tr>
</table>
</div><div class="memdoc">
<p>Function that does the actual sending and receiving of traffic from the network.All the other functions in the <a class="el" href="group__api.html">API</a> simply stage messages for being sent to the broker. This function does the actual sending of those messages. Additionally this function receives traffic (responses and acknowledgements) from the broker and responds to that traffic accordingly. Lastly this function also calls the <code>publish_response_callback</code> when any <code>MQTT_CONTROL_PUBLISH</code> messages are received. </p>
<dl class="section pre"><dt>Precondition</dt><dd>mqtt_init must have been called.</dd></dl>
<dl class="params"><dt>Parameters</dt><dd>
<table class="params">
<tr><td class="paramdir">[in,out]</td><td class="paramname">client</td><td>The MQTT client.</td></tr>
</table>
</dd>
</dl>
<dl class="section attention"><dt>Attention</dt><dd>It is the responsibility of the application programmer to call this function periodically. All functions in the <a class="el" href="group__api.html">API</a> are thread-safe so it is perfectly reasonable to have a thread dedicated to calling this function every 200 ms or so. MQTT-C can be used in single threaded application though by simply calling this functino periodically inside your main thread. See <a class="el" href="simple_publisher_8c-example.html">simple_publisher.c</a> and <a class="el" href="simple_subscriber_8c-example.html">simple_subscriber.c</a> for examples (specifically the <code>client_refresher</code> functions).</dd></dl>
<dl class="section return"><dt>Returns</dt><dd>MQTT_OK upon success, an <a class="el" href="group__api.html#gad0c901a8d30691ed0ca17915b691b7e7">MQTTErrors</a> otherwise. </dd></dl>
<dl><dt><b>Examples: </b></dt><dd><a class="el" href="bio_publisher_8c-example.html#a6">bio_publisher.c</a>, <a class="el" href="openssl_publisher_8c-example.html#a6">openssl_publisher.c</a>, <a class="el" href="reconnect_subscriber_8c-example.html#a12">reconnect_subscriber.c</a>, <a class="el" href="simple_publisher_8c-example.html#a6">simple_publisher.c</a>, and <a class="el" href="simple_subscriber_8c-example.html#a9">simple_subscriber.c</a>.</dd>
</dl>
</div>
</div>
<a id="ga08d16571dfefa690698c0cca5cca7a1d"></a>
<h2 class="memtitle"><span class="permalink"><a href="#ga08d16571dfefa690698c0cca5cca7a1d">◆ </a></span>mqtt_unsubscribe()</h2>
<div class="memitem">
<div class="memproto">
<table class="memname">
<tr>
<td class="memname">enum <a class="el" href="group__api.html#gad0c901a8d30691ed0ca17915b691b7e7">MQTTErrors</a> mqtt_unsubscribe </td>
<td>(</td>
<td class="paramtype">struct <a class="el" href="structmqtt__client.html">mqtt_client</a> * </td>
<td class="paramname"><em>client</em>, </td>
</tr>
<tr>
<td class="paramkey"></td>
<td></td>
<td class="paramtype">const char * </td>
<td class="paramname"><em>topic_name</em> </td>
</tr>
<tr>
<td></td>
<td>)</td>
<td></td><td></td>
</tr>
</table>
</div><div class="memdoc">
<p>Unsubscribe from a topic. </p>
<dl class="section pre"><dt>Precondition</dt><dd>mqtt_connect must have been called.</dd></dl>
<dl class="params"><dt>Parameters</dt><dd>
<table class="params">
<tr><td class="paramdir">[in,out]</td><td class="paramname">client</td><td>The MQTT client. </td></tr>
<tr><td class="paramdir">[in]</td><td class="paramname">topic_name</td><td>The name of the topic to unsubscribe from.</td></tr>
</table>
</dd>
</dl>
<dl class="section return"><dt>Returns</dt><dd><code>MQTT_OK</code> upon success, an <a class="el" href="group__api.html#gad0c901a8d30691ed0ca17915b691b7e7">MQTTErrors</a> otherwise. </dd></dl>
</div>
</div>
</div><!-- contents -->
<!-- start footer part -->
<hr class="footer"/><address class="footer"><small>
Generated by  <a href="http://www.doxygen.org/index.html">
<img class="footer" src="doxygen.png" alt="doxygen"/>
</a> 1.8.13
</small></address>
</body>
</html>