<!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>RadioLib: src/protocols/MQTT/MQTT.h Source File</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="navtree.css" rel="stylesheet" type="text/css"/>
<script type="text/javascript" src="resize.js"></script>
<script type="text/javascript" src="navtreedata.js"></script>
<script type="text/javascript" src="navtree.js"></script>
<script type="text/javascript">
  $(document).ready(initResizable);
</script>
<link href="search/search.css" rel="stylesheet" type="text/css"/>
<script type="text/javascript" src="search/searchdata.js"></script>
<script type="text/javascript" src="search/search.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">RadioLib
   </div>
   <div id="projectbrief">Universal wireless communication library for Arduino</div>
  </td>
 </tr>
 </tbody>
</table>
</div>
<!-- end header part -->
<!-- Generated by Doxygen 1.8.13 -->
<script type="text/javascript">
var searchBox = new SearchBox("searchBox", "search",false,'Search');
</script>
<script type="text/javascript" src="menudata.js"></script>
<script type="text/javascript" src="menu.js"></script>
<script type="text/javascript">
$(function() {
  initMenu('',true,false,'search.php','Search');
  $(document).ready(function() { init_search(); });
});
</script>
<div id="main-nav"></div>
</div><!-- top -->
<div id="side-nav" class="ui-resizable side-nav-resizable">
  <div id="nav-tree">
    <div id="nav-tree-contents">
      <div id="nav-sync" class="sync"></div>
    </div>
  </div>
  <div id="splitbar" style="-moz-user-select:none;" 
       class="ui-resizable-handle">
  </div>
</div>
<script type="text/javascript">
$(document).ready(function(){initNavTree('_m_q_t_t_8h_source.html','');});
</script>
<div id="doc-content">
<!-- window showing the filter options -->
<div id="MSearchSelectWindow"
     onmouseover="return searchBox.OnSearchSelectShow()"
     onmouseout="return searchBox.OnSearchSelectHide()"
     onkeydown="return searchBox.OnSearchSelectKey(event)">
</div>

<!-- iframe showing the search results (closed by default) -->
<div id="MSearchResultsWindow">
<iframe src="javascript:void(0)" frameborder="0" 
        name="MSearchResults" id="MSearchResults">
</iframe>
</div>

<div class="header">
  <div class="headertitle">
