This commit is contained in:
Tuan PM
2018-02-27 23:02:40 +07:00
6 changed files with 15 additions and 10 deletions

View File

@@ -2,7 +2,6 @@
[![](http://hits.dwyl.io/tuanpmt/espmqtt.svg)](http://hits.dwyl.io/tuanpmt/espmqtt) [![](http://hits.dwyl.io/tuanpmt/espmqtt.svg)](http://hits.dwyl.io/tuanpmt/espmqtt)
[![Twitter Follow](https://img.shields.io/twitter/follow/tuanpmt.svg?style=social&label=Follow)](https://twitter.com/tuanpmt) [![Twitter Follow](https://img.shields.io/twitter/follow/tuanpmt.svg?style=social&label=Follow)](https://twitter.com/tuanpmt)
![GitHub contributors](https://img.shields.io/github/contributors/tuanpmt/espmqtt.svg) ![GitHub contributors](https://img.shields.io/github/contributors/tuanpmt/espmqtt.svg)
[![Paypal donate](https://img.shields.io/badge/Donate-PayPal-green.svg)](https://www.paypal.me/tuanpm)
# ESP32 MQTT Library # ESP32 MQTT Library

View File

@@ -67,6 +67,7 @@ typedef struct {
char lwt_msg[MQTT_MAX_LWT_MSG]; char lwt_msg[MQTT_MAX_LWT_MSG];
int lwt_qos; int lwt_qos;
int lwt_retain; int lwt_retain;
int lwt_msg_len;
int disable_clean_session; int disable_clean_session;
int keepalive; int keepalive;
bool disable_auto_reconnect; bool disable_auto_reconnect;

View File

@@ -12,9 +12,9 @@
#define MQTT_MAX_HOST_LEN 64 #define MQTT_MAX_HOST_LEN 64
#define MQTT_MAX_CLIENT_LEN 32 #define MQTT_MAX_CLIENT_LEN 32
#define MQTT_MAX_USERNAME_LEN 32 #define MQTT_MAX_USERNAME_LEN 32
#define MQTT_MAX_PASSWORD_LEN 32 #define MQTT_MAX_PASSWORD_LEN 65
#define MQTT_MAX_LWT_TOPIC 32 #define MQTT_MAX_LWT_TOPIC 32
#define MQTT_MAX_LWT_MSG 32 #define MQTT_MAX_LWT_MSG 128
#define MQTT_TASK_PRIORITY 5 #define MQTT_TASK_PRIORITY 5
#define MQTT_TASK_STACK (6*1024) #define MQTT_TASK_STACK (6*1024)
#define MQTT_KEEPALIVE_TICK (120) #define MQTT_KEEPALIVE_TICK (120)

View File

@@ -27,5 +27,5 @@
char *platform_create_id_string(); char *platform_create_id_string();
int platform_random(int max); int platform_random(int max);
int platform_tick_get_ms(); long long platform_tick_get_ms();
#endif #endif

View File

@@ -19,7 +19,7 @@ int platform_random(int max)
return esp_random()%max; return esp_random()%max;
} }
int platform_tick_get_ms() long long platform_tick_get_ms()
{ {
struct timeval te; struct timeval te;
gettimeofday(&te, NULL); // get current time gettimeofday(&te, NULL); // get current time

View File

@@ -61,8 +61,8 @@ struct esp_mqtt_client {
mqtt_state_t mqtt_state; mqtt_state_t mqtt_state;
mqtt_connect_info_t connect_info; mqtt_connect_info_t connect_info;
mqtt_client_state_t state; mqtt_client_state_t state;
int keepalive_tick; long long keepalive_tick;
int reconnect_tick; long long reconnect_tick;
int wait_timeout_ms; int wait_timeout_ms;
int auto_reconnect; int auto_reconnect;
esp_mqtt_event_t event; esp_mqtt_event_t event;
@@ -127,7 +127,12 @@ static esp_err_t esp_mqtt_set_config(esp_mqtt_client_handle_t client, const esp_
if (config->lwt_msg[0]) { if (config->lwt_msg[0]) {
client->connect_info.will_message = strdup(config->lwt_msg); client->connect_info.will_message = strdup(config->lwt_msg);
client->connect_info.will_length = strlen(config->lwt_msg); if (config->lwt_msg_len > 0) {
client->connect_info.will_length = config->lwt_msg_len;
}
else {
client->connect_info.will_length = strlen(config->lwt_msg);
}
} }
client->connect_info.will_qos = config->lwt_qos; client->connect_info.will_qos = config->lwt_qos;
@@ -311,8 +316,8 @@ esp_mqtt_client_handle_t esp_mqtt_client_init(const esp_mqtt_client_config_t *co
client->config->scheme = create_string("mqtt", 4); client->config->scheme = create_string("mqtt", 4);
} }
client->keepalive_tick = 0; client->keepalive_tick = platform_tick_get_ms();
client->reconnect_tick = 0; client->reconnect_tick = platform_tick_get_ms();
int buffer_size = config->buffer_size; int buffer_size = config->buffer_size;
if (buffer_size <= 0) { if (buffer_size <= 0) {