MQTT cleanups:

- create mqtt_opts.h file and move options in there
- documentation cleanups
This commit is contained in:
Dirk Ziegelmeier 2016-12-20 10:08:50 +01:00
parent 14e36866f5
commit 12bc2c0425
3 changed files with 119 additions and 45 deletions

View File

@ -1021,6 +1021,7 @@ mqtt_tcp_connect_cb(void *arg, struct tcp_pcb *tpcb, err_t err)
/** /**
* @ingroup mqtt
* MQTT publish function. * MQTT publish function.
* @param client MQTT client * @param client MQTT client
* @param topic Publish topic string * @param topic Publish topic string
@ -1090,7 +1091,8 @@ mqtt_publish(mqtt_client_t *client, const char *topic, const void *payload, u16_
/** /**
* @brief MQTT subscribe/unsubscribe function. * @ingroup mqtt
* MQTT subscribe/unsubscribe function.
* @param client MQTT client * @param client MQTT client
* @param topic topic to subscribe to * @param topic topic to subscribe to
* @param qos Quality of service, 0 1 or 2 (only used for subscribe) * @param qos Quality of service, 0 1 or 2 (only used for subscribe)
@ -1145,6 +1147,7 @@ mqtt_sub_unsub(mqtt_client_t *client, const char *topic, u8_t qos, mqtt_request_
/** /**
* @ingroup mqtt
* Set callback to handle incoming publish requests from server * Set callback to handle incoming publish requests from server
* @param client MQTT client * @param client MQTT client
* @param pub_cb Callback invoked when publish starts, contain topic and total length of payload * @param pub_cb Callback invoked when publish starts, contain topic and total length of payload
@ -1162,6 +1165,7 @@ mqtt_set_inpub_callback(mqtt_client_t *client, mqtt_incoming_publish_cb_t pub_cb
} }
/** /**
* @ingroup mqtt
* Create a new MQTT client instance * Create a new MQTT client instance
* @return Pointer to instance on success, NULL otherwise * @return Pointer to instance on success, NULL otherwise
*/ */
@ -1177,6 +1181,7 @@ mqtt_client_new(void)
/** /**
* @ingroup mqtt
* Connect to MQTT server * Connect to MQTT server
* @param client MQTT client * @param client MQTT client
* @param host String containing server IP * @param host String containing server IP
@ -1290,6 +1295,7 @@ tcp_fail:
/** /**
* @ingroup mqtt
* Disconnect from MQTT server * Disconnect from MQTT server
* @param client MQTT client * @param client MQTT client
*/ */
@ -1306,6 +1312,7 @@ mqtt_disconnect(mqtt_client_t *client)
} }
/** /**
* @ingroup mqtt
* Check connection with server * Check connection with server
* @param client MQTT client * @param client MQTT client
* @return 1 if connected to server, 0 otherwise * @return 1 if connected to server, 0 otherwise

View File

@ -34,49 +34,24 @@
* Author: Erik Andersson * Author: Erik Andersson
* *
*/ */
#ifndef LWIP_HDR_MQTT_CLIENT_H #ifndef LWIP_HDR_APPS_MQTT_CLIENT_H
#define LWIP_HDR_MQTT_CLIENT_H #define LWIP_HDR_APPS_MQTT_CLIENT_H
#include "lwip/apps/mqtt_opts.h"
#include "lwip/err.h" #include "lwip/err.h"
#include "lwip/opt.h"
#ifdef __cplusplus #ifdef __cplusplus
extern "C" { extern "C" {
#endif #endif
/** @ingroup mqtt
* @{
*/
/**
* Output ring-buffer size, must be able to fit largest outgoing publish message topic+payloads
*/
#ifndef MQTT_OUTPUT_RINGBUF_SIZE
#define MQTT_OUTPUT_RINGBUF_SIZE 256
#endif
/**
* Number of bytes in receive buffer, must be at least the size of the longest incoming topic + 8
* If one wants to avoid fragmented incoming publish, set length to max incoming topic length + max payload length + 8
*/
#ifndef MQTT_VAR_HEADER_BUFFER_LEN
#define MQTT_VAR_HEADER_BUFFER_LEN 128
#endif
/**
* Maximum number of pending subscribe, unsubscribe and publish requests to server .
*/
#ifndef MQTT_REQ_MAX_IN_FLIGHT
#define MQTT_REQ_MAX_IN_FLIGHT 4
#endif
typedef struct mqtt_client_t mqtt_client_t; typedef struct mqtt_client_t mqtt_client_t;
/*---------------------------------------------------------------------------------------------- */ /*---------------------------------------------------------------------------------------------- */
/* Connection with server */ /* Connection with server */
/** Client information and connection parameters */ /**
* @ingroup mqtt
* Client information and connection parameters */
struct mqtt_connect_client_info_t { struct mqtt_connect_client_info_t {
/** Client identifier, must be set by caller */ /** Client identifier, must be set by caller */
const char *client_id; const char *client_id;
@ -93,7 +68,9 @@ struct mqtt_connect_client_info_t {
u8_t will_retain; u8_t will_retain;
}; };
/** Connection status codes */ /**
* @ingroup mqtt
* Connection status codes */
typedef enum typedef enum
{ {
MQTT_CONNECT_ACCEPTED = 0, MQTT_CONNECT_ACCEPTED = 0,
@ -106,7 +83,9 @@ typedef enum
MQTT_CONNECT_TIMEOUT = 257 MQTT_CONNECT_TIMEOUT = 257
} mqtt_connection_status_t; } mqtt_connection_status_t;
/** Function prototype for mqtt connection status callback. Called when /**
* @ingroup mqtt
* Function prototype for mqtt connection status callback. Called when
* client has connected to the server after initiating a mqtt connection attempt by * client has connected to the server after initiating a mqtt connection attempt by
* calling mqtt_connect() or when connection is closed by server or an error * calling mqtt_connect() or when connection is closed by server or an error
* *
@ -118,13 +97,17 @@ typedef enum
typedef void (*mqtt_connection_cb_t)(mqtt_client_t *client, void *arg, mqtt_connection_status_t status); typedef void (*mqtt_connection_cb_t)(mqtt_client_t *client, void *arg, mqtt_connection_status_t status);
/** Data callback flags */ /**
* @ingroup mqtt
* Data callback flags */
enum { enum {
/** Flag set when last fragment of data arrives in data callback */ /** Flag set when last fragment of data arrives in data callback */
MQTT_DATA_FLAG_LAST = 1, MQTT_DATA_FLAG_LAST = 1,
}; };
/** Function prototype for MQTT incoming publish data callback function. Called when data /**
* @ingroup mqtt
* Function prototype for MQTT incoming publish data callback function. Called when data
* arrives to a subscribed topic @see mqtt_subscribe * arrives to a subscribed topic @see mqtt_subscribe
* *
* @param client MQTT client itself * @param client MQTT client itself
@ -138,7 +121,9 @@ enum {
typedef void (*mqtt_incoming_data_cb_t)(void *arg, const u8_t *data, u16_t len, u8_t flags); typedef void (*mqtt_incoming_data_cb_t)(void *arg, const u8_t *data, u16_t len, u8_t flags);
/** Function prototype for MQTT incoming publish function. Called when an incoming publish /**
* @ingroup mqtt
* Function prototype for MQTT incoming publish function. Called when an incoming publish
* arrives to a subscribed topic @see mqtt_subscribe * arrives to a subscribed topic @see mqtt_subscribe
* *
* @param client MQTT client itself * @param client MQTT client itself
@ -150,7 +135,9 @@ typedef void (*mqtt_incoming_data_cb_t)(void *arg, const u8_t *data, u16_t len,
typedef void (*mqtt_incoming_publish_cb_t)(void *arg, const char *topic, u32_t tot_len); typedef void (*mqtt_incoming_publish_cb_t)(void *arg, const char *topic, u32_t tot_len);
/** Function prototype for mqtt request callback. Called when a subscribe, unsubscribe /**
* @ingroup mqtt
* Function prototype for mqtt request callback. Called when a subscribe, unsubscribe
* or publish request has completed * or publish request has completed
* @param arg Pointer to user data supplied when invoking request * @param arg Pointer to user data supplied when invoking request
* @param err ERR_OK on success * @param err ERR_OK on success
@ -236,9 +223,11 @@ void mqtt_set_inpub_callback(mqtt_client_t *client, mqtt_incoming_publish_cb_t,
/** Common function for subscribe and unsubscribe */ /** Common function for subscribe and unsubscribe */
err_t mqtt_sub_unsub(mqtt_client_t *client, const char *topic, u8_t qos, mqtt_request_cb_t cb, void *arg, u8_t sub); err_t mqtt_sub_unsub(mqtt_client_t *client, const char *topic, u8_t qos, mqtt_request_cb_t cb, void *arg, u8_t sub);
/** Subscribe to topic */ /** @ingroup mqtt
*Subscribe to topic */
#define mqtt_subscribe(client, topic, qos, cb, arg) mqtt_sub_unsub(client, topic, qos, cb, arg, 1) #define mqtt_subscribe(client, topic, qos, cb, arg) mqtt_sub_unsub(client, topic, qos, cb, arg, 1)
/** Unsubscribe to topic */ /** @ingroup mqtt
* Unsubscribe to topic */
#define mqtt_unsubscribe(client, topic, cb, arg) mqtt_sub_unsub(client, topic, 0, cb, arg, 0) #define mqtt_unsubscribe(client, topic, cb, arg) mqtt_sub_unsub(client, topic, 0, cb, arg, 0)
@ -246,12 +235,8 @@ err_t mqtt_sub_unsub(mqtt_client_t *client, const char *topic, u8_t qos, mqtt_re
err_t mqtt_publish(mqtt_client_t *client, const char *topic, const void *payload, u16_t payload_length, u8_t qos, u8_t retain, err_t mqtt_publish(mqtt_client_t *client, const char *topic, const void *payload, u16_t payload_length, u8_t qos, u8_t retain,
mqtt_request_cb_t cb, void *arg); mqtt_request_cb_t cb, void *arg);
/**
* @}
*/
#ifdef __cplusplus #ifdef __cplusplus
} }
#endif #endif
#endif /* LWIP_HDR_MQTT_CLIENT_H */ #endif /* LWIP_HDR_APPS_MQTT_CLIENT_H */

View File

@ -0,0 +1,82 @@
/**
* @file
* MQTT client options
*/
/*
* Copyright (c) 2016 Erik Andersson
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without modification,
* are permitted provided that the following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright notice,
* this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright notice,
* this list of conditions and the following disclaimer in the documentation
* and/or other materials provided with the distribution.
* 3. The name of the author may not be used to endorse or promote products
* derived from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
* MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT
* SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT
* OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
* IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY
* OF SUCH DAMAGE.
*
* This file is part of the lwIP TCP/IP stack.
*
* Author: Erik Andersson
*
*/
#ifndef LWIP_HDR_APPS_MQTT_OPTS_H
#define LWIP_HDR_APPS_MQTT_OPTS_H
#include "lwip/opt.h"
#ifdef __cplusplus
extern "C" {
#endif
/**
* @defgroup mqtt_opts Options
* @ingroup mqtt
* @{
*/
/**
* Output ring-buffer size, must be able to fit largest outgoing publish message topic+payloads
*/
#ifndef MQTT_OUTPUT_RINGBUF_SIZE
#define MQTT_OUTPUT_RINGBUF_SIZE 256
#endif
/**
* Number of bytes in receive buffer, must be at least the size of the longest incoming topic + 8
* If one wants to avoid fragmented incoming publish, set length to max incoming topic length + max payload length + 8
*/
#ifndef MQTT_VAR_HEADER_BUFFER_LEN
#define MQTT_VAR_HEADER_BUFFER_LEN 128
#endif
/**
* Maximum number of pending subscribe, unsubscribe and publish requests to server .
*/
#ifndef MQTT_REQ_MAX_IN_FLIGHT
#define MQTT_REQ_MAX_IN_FLIGHT 4
#endif
/**
* @}
*/
#ifdef __cplusplus
}
#endif
#endif /* LWIP_HDR_APPS_MQTT_OPTS_H */