mqtt client release v1.1.0 ...
This commit is contained in:
19
components/connectivity/mqttclient/mqttclient/CMakeLists.txt
Normal file
19
components/connectivity/mqttclient/mqttclient/CMakeLists.txt
Normal file
@@ -0,0 +1,19 @@
|
||||
aux_source_directory(. DIR_SRCS)
|
||||
|
||||
string(REGEX REPLACE ".*/(.*)" "\\1" LIB_NAME ${CMAKE_CURRENT_SOURCE_DIR})
|
||||
|
||||
if (DIR_SRCS)
|
||||
foreach(libname ${LIBNAMES})
|
||||
if (${LIB_NAME} STREQUAL ${libname})
|
||||
add_library(${libname} ${CMAKE_LIB_TYPE} ${DIR_SRCS})
|
||||
target_link_libraries(${libname} "mqtt" "platform" "network" "common")
|
||||
endif()
|
||||
endforeach()
|
||||
|
||||
else()
|
||||
message(WARNING "not find is src file!")
|
||||
endif()
|
||||
|
||||
|
||||
|
||||
|
@@ -2,7 +2,7 @@
|
||||
* @Author: jiejie
|
||||
* @Github: https://github.com/jiejieTop
|
||||
* @Date: 2020-02-25 03:36:09
|
||||
* @LastEditTime: 2020-02-25 07:16:43
|
||||
* @LastEditTime: 2020-06-17 19:59:41
|
||||
* @Description: the code belongs to jiejie, please keep the author information and source code according to the license.
|
||||
*/
|
||||
|
||||
@@ -11,6 +11,10 @@
|
||||
|
||||
#include "mqtt_config.h"
|
||||
|
||||
#ifndef MQTT_LOG_LEVEL
|
||||
#define MQTT_LOG_LEVEL MQTT_LOG_DEBUG_LEVEL //MQTT_LOG_WARN_LEVEL MQTT_LOG_DEBUG_LEVEL
|
||||
#endif // !MQTT_LOG_LEVEL
|
||||
|
||||
#ifndef MQTT_MAX_PACKET_ID
|
||||
#define MQTT_MAX_PACKET_ID (0xFFFF - 1)
|
||||
#endif // !MQTT_MAX_PACKET_ID
|
||||
@@ -64,18 +68,19 @@
|
||||
#endif // !MQTT_THREAD_TICK
|
||||
|
||||
|
||||
#ifdef MQTT_NETWORK_TYPE_TLS
|
||||
#ifndef MQTT_NETWORK_TYPE_NO_TLS
|
||||
|
||||
#ifndef MQTT_TLS_HANDSHAKE_TIMEOUT
|
||||
#define MQTT_TLS_HANDSHAKE_TIMEOUT (5 * 1000)
|
||||
#endif // !MQTT_TLS_HANDSHAKE_TIMEOUT
|
||||
|
||||
#include "mbedtls/config.h"
|
||||
#include "mbedtls/ssl.h"
|
||||
#include "mbedtls/entropy.h"
|
||||
#include "mbedtls/net_sockets.h"
|
||||
#include "mbedtls/ctr_drbg.h"
|
||||
#include "mbedtls/error.h"
|
||||
#include "mbedtls/debug.h"
|
||||
#endif /* MQTT_NETWORK_TYPE_TLS */
|
||||
#endif /* MQTT_NETWORK_TYPE_NO_TLS */
|
||||
|
||||
#endif /* _DEFCONFIG_H_ */
|
||||
|
File diff suppressed because it is too large
Load Diff
@@ -2,17 +2,18 @@
|
||||
* @Author: jiejie
|
||||
* @Github: https://github.com/jiejieTop
|
||||
* @Date: 2019-12-09 21:31:25
|
||||
* @LastEditTime: 2020-04-18 12:29:23
|
||||
* @LastEditTime: 2020-06-16 16:57:40
|
||||
* @Description: the code belongs to jiejie, please keep the author information and source code according to the license.
|
||||
*/
|
||||
#ifndef _MQTTCLIENT_H_
|
||||
#define _MQTTCLIENT_H_
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdint.h>
|
||||
#include <string.h>
|
||||
|
||||
#include "MQTTPacket.h"
|
||||
#include "list.h"
|
||||
#include "mqtt_list.h"
|
||||
#include "platform_timer.h"
|
||||
#include "platform_memory.h"
|
||||
#include "platform_mutex.h"
|
||||
@@ -20,8 +21,8 @@
|
||||
#include "mqtt_defconfig.h"
|
||||
#include "network.h"
|
||||
#include "random.h"
|
||||
#include "error.h"
|
||||
#include "log.h"
|
||||
#include "mqtt_error.h"
|
||||
#include "mqtt_log.h"
|
||||
|
||||
typedef enum mqtt_qos {
|
||||
QOS0 = 0,
|
||||
@@ -39,15 +40,15 @@ typedef enum client_state {
|
||||
}client_state_t;
|
||||
|
||||
typedef struct mqtt_connack_data {
|
||||
unsigned char rc;
|
||||
unsigned char session_present;
|
||||
uint8_t rc;
|
||||
uint8_t session_present;
|
||||
} mqtt_connack_data_t;
|
||||
|
||||
typedef struct mqtt_message {
|
||||
mqtt_qos_t qos;
|
||||
unsigned char retained;
|
||||
unsigned char dup;
|
||||
unsigned short id;
|
||||
uint8_t retained;
|
||||
uint8_t dup;
|
||||
uint16_t id;
|
||||
size_t payloadlen;
|
||||
void *payload;
|
||||
} mqtt_message_t;
|
||||
@@ -62,83 +63,111 @@ typedef void (*message_handler_t)(void* client, message_data_t* msg);
|
||||
typedef void (*reconnect_handler_t)(void* client, void* reconnect_date);
|
||||
|
||||
typedef struct message_handlers {
|
||||
list_t list;
|
||||
mqtt_list_t list;
|
||||
mqtt_qos_t qos;
|
||||
const char* topic_filter;
|
||||
message_handler_t handler;
|
||||
} message_handlers_t;
|
||||
|
||||
typedef struct ack_handlers {
|
||||
list_t list;
|
||||
mqtt_list_t list;
|
||||
platform_timer_t timer;
|
||||
unsigned int type;
|
||||
unsigned short packet_id;
|
||||
uint32_t type;
|
||||
uint16_t packet_id;
|
||||
message_handlers_t *handler;
|
||||
unsigned short payload_len;
|
||||
unsigned char *payload;
|
||||
uint16_t payload_len;
|
||||
uint8_t *payload;
|
||||
} ack_handlers_t;
|
||||
|
||||
typedef struct connect_params {
|
||||
char *client_id;
|
||||
char *user_name;
|
||||
char *password;
|
||||
size_t client_id_len;
|
||||
size_t user_name_len;
|
||||
size_t password_len;
|
||||
unsigned char will_flag;
|
||||
void *will_options;
|
||||
unsigned short keep_alive_interval;
|
||||
unsigned char clean_session;
|
||||
unsigned char mqtt_version;
|
||||
network_params_t network_params;
|
||||
} connect_params_t;
|
||||
typedef struct mqtt_will_options {
|
||||
mqtt_qos_t will_qos;
|
||||
uint8_t will_retained;
|
||||
char *will_topic;
|
||||
char *will_message;
|
||||
} mqtt_will_options_t;
|
||||
|
||||
typedef struct mqtt_client {
|
||||
unsigned short packet_id;
|
||||
unsigned char ping_outstanding;
|
||||
unsigned char ack_handler_number;
|
||||
unsigned char *read_buf;
|
||||
unsigned char *write_buf;
|
||||
unsigned int cmd_timeout;
|
||||
unsigned int read_buf_size;
|
||||
unsigned int write_buf_size;
|
||||
unsigned int reconnect_try_duration;
|
||||
void *reconnect_date;
|
||||
reconnect_handler_t reconnect_handler;
|
||||
client_state_t client_state;
|
||||
platform_mutex_t write_lock;
|
||||
platform_mutex_t global_lock;
|
||||
list_t msg_handler_list;
|
||||
list_t ack_handler_list;
|
||||
network_t *network;
|
||||
platform_thread_t *thread;
|
||||
platform_timer_t reconnect_timer;
|
||||
platform_timer_t last_sent;
|
||||
platform_timer_t last_received;
|
||||
connect_params_t *connect_params;
|
||||
interceptor_handler_t interceptor_handler;
|
||||
char *mqtt_client_id;
|
||||
char *mqtt_user_name;
|
||||
char *mqtt_password;
|
||||
char *mqtt_host;
|
||||
char *mqtt_port;
|
||||
char *mqtt_ca;
|
||||
void *mqtt_reconnect_data;
|
||||
uint8_t *mqtt_read_buf;
|
||||
uint8_t *mqtt_write_buf;
|
||||
uint16_t mqtt_keep_alive_interval;
|
||||
uint16_t mqtt_packet_id;
|
||||
uint32_t mqtt_will_flag : 1;
|
||||
uint32_t mqtt_clean_session : 1;
|
||||
uint32_t mqtt_ping_outstanding : 2;
|
||||
uint32_t mqtt_version : 4;
|
||||
uint32_t mqtt_ack_handler_number : 24;
|
||||
uint32_t mqtt_cmd_timeout;
|
||||
uint32_t mqtt_read_buf_size;
|
||||
uint32_t mqtt_write_buf_size;
|
||||
uint32_t mqtt_reconnect_try_duration;
|
||||
size_t mqtt_client_id_len;
|
||||
size_t mqtt_user_name_len;
|
||||
size_t mqtt_password_len;
|
||||
mqtt_will_options_t *mqtt_will_options;
|
||||
client_state_t mqtt_client_state;
|
||||
platform_mutex_t mqtt_write_lock;
|
||||
platform_mutex_t mqtt_global_lock;
|
||||
mqtt_list_t mqtt_msg_handler_list;
|
||||
mqtt_list_t mqtt_ack_handler_list;
|
||||
network_t *mqtt_network;
|
||||
platform_thread_t *mqtt_thread;
|
||||
platform_timer_t mqtt_reconnect_timer;
|
||||
platform_timer_t mqtt_last_sent;
|
||||
platform_timer_t mqtt_last_received;
|
||||
reconnect_handler_t mqtt_reconnect_handler;
|
||||
interceptor_handler_t mqtt_interceptor_handler;
|
||||
} mqtt_client_t;
|
||||
|
||||
typedef struct client_init_params{
|
||||
unsigned int cmd_timeout;
|
||||
unsigned int read_buf_size;
|
||||
unsigned int write_buf_size;
|
||||
unsigned int reconnect_try_duration;
|
||||
void *reconnect_date;
|
||||
reconnect_handler_t reconnect_handler;
|
||||
connect_params_t connect_params;
|
||||
} client_init_params_t;
|
||||
|
||||
int mqtt_keep_alive(mqtt_client_t* c);
|
||||
int mqtt_init(mqtt_client_t* c, client_init_params_t* init);
|
||||
#define MQTT_ROBUSTNESS_CHECK(item, err) if (!(item)) { \
|
||||
MQTT_LOG_E("%s:%d %s()... check for error.", __FILE__, __LINE__, __FUNCTION__); \
|
||||
return err; }
|
||||
|
||||
#define MQTT_CLIENT_SET_DEFINE(name, type, res) \
|
||||
type mqtt_set_##name(mqtt_client_t *c, type t) { \
|
||||
MQTT_ROBUSTNESS_CHECK((c), res); \
|
||||
c->mqtt_##name = t; \
|
||||
return c->mqtt_##name; \
|
||||
}
|
||||
|
||||
#define MQTT_CLIENT_SET_STATEMENT(name, type) \
|
||||
type mqtt_set_##name(mqtt_client_t *, type);
|
||||
|
||||
MQTT_CLIENT_SET_STATEMENT(client_id, char*)
|
||||
MQTT_CLIENT_SET_STATEMENT(user_name, char*)
|
||||
MQTT_CLIENT_SET_STATEMENT(password, char*)
|
||||
MQTT_CLIENT_SET_STATEMENT(host, char*)
|
||||
MQTT_CLIENT_SET_STATEMENT(port, char*)
|
||||
MQTT_CLIENT_SET_STATEMENT(ca, char*)
|
||||
MQTT_CLIENT_SET_STATEMENT(reconnect_data, void*)
|
||||
MQTT_CLIENT_SET_STATEMENT(keep_alive_interval, uint16_t)
|
||||
MQTT_CLIENT_SET_STATEMENT(will_flag, uint32_t)
|
||||
MQTT_CLIENT_SET_STATEMENT(clean_session, uint32_t)
|
||||
MQTT_CLIENT_SET_STATEMENT(version, uint32_t)
|
||||
MQTT_CLIENT_SET_STATEMENT(cmd_timeout, uint32_t)
|
||||
MQTT_CLIENT_SET_STATEMENT(read_buf_size, uint32_t)
|
||||
MQTT_CLIENT_SET_STATEMENT(write_buf_size, uint32_t)
|
||||
MQTT_CLIENT_SET_STATEMENT(reconnect_try_duration, uint32_t)
|
||||
MQTT_CLIENT_SET_STATEMENT(reconnect_handler, reconnect_handler_t)
|
||||
MQTT_CLIENT_SET_STATEMENT(interceptor_handler, interceptor_handler_t)
|
||||
|
||||
void mqtt_sleep_ms(int ms);
|
||||
mqtt_client_t *mqtt_lease(void);
|
||||
int mqtt_release(mqtt_client_t* c);
|
||||
int mqtt_connect(mqtt_client_t* c);
|
||||
int mqtt_disconnect(mqtt_client_t* c);
|
||||
int mqtt_keep_alive(mqtt_client_t* c);
|
||||
int mqtt_subscribe(mqtt_client_t* c, const char* topic_filter, mqtt_qos_t qos, message_handler_t msg_handler);
|
||||
int mqtt_unsubscribe(mqtt_client_t* c, const char* topic_filter);
|
||||
int mqtt_publish(mqtt_client_t* c, const char* topic_filter, mqtt_message_t* msg);
|
||||
int mqtt_list_subscribe_topic(mqtt_client_t* c);
|
||||
int mqtt_set_interceptor_handler(mqtt_client_t* c, interceptor_handler_t handler);
|
||||
|
||||
int mqtt_set_will_options(mqtt_client_t* c, char *topic, mqtt_qos_t qos, uint8_t retained, char *message);
|
||||
|
||||
#endif /* _MQTTCLIENT_H_ */
|
||||
|
Reference in New Issue
Block a user