mqtt.h 26 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506
  1. /**
  2. * Copyright (c) 2015 - 2019, Nordic Semiconductor ASA
  3. *
  4. * All rights reserved.
  5. *
  6. * Redistribution and use in source and binary forms, with or without modification,
  7. * are permitted provided that the following conditions are met:
  8. *
  9. * 1. Redistributions of source code must retain the above copyright notice, this
  10. * list of conditions and the following disclaimer.
  11. *
  12. * 2. Redistributions in binary form, except as embedded into a Nordic
  13. * Semiconductor ASA integrated circuit in a product or a software update for
  14. * such product, must reproduce the above copyright notice, this list of
  15. * conditions and the following disclaimer in the documentation and/or other
  16. * materials provided with the distribution.
  17. *
  18. * 3. Neither the name of Nordic Semiconductor ASA nor the names of its
  19. * contributors may be used to endorse or promote products derived from this
  20. * software without specific prior written permission.
  21. *
  22. * 4. This software, with or without modification, must only be used with a
  23. * Nordic Semiconductor ASA integrated circuit.
  24. *
  25. * 5. Any software provided in binary form under this license must not be reverse
  26. * engineered, decompiled, modified and/or disassembled.
  27. *
  28. * THIS SOFTWARE IS PROVIDED BY NORDIC SEMICONDUCTOR ASA "AS IS" AND ANY EXPRESS
  29. * OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
  30. * OF MERCHANTABILITY, NONINFRINGEMENT, AND FITNESS FOR A PARTICULAR PURPOSE ARE
  31. * DISCLAIMED. IN NO EVENT SHALL NORDIC SEMICONDUCTOR ASA OR CONTRIBUTORS BE
  32. * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
  33. * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
  34. * GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
  35. * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
  36. * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
  37. * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  38. *
  39. */
  40. /** @file mqtt.h
  41. *
  42. * @defgroup iot_sdk_mqtt_api MQTT Client on nRF5x
  43. * @ingroup iot_sdk_mqtt
  44. * @{
  45. * @brief MQTT Client Implementation on the Nordic nRF platforms.
  46. *
  47. * @details
  48. * MQTT Client's Application interface is defined in this header.
  49. *
  50. * @note The implementation assumes LwIP Stack is available with TCP module enabled.
  51. *
  52. * @note By default the implementation uses MQTT version 3.1.0.
  53. * However few cloud services like the Xively use the version 3.1.1.
  54. * For this please set p_client.protocol_version = MQTT_VERSION_3_1_1.
  55. */
  56. #ifndef MQTT_H_
  57. #define MQTT_H_
  58. #include <stdint.h>
  59. #include "iot_defines.h"
  60. #include "iot_timer.h"
  61. #include "nrf_tls.h"
  62. #ifdef __cplusplus
  63. extern "C" {
  64. #endif
  65. /**@brief MQTT Asynchronous Events notified to the application from the module
  66. * through the callback registered by the application. */
  67. typedef enum
  68. {
  69. MQTT_EVT_CONNACK, /**< Acknowledgment of connection request. Event result accompanying the event indicates whether the connection failed or succeeded. */
  70. MQTT_EVT_DISCONNECT, /**< Disconnection Event. MQTT Client Reference is no longer valid once this event is received for the client. */
  71. MQTT_EVT_PUBLISH, /**< Publish event received when message is published on a topic client is subscribed to. */
  72. MQTT_EVT_PUBACK, /**< Acknowledgment for published message with QoS 1. */
  73. MQTT_EVT_PUBREC, /**< Reception confirmation for published message with QoS 2. */
  74. MQTT_EVT_PUBREL, /**< Release of published published messages with QoS 2. */
  75. MQTT_EVT_PUBCOMP, /**< Confirmation to a publish release message. Applicable only to QoS 2 messages. */
  76. MQTT_EVT_SUBACK, /**< Acknowledgment to a subscription request. */
  77. MQTT_EVT_UNSUBACK /**< Acknowledgment to a unsubscription request. */
  78. } mqtt_evt_id_t;
  79. /**@brief MQTT version protocol level. */
  80. typedef enum
  81. {
  82. MQTT_VERSION_3_1_0 = 3, /**< Protocol level for 3.1.0. */
  83. MQTT_VERSION_3_1_1 = 4 /**< Protocol level for 3.1.1. */
  84. } mqtt_version_t;
  85. /**@brief MQTT transport type. */
  86. typedef enum
  87. {
  88. MQTT_TRANSPORT_NON_SECURE = 0x00, /**< Use non secure TCP transport for MQTT connection. */
  89. MQTT_TRANSPORT_SECURE = 0x01, /**< Use secure TCP transport (TLS) for MQTT connection. */
  90. MQTT_TRANSPORT_MAX = 0x02 /**< Shall not be used as a transport type. Indicator of maximum transport types possible. */
  91. } mqtt_transport_type_t;
  92. /**@brief MQTT Quality of Service types. */
  93. typedef enum
  94. {
  95. MQTT_QoS_0_AT_MOST_ONCE = 0x00, /**< Lowest Quality of Service, no acknowledgment needed for published message. */
  96. MQTT_QoS_1_ATLEAST_ONCE = 0x01, /**< Medium Quality of Service, if acknowledgment expected for published message, duplicate messages permitted. */
  97. MQTT_QoS_2_EACTLY_ONCE = 0x02 /**< Highest Quality of Service, acknowledgment expected and message shall be published only once. Message not published to interested parties unless client issues a PUBREL. */
  98. } mqtt_qos_t;
  99. /**@brief MQTT Asynchronous Events notified to the application from the module
  100. * through the callback registered by the application. */
  101. typedef enum
  102. {
  103. MQTT_CONNECTION_ACCEPTED = 0x00, /**< Connection accepted. */
  104. MQTT_UNACCEPTABLE_PROTOCOL_VERSION = 0x01, /**< The Server does not support the level of the MQTT protocol requested by the Client. */
  105. MQTT_IDENTIFIER_REJECTED = 0x02, /**< The Client identifier is correct UTF-8 but not allowed by the Server. */
  106. MQTT_SERVER_UNAVAILABLE = 0x03, /**< The Network Connection has been made but the MQTT service is unavailable. */
  107. MQTT_BAD_USER_NAME_OR_PASSWORD = 0x04, /**< The data in the user name or password is malformed. */
  108. MQTT_NOT_AUTHORIZED = 0x05 /**< The Client is not authorized to connect. */
  109. } mqtt_conn_return_code_t;
  110. /**@brief MQTT client forward declaration @ref mqtt_client_t for details. */
  111. typedef struct mqtt_client_t mqtt_client_t;
  112. /**@brief Abstracts UTF-8 encoded strings. */
  113. typedef struct
  114. {
  115. uint8_t * p_utf_str; /**< Pointer to UTF-8 string. */
  116. uint32_t utf_strlen; /**< Length of UTF string. */
  117. } mqtt_utf8_t;
  118. /**@brief Abstracts binary strings. */
  119. typedef struct
  120. {
  121. uint8_t * p_bin_str; /**< Pointer to binary stream. */
  122. uint32_t bin_strlen; /**< Length of binary stream. */
  123. } mqtt_binstr_t;
  124. /**@brief Abstracts MQTT UTF-8 encoded topic that can be subscribed to or published. */
  125. typedef struct
  126. {
  127. mqtt_utf8_t topic; /**< Topic on to be published or subscribed to. */
  128. uint8_t qos; /**< Quality of service requested for the subscription. @ref mqtt_qos_t for details. */
  129. } mqtt_topic_t;
  130. /**@brief Abstracts MQTT UTF-8 encoded unique client identifier. */
  131. typedef mqtt_utf8_t mqtt_client_id_t;
  132. /**@brief Abstracts MQTT UTF-8 encoded password to be used for the client connection. */
  133. typedef mqtt_utf8_t mqtt_password_t;
  134. /**@brief Abstracts MQTT UTF-8 encoded user name to be used for the client connection. */
  135. typedef mqtt_utf8_t mqtt_username_t;
  136. /**@brief Abstracts will message used in @ref mqtt_connect request.
  137. *
  138. * @note utf8 is used here instead of binary string as a zero length encoding is expected in
  139. * will message is empty.
  140. */
  141. typedef mqtt_utf8_t mqtt_will_message_t;
  142. /**@brief Abstracts message in binary encoded string received or published on a topic. */
  143. typedef mqtt_binstr_t mqtt_message_t;
  144. /**@brief Parameters for a publish message. */
  145. typedef struct
  146. {
  147. mqtt_topic_t topic; /**< Topic on which data was published. */
  148. mqtt_message_t payload; /**< Payload on the topic published. */
  149. } mqtt_publish_message_t;
  150. /**@brief Parameters for a connection acknowledgment (connack). */
  151. typedef struct
  152. {
  153. uint8_t session_present_flag; /**< The Session Present flag enables a Client to establish whether the Client and Server have a consistent view about whether there is already stored Session state. */
  154. mqtt_conn_return_code_t return_code; /**< The appropriate non-zero Connect return code indicates if the Server is unable to process a connection request for some reason. */
  155. } mqtt_connack_param_t;
  156. /**@brief Parameters for MQTT publish acknowledgment(puback). */
  157. typedef struct
  158. {
  159. uint16_t message_id;
  160. } mqtt_puback_param_t;
  161. /**@brief Parameters for MQTT publish receive(pubrec). */
  162. typedef struct
  163. {
  164. uint16_t message_id;
  165. } mqtt_pubrec_param_t;
  166. /**@brief Parameters for MQTT publish release(pubrec). */
  167. typedef struct
  168. {
  169. uint16_t message_id;
  170. } mqtt_pubrel_param_t;
  171. /**@brief Parameters for MQTT publish complete(pubcomp). */
  172. typedef struct
  173. {
  174. uint16_t message_id;
  175. } mqtt_pubcomp_param_t;
  176. /**@brief Parameters for MQTT subscription acknowledgment (suback). */
  177. typedef struct
  178. {
  179. uint16_t message_id;
  180. } mqtt_suback_param_t;
  181. /**@brief Parameters for MQTT unsubscription acknowledgment (unsuback). */
  182. typedef struct
  183. {
  184. uint16_t message_id;
  185. } mqtt_unsuback_param_t;
  186. /**@brief Parameters for a publish message. */
  187. typedef struct
  188. {
  189. mqtt_publish_message_t message; /**< Messages including topic, QoS and its payload (if any) to be published. */
  190. uint16_t message_id; /**< Message id used for the publish message. Redundant for QoS 0. */
  191. uint8_t dup_flag:1; /**< Duplicate flag. If 1, it indicates the message is being retransmitted. Has no meaning with QoS 0. */
  192. uint8_t retain_flag:1; /**< retain flag. If 1, the message shall be stored persistently by the broker. */
  193. } mqtt_publish_param_t;
  194. /**@brief List of topics in a subscription request. */
  195. typedef struct
  196. {
  197. mqtt_topic_t * p_list; /**< Array containing topics along with QoS for each. */
  198. uint32_t list_count; /**< Number of topics in the subscription list */
  199. uint16_t message_id; /**< Message id used to identify subscription request. */
  200. } mqtt_subscription_list_t;
  201. /**
  202. * @brief Defines event parameters notified along with asynchronous events to the application.
  203. * Currently, only MQTT_EVT_PUBLISH is accompanied with parameters.
  204. */
  205. typedef union
  206. {
  207. mqtt_connack_param_t connack; /**< Parameters accompanying MQTT_EVT_CONNACK event. */
  208. mqtt_publish_param_t publish; /**< Parameters accompanying MQTT_EVT_PUBLISH event. */
  209. mqtt_puback_param_t puback; /**< Parameters accompanying MQTT_EVT_PUBACK event. */
  210. mqtt_pubrec_param_t pubrec; /**< Parameters accompanying MQTT_EVT_PUBREC event. */
  211. mqtt_pubrel_param_t pubrel; /**< Parameters accompanying MQTT_EVT_PUBREL event. */
  212. mqtt_pubcomp_param_t pubcomp; /**< Parameters accompanying MQTT_EVT_PUBCOMP event. */
  213. mqtt_suback_param_t suback; /**< Parameters accompanying MQTT_EVT_SUBACK event. */
  214. mqtt_suback_param_t unsuback; /**< Parameters accompanying MQTT_EVT_UNSUBACK event. */
  215. } mqtt_evt_param_t;
  216. /**@brief Defined MQTT asynchronous event notified to the application. */
  217. typedef struct
  218. {
  219. mqtt_evt_id_t id; /**< Identifies the event. */
  220. mqtt_evt_param_t param; /**< Contains parameters (if any) accompanying the event. */
  221. uint32_t result; /**< Event result. For example, MQTT_EVT_CONNACK has a result code indicating success or failure code of connection procedure. */
  222. } mqtt_evt_t;
  223. /**@brief Asynchronous event notification callback registered by the application with
  224. * the module to receive module events.
  225. *
  226. * @param[in] p_client Identifies the client for which the event is notified.
  227. * @param[in] p_evet Event description along with result and associated parameters (if any).
  228. */
  229. typedef void (*mqtt_evt_cb_t)(mqtt_client_t * const p_client, const mqtt_evt_t * p_evt);
  230. /**@brief MQTT Client definition to maintain information relevant to the client. */
  231. struct mqtt_client_t
  232. {
  233. mqtt_client_id_t client_id; /**< Unique client identification to be used for the connection. Shall be zero length or NULL valued. */
  234. mqtt_username_t * p_user_name; /**< User name (if any) to be used for the connection. NULL indicates no user name. */
  235. mqtt_password_t * p_password; /**< Password (if any) to be used for the connection. Note that if password is provided, user name shall also be provided. NULL indicates no password. */
  236. mqtt_topic_t * p_will_topic; /**< Will topic and QoS. Can be NULL. */
  237. mqtt_will_message_t * p_will_message; /**< Will message. Can be NULL. Non NULL value valid only if will topic is not NULL. */
  238. nrf_tls_key_settings_t * p_security_settings; /**< Provide security settings like PSK, own certificate etc here. The memory provided for the settings shall be resident. */
  239. mqtt_evt_cb_t evt_cb; /**< Application callback registered with the module to get MQTT events. */
  240. ipv6_addr_t broker_addr; /**< IPv6 Address of MQTT broker to which client connection is requested. */
  241. uint16_t broker_port; /**< Broker's Port number. */
  242. uint8_t poll_abort_counter; /**< Poll abort counter maintained for the TCP connection. */
  243. uint8_t protocol_version; /**< MQTT protocol version. */
  244. uint8_t transport_type; /**< Transport type selection for client instance. @ref mqtt_transport_type_t for possible values. MQTT_TRANSPORT_MAX is not a valid type.*/
  245. uint8_t will_retain:1; /**< Will retain flag, 1 if will message shall be retained persistently. */
  246. uint8_t clean_session:1; /**< Clean session flag indicating a fresh (1) or a retained session (0). Default is 1. */
  247. iot_timer_time_in_ms_t last_activity; /**< Internal. Ticks maintaining wallcock in last activity that occurred. Needed for periodic PING. */
  248. uint32_t state; /**< Internal. Shall not be touched by the application. Client's state in the connection. */
  249. int socket_fd; /**< Internal. Shall not be touched by the application. TCP socket file descriptor. */
  250. uint32_t tcp_id; /**< Internal. Shall not be touched by the application. TCP Connection Reference provided by the IP stack. */
  251. uint8_t * p_packet; /**< Internal. Shall not be touched by the application. Used for creating MQTT packet in TX path. */
  252. uint8_t * p_pending_packet; /**< Internal. Shall not be touched by the application. */
  253. nrf_tls_instance_t tls_instance; /**< Internal. Shall not be touched by the application. TLS instance identifier. Valid only if transport is a secure one. */
  254. uint32_t pending_packetlen; /**< Internal. Shall not be touched by the application. */
  255. };
  256. /**
  257. * @brief Initializes the module.
  258. *
  259. * @retval NRF_SUCCESS or an error code indicating reason for failure.
  260. *
  261. * @note Shall be called before initiating any procedures on the module.
  262. * @note If module initialization fails, no module APIs shall be called.
  263. */
  264. uint32_t mqtt_init(void);
  265. /**
  266. * @brief Initializes the client instance.
  267. *
  268. * @param[in] p_client Client instance for which the procedure is requested.
  269. * Shall not be NULL.
  270. *
  271. * @note Shall be called before connecting the client in order to avoid unexpected behavior
  272. * caused by uninitialized parameters.
  273. */
  274. void mqtt_client_init(mqtt_client_t * const p_client);
  275. /**
  276. * @brief API to request new MQTT client connection.
  277. *
  278. * @param[out] p_client Client instance for which the procedure is requested.
  279. * Shall not be NULL.
  280. *
  281. * @note This memory is assumed to be resident until mqtt_disconnect is called.
  282. * @note Any subsequent changes to parameters like broker address, user name, device id, etc. have
  283. * no effect once MQTT connection is established.
  284. *
  285. * @retval NRF_SUCCESS or an error code indicating reason for failure.
  286. *
  287. * @note Default protocol revision used for connection request is 3.1.0. Please set
  288. * p_client.protocol_version = MQTT_VERSION_3_1_1 to use protocol 3.1.1.
  289. * @note If more than one simultaneous client connections are needed, please define
  290. * MQTT_MAX_CLIENTS to override default of 1.
  291. * @note Please define MQTT_KEEPALIVE time to override default of 1 minute.
  292. * @note Please define MQTT_MAX_PACKET_LENGTH time to override default of 128 bytes.
  293. * Ensure the system has enough memory for the new length per client.
  294. */
  295. uint32_t mqtt_connect(mqtt_client_t * const p_client);
  296. /**
  297. * @brief API to publish messages on topics.
  298. *
  299. * @param[in] p_client Client instance for which the procedure is requested.
  300. * Shall not be NULL.
  301. * @param[in] p_param Parameters to be used for the publish message.
  302. * Shall not be NULL.
  303. *
  304. * @retval NRF_SUCCESS or an error code indicating reason for failure.
  305. *
  306. * @note Default protocol revision used for connection request is 3.1.0. Please set
  307. * p_client.protocol_version = MQTT_VERSION_3_1_1 to use protocol 3.1.1.
  308. */
  309. uint32_t mqtt_publish(mqtt_client_t * const p_client,
  310. mqtt_publish_param_t const * const p_param);
  311. /**
  312. * @brief API used by subscribing client to send acknowledgment to the broker.
  313. * Applicable only to QoS 1 publish messages.
  314. *
  315. * @param[in] p_client Client instance for which the procedure is requested.
  316. * Shall not be NULL.
  317. * @param[in] p_param Identifies message being acknowledged.
  318. *
  319. * @retval NRF_SUCCESS or an error code indicating reason for failure.
  320. *
  321. * @note Default protocol revision used for connection request is 3.1.0. Please set
  322. * p_client.protocol_version = MQTT_VERSION_3_1_1 to use protocol 3.1.1.
  323. */
  324. uint32_t mqtt_publish_ack(mqtt_client_t * const p_client,
  325. mqtt_puback_param_t const * const p_param);
  326. /**
  327. * @brief API to send assured acknowledgment from a subscribing client to the broker.
  328. * Should be called on reception of @ref MQTT_EVT_PUBLISH with QoS set to
  329. * @ref MQTT_QoS_2_EACTLY_ONCE.
  330. *
  331. * @param[in] p_client Identifies client instance for which the procedure is requested.
  332. * Shall not be NULL.
  333. * @param[in] p_param Identifies message being acknowledged.
  334. *
  335. * @retval NRF_SUCCESS or an error code indicating reason for failure.
  336. *
  337. * @note Default protocol revision used for connection request is 3.1.0. Please set
  338. * p_client.protocol_version = MQTT_VERSION_3_1_1 to use protocol 3.1.1.
  339. */
  340. uint32_t mqtt_publish_receive(mqtt_client_t * const p_client,
  341. mqtt_pubrec_param_t const * const p_param);
  342. /**
  343. * @brief API to used by publishing client to request releasing published data.
  344. * Shall be used only after @ref MQTT_EVT_PUBREC is received and is valid
  345. * only for QoS level @ref MQTT_QoS_2_EACTLY_ONCE.
  346. *
  347. * @param[in] p_client Client instance for which the procedure is requested.
  348. * Shall not be NULL.
  349. * @param[in] p_param Identifies message being released.
  350. *
  351. * @retval NRF_SUCCESS or an error code indicating reason for failure.
  352. *
  353. * @note Default protocol revision used for connection request is 3.1.0. Please set
  354. * p_client.protocol_version = MQTT_VERSION_3_1_1 to use protocol 3.1.1.
  355. */
  356. uint32_t mqtt_publish_release(mqtt_client_t * const p_client,
  357. mqtt_pubrel_param_t const * const p_param);
  358. /**
  359. * @brief API used by subscribing clients to acknowledge reception of a released message.
  360. * Should be used on reception @ref MQTT_EVT_PUBREL event.
  361. *
  362. * @param[in] p_client Identifies client instance for which the procedure is requested.
  363. * Shall not be NULL.
  364. * @param[in] p_param Identifies message being completed.
  365. *
  366. * @retval NRF_SUCCESS or an error code indicating reason for failure.
  367. *
  368. * @note Default protocol revision used for connection request is 3.1.0. Please set
  369. * p_client.protocol_version = MQTT_VERSION_3_1_1 to use protocol 3.1.1.
  370. */
  371. uint32_t mqtt_publish_complete(mqtt_client_t * const p_client,
  372. mqtt_pubcomp_param_t const * const p_param);
  373. /**
  374. * @brief API to request subscribing to a topic on the connection.
  375. *
  376. * @param[in] p_client Identifies client instance for which the procedure is requested.
  377. * Shall not be NULL.
  378. * @param[in] p_param Subscription parameters. Shall not be NULL.
  379. *
  380. * @retval NRF_SUCCESS or an error code indicating reason for failure.
  381. */
  382. uint32_t mqtt_subscribe(mqtt_client_t * const p_client,
  383. mqtt_subscription_list_t const * const p_param);
  384. /**
  385. * @brief API to request un-subscribe from a topic on the connection.
  386. *
  387. * @param[in] p_client Identifies client instance for which the procedure is requested.
  388. * Shall not be NULL.
  389. * @param[in] p_param Parameters describing topics being unsubscribed from.
  390. * Shall not be NULL.
  391. *
  392. * @note QoS included in topic description is unused in this API.
  393. *
  394. * @retval NRF_SUCCESS or an error code indicating reason for failure.
  395. */
  396. uint32_t mqtt_unsubscribe(mqtt_client_t * const p_client,
  397. mqtt_subscription_list_t const * const p_param);
  398. /**
  399. * @brief API to abort MQTT connection.
  400. *
  401. * @param[in] p_client Identifies client instance for which procedure is requested.
  402. *
  403. * @retval NRF_SUCCESS or an error code indicating reason for failure.
  404. */
  405. uint32_t mqtt_abort(mqtt_client_t * const p_client);
  406. /**
  407. * @brief API to disconnect MQTT connection.
  408. *
  409. * @param[in] p_client Identifies client instance for which procedure is requested.
  410. *
  411. * @retval NRF_SUCCESS or an error code indicating reason for failure.
  412. */
  413. uint32_t mqtt_disconnect(mqtt_client_t * const p_client);
  414. /**
  415. * @brief This API should be called periodically for the module to be able to keep the connection
  416. * alive by sending Ping Requests if need be.
  417. *
  418. * @note Application shall ensure that the periodicity of calling this function makes it possible to
  419. * respect the Keep Alive time agreed with the broker on connection.
  420. * @ref mqtt_connect for details on Keep Alive time.
  421. *
  422. * @retval NRF_SUCCESS or an result code indicating reason for failure.
  423. */
  424. uint32_t mqtt_live(void);
  425. /**
  426. * @brief Wait for an incoming MQTT packet.
  427. * The registered callback will be called with the packet payload.
  428. *
  429. * @param[in] p_client Client instance for which the procedure is requested.
  430. * Shall not be NULL.
  431. * @param[in] timeout Maximum interval (in milliseconds) to wait for a packet.
  432. * If timeout is 0, the interval is indefinitely.
  433. *
  434. * @retval NRF_SUCCESS or an error code indicating reason for failure.
  435. *
  436. * @note This API is only supported when using the socket transport layer.
  437. */
  438. uint32_t mqtt_input(mqtt_client_t * const p_client, uint32_t timeout);
  439. #ifdef __cplusplus
  440. }
  441. #endif
  442. #endif // MQTT_H_
  443. /**@} */