<div class="title">MQTT.h</div>  </div>
</div><!--header-->
<div class="contents">
<div class="fragment"><div class="line"><a name="l00001"></a><span class="lineno">    1</span>&#160;<span class="preprocessor">#if !defined(_RADIOLIB_MQTT_H)</span></div><div class="line"><a name="l00002"></a><span class="lineno">    2</span>&#160;<span class="preprocessor">#define _RADIOLIB_MQTT_H</span></div><div class="line"><a name="l00003"></a><span class="lineno">    3</span>&#160;</div><div class="line"><a name="l00004"></a><span class="lineno">    4</span>&#160;<span class="preprocessor">#include &quot;../../TypeDef.h&quot;</span></div><div class="line"><a name="l00005"></a><span class="lineno">    5</span>&#160;</div><div class="line"><a name="l00006"></a><span class="lineno">    6</span>&#160;<span class="preprocessor">#if !defined(RADIOLIB_EXCLUDE_MQTT)</span></div><div class="line"><a name="l00007"></a><span class="lineno">    7</span>&#160;</div><div class="line"><a name="l00008"></a><span class="lineno">    8</span>&#160;<span class="preprocessor">#include &quot;../TransportLayer/TransportLayer.h&quot;</span></div><div class="line"><a name="l00009"></a><span class="lineno">    9</span>&#160;</div><div class="line"><a name="l00010"></a><span class="lineno">   10</span>&#160;<span class="comment">// MQTT packet types</span></div><div class="line"><a name="l00011"></a><span class="lineno">   11</span>&#160;<span class="preprocessor">#define MQTT_CONNECT                                  0x01</span></div><div class="line"><a name="l00012"></a><span class="lineno">   12</span>&#160;<span class="preprocessor">#define MQTT_CONNACK                                  0x02</span></div><div class="line"><a name="l00013"></a><span class="lineno">   13</span>&#160;<span class="preprocessor">#define MQTT_PUBLISH                                  0x03</span></div><div class="line"><a name="l00014"></a><span class="lineno">   14</span>&#160;<span class="preprocessor">#define MQTT_PUBACK                                   0x04</span></div><div class="line"><a name="l00015"></a><span class="lineno">   15</span>&#160;<span class="preprocessor">#define MQTT_PUBREC                                   0x05</span></div><div class="line"><a name="l00016"></a><span class="lineno">   16</span>&#160;<span class="preprocessor">#define MQTT_PUBREL                                   0x06</span></div><div class="line"><a name="l00017"></a><span class="lineno">   17</span>&#160;<span class="preprocessor">#define MQTT_PUBCOMP                                  0x07</span></div><div class="line"><a name="l00018"></a><span class="lineno">   18</span>&#160;<span class="preprocessor">#define MQTT_SUBSCRIBE                                0x08</span></div><div class="line"><a name="l00019"></a><span class="lineno">   19</span>&#160;<span class="preprocessor">#define MQTT_SUBACK                                   0x09</span></div><div class="line"><a name="l00020"></a><span class="lineno">   20</span>&#160;<span class="preprocessor">#define MQTT_UNSUBSCRIBE                              0x0A</span></div><div class="line"><a name="l00021"></a><span class="lineno">   21</span>&#160;<span class="preprocessor">#define MQTT_UNSUBACK                                 0x0B</span></div><div class="line"><a name="l00022"></a><span class="lineno">   22</span>&#160;<span class="preprocessor">#define MQTT_PINGREQ                                  0x0C</span></div><div class="line"><a name="l00023"></a><span class="lineno">   23</span>&#160;<span class="preprocessor">#define MQTT_PINGRESP                                 0x0D</span></div><div class="line"><a name="l00024"></a><span class="lineno">   24</span>&#160;<span class="preprocessor">#define MQTT_DISCONNECT                               0x0E</span></div><div class="line"><a name="l00025"></a><span class="lineno">   25</span>&#160;</div><div class="line"><a name="l00026"></a><span class="lineno">   26</span>&#160;<span class="comment">// MQTT CONNECT flags</span></div><div class="line"><a name="l00027"></a><span class="lineno">   27</span>&#160;<span class="preprocessor">#define MQTT_CONNECT_USER_NAME_FLAG                   0b10000000</span></div><div class="line"><a name="l00028"></a><span class="lineno">   28</span>&#160;<span class="preprocessor">#define MQTT_CONNECT_PASSWORD_FLAG                    0b01000000</span></div><div class="line"><a name="l00029"></a><span class="lineno">   29</span>&#160;<span class="preprocessor">#define MQTT_CONNECT_WILL_RETAIN                      0b00100000</span></div><div class="line"><a name="l00030"></a><span class="lineno">   30</span>&#160;<span class="preprocessor">#define MQTT_CONNECT_WILL_FLAG                        0b00000100</span></div><div class="line"><a name="l00031"></a><span class="lineno">   31</span>&#160;<span class="preprocessor">#define MQTT_CONNECT_CLEAN_SESSION                    0b00000010</span></div><div class="line"><a name="l00032"></a><span class="lineno">   32</span>&#160;</div><div class="line"><a name="l00038"></a><span class="lineno"><a class="line" href="class_m_q_t_t_client.html">   38</a></span>&#160;<span class="keyword">class </span><a class="code" href="class_m_q_t_t_client.html">MQTTClient</a> {</div><div class="line"><a name="l00039"></a><span class="lineno">   39</span>&#160;  <span class="keyword">public</span>:</div><div class="line"><a name="l00045"></a><span class="lineno">   45</span>&#160;    <span class="keyword">explicit</span> <a class="code" href="class_m_q_t_t_client.html#a6ecdbc80b76ae32b926e84af620dacb6">MQTTClient</a>(<a class="code" href="class_transport_layer.html">TransportLayer</a>* tl, uint16_t port = 1883);</div><div class="line"><a name="l00046"></a><span class="lineno">   46</span>&#160;</div><div class="line"><a name="l00047"></a><span class="lineno">   47</span>&#160;    <span class="comment">// basic methods</span></div><div class="line"><a name="l00048"></a><span class="lineno">   48</span>&#160;</div><div class="line"><a name="l00070"></a><span class="lineno">   70</span>&#160;    int16_t <a class="code" href="class_m_q_t_t_client.html#ac15b32e89df903b20b066113bf8c4a88">connect</a>(<span class="keyword">const</span> <span class="keywordtype">char</span>* host, <span class="keyword">const</span> <span class="keywordtype">char</span>* clientId, <span class="keyword">const</span> <span class="keywordtype">char</span>* userName = <span class="stringliteral">&quot;&quot;</span>, <span class="keyword">const</span> <span class="keywordtype">char</span>* password = <span class="stringliteral">&quot;&quot;</span>, uint16_t keepAlive = 60, <span class="keywordtype">bool</span> cleanSession = <span class="keyword">true</span>, <span class="keyword">const</span> <span class="keywordtype">char</span>* willTopic = <span class="stringliteral">&quot;&quot;</span>, <span class="keyword">const</span> <span class="keywordtype">char</span>* willMessage = <span class="stringliteral">&quot;&quot;</span>);</div><div class="line"><a name="l00071"></a><span class="lineno">   71</span>&#160;</div><div class="line"><a name="l00077"></a><span class="lineno">   77</span>&#160;    int16_t <a class="code" href="class_m_q_t_t_client.html#af10176e2cf67bd652823d44f3203a96e">disconnect</a>();</div><div class="line"><a name="l00078"></a><span class="lineno">   78</span>&#160;</div><div class="line"><a name="l00088"></a><span class="lineno">   88</span>&#160;    int16_t <a class="code" href="class_m_q_t_t_client.html#ace3ee45313dea2f853207accf20b7c87">publish</a>(String&amp; topic, String&amp; message);</div><div class="line"><a name="l00089"></a><span class="lineno">   89</span>&#160;</div><div class="line"><a name="l00099"></a><span class="lineno">   99</span>&#160;    int16_t <a class="code" href="class_m_q_t_t_client.html#ace3ee45313dea2f853207accf20b7c87">publish</a>(<span class="keyword">const</span> <span class="keywordtype">char</span>* topic, <span class="keyword">const</span> <span class="keywordtype">char</span>* message);</div><div class="line"><a name="l00100"></a><span class="lineno">  100</span>&#160;</div><div class="line"><a name="l00108"></a><span class="lineno">  108</span>&#160;    int16_t <a class="code" href="class_m_q_t_t_client.html#a9488df90534953c33d76e9183965a300">subscribe</a>(<span class="keyword">const</span> <span class="keywordtype">char</span>* topicFilter);</div><div class="line"><a name="l00109"></a><span class="lineno">  109</span>&#160;</div><div class="line"><a name="l00117"></a><span class="lineno">  117</span>&#160;    int16_t <a class="code" href="class_m_q_t_t_client.html#a782158f20b289746b7b6884fd922a22c">unsubscribe</a>(<span class="keyword">const</span> <span class="keywordtype">char</span>* topicFilter);</div><div class="line"><a name="l00118"></a><span class="lineno">  118</span>&#160;</div><div class="line"><a name="l00124"></a><span class="lineno">  124</span>&#160;    int16_t <a class="code" href="class_m_q_t_t_client.html#aea3fb930ed43a0b3122ccc90efebb99d">ping</a>();</div><div class="line"><a name="l00125"></a><span class="lineno">  125</span>&#160;</div><div class="line"><a name="l00131"></a><span class="lineno">  131</span>&#160;    int16_t <a class="code" href="class_m_q_t_t_client.html#a49cb16ef730ad50ba5dc472ac10d933e">check</a>(<span class="keywordtype">void</span> (*func)(<span class="keyword">const</span> <span class="keywordtype">char</span>*, <span class="keyword">const</span> <span class="keywordtype">char</span>*));</div><div class="line"><a name="l00132"></a><span class="lineno">  132</span>&#160;</div><div class="line"><a name="l00133"></a><span class="lineno">  133</span>&#160;<span class="preprocessor">#ifndef RADIOLIB_GODMODE</span></div><div class="line"><a name="l00134"></a><span class="lineno">  134</span>&#160;  <span class="keyword">private</span>:</div><div class="line"><a name="l00135"></a><span class="lineno">  135</span>&#160;<span class="preprocessor">#endif</span></div><div class="line"><a name="l00136"></a><span class="lineno">  136</span>&#160;    <a class="code" href="class_transport_layer.html">TransportLayer</a>* _tl;</div><div class="line"><a name="l00137"></a><span class="lineno">  137</span>&#160;</div><div class="line"><a name="l00138"></a><span class="lineno">  138</span>&#160;    uint16_t _port;</div><div class="line"><a name="l00139"></a><span class="lineno">  139</span>&#160;    uint16_t _packetId;</div><div class="line"><a name="l00140"></a><span class="lineno">  140</span>&#160;</div><div class="line"><a name="l00141"></a><span class="lineno">  141</span>&#160;    <span class="keyword">static</span> <span class="keywordtype">size_t</span> encodeLength(uint32_t len, uint8_t* encoded);</div><div class="line"><a name="l00142"></a><span class="lineno">  142</span>&#160;    <span class="keyword">static</span> uint32_t decodeLength(uint8_t* encoded, uint8_t&amp; numBytes);</div><div class="line"><a name="l00143"></a><span class="lineno">  143</span>&#160;};</div><div class="line"><a name="l00144"></a><span class="lineno">  144</span>&#160;</div><div class="line"><a name="l00145"></a><span class="lineno">  145</span>&#160;<span class="preprocessor">#endif</span></div><div class="line"><a name="l00146"></a><span class="lineno">  146</span>&#160;</div><div class="line"><a name="l00147"></a><span class="lineno">  147</span>&#160;<span class="preprocessor">#endif</span></div><div class="ttc" id="class_m_q_t_t_client_html_a9488df90534953c33d76e9183965a300"><div class="ttname"><a href="class_m_q_t_t_client.html#a9488df90534953c33d76e9183965a300">MQTTClient::subscribe</a></div><div class="ttdeci">int16_t subscribe(const char *topicFilter)</div><div class="ttdoc">Subscribe to MQTT topic. </div><div class="ttdef"><b>Definition:</b> MQTT.cpp:211</div></div>
<div class="ttc" id="class_transport_layer_html"><div class="ttname"><a href="class_transport_layer.html">TransportLayer</a></div><div class="ttdoc">Provides common interface for protocols that run on modules with Internet connectivity, such as HTTP or MQTT. Because this class is used mainly as interface, all of its virtual members must be implemented in the module class. </div><div class="ttdef"><b>Definition:</b> TransportLayer.h:12</div></div>
<div class="ttc" id="class_m_q_t_t_client_html_aea3fb930ed43a0b3122ccc90efebb99d"><div class="ttname"><a href="class_m_q_t_t_client.html#aea3fb930ed43a0b3122ccc90efebb99d">MQTTClient::ping</a></div><div class="ttdeci">int16_t ping()</div><div class="ttdoc">Ping MQTT broker. This method can be used to keep connection open. </div><div class="ttdef"><b>Definition:</b> MQTT.cpp:356</div></div>
<div class="ttc" id="class_m_q_t_t_client_html_af10176e2cf67bd652823d44f3203a96e"><div class="ttname"><a href="class_m_q_t_t_client.html#af10176e2cf67bd652823d44f3203a96e">MQTTClient::disconnect</a></div><div class="ttdeci">int16_t disconnect()</div><div class="ttdoc">Disconnect from MQTT broker. </div><div class="ttdef"><b>Definition:</b> MQTT.cpp:146</div></div>
<div class="ttc" id="class_m_q_t_t_client_html_a6ecdbc80b76ae32b926e84af620dacb6"><div class="ttname"><a href="class_m_q_t_t_client.html#a6ecdbc80b76ae32b926e84af620dacb6">MQTTClient::MQTTClient</a></div><div class="ttdeci">MQTTClient(TransportLayer *tl, uint16_t port=1883)</div><div class="ttdoc">Default constructor. </div><div class="ttdef"><b>Definition:</b> MQTT.cpp:4</div></div>
<div class="ttc" id="class_m_q_t_t_client_html_ac15b32e89df903b20b066113bf8c4a88"><div class="ttname"><a href="class_m_q_t_t_client.html#ac15b32e89df903b20b066113bf8c4a88">MQTTClient::connect</a></div><div class="ttdeci">int16_t connect(const char *host, const char *clientId, const char *userName=&quot;&quot;, const char *password=&quot;&quot;, uint16_t keepAlive=60, bool cleanSession=true, const char *willTopic=&quot;&quot;, const char *willMessage=&quot;&quot;)</div><div class="ttdoc">Connects to MQTT broker (/server). </div><div class="ttdef"><b>Definition:</b> MQTT.cpp:10</div></div>
<div class="ttc" id="class_m_q_t_t_client_html_ace3ee45313dea2f853207accf20b7c87"><div class="ttname"><a href="class_m_q_t_t_client.html#ace3ee45313dea2f853207accf20b7c87">MQTTClient::publish</a></div><div class="ttdeci">int16_t publish(String &amp;topic, String &amp;message)</div><div class="ttdoc">Publish MQTT message. </div><div class="ttdef"><b>Definition:</b> MQTT.cpp:164</div></div>
<div class="ttc" id="class_m_q_t_t_client_html_a49cb16ef730ad50ba5dc472ac10d933e"><div class="ttname"><a href="class_m_q_t_t_client.html#a49cb16ef730ad50ba5dc472ac10d933e">MQTTClient::check</a></div><div class="ttdeci">int16_t check(void(*func)(const char *, const char *))</div><div class="ttdoc">Set function to be called when checking new messages in subscribed topics. </div><div class="ttdef"><b>Definition:</b> MQTT.cpp:396</div></div>
<div class="ttc" id="class_m_q_t_t_client_html_a782158f20b289746b7b6884fd922a22c"><div class="ttname"><a href="class_m_q_t_t_client.html#a782158f20b289746b7b6884fd922a22c">MQTTClient::unsubscribe</a></div><div class="ttdeci">int16_t unsubscribe(const char *topicFilter)</div><div class="ttdoc">Unsubscribe from MQTT topic. </div><div class="ttdef"><b>Definition:</b> MQTT.cpp:285</div></div>
<div class="ttc" id="class_m_q_t_t_client_html"><div class="ttname"><a href="class_m_q_t_t_client.html">MQTTClient</a></div><div class="ttdoc">Client for simple MQTT communication. </div><div class="ttdef"><b>Definition:</b> MQTT.h:38</div></div>
</div><!-- fragment --></div><!-- contents -->
</div><!-- doc-content -->
<!-- start footer part -->
<div id="nav-path" class="navpath"><!-- id is needed for treeview function! -->
  <ul>
    <li class="navelem"><a class="el" href="dir_68267d1309a1af8e8297ef4c3efbcdba.html">src</a></li><li class="navelem"><a class="el" href="dir_79690749eba542503bb1a9a3dbb495e1.html">protocols</a></li><li class="navelem"><a class="el" href="dir_a6b6d785787649e9a3efd5036a39108c.html">MQTT</a></li><li class="navelem"><b>MQTT.h</b></li>
    <li class="footer">Generated by
    <a href="http://www.doxygen.org/index.html">
    <img class="footer" src="doxygen.png" alt="doxygen"/></a> 1.8.13 </li>
  </ul>
</div>
</body>
</html>