From f0f3e11f6b3d29ce2da6a74a7b4d8463b6c98eed Mon Sep 17 00:00:00 2001 From: Tijn Kooijmans Date: Thu, 22 Feb 2018 13:16:41 +0100 Subject: [PATCH 1/6] allow setting of cusom length lwt msg --- include/mqtt_client.h | 1 + mqtt_client.c | 5 ++++- 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/include/mqtt_client.h b/include/mqtt_client.h index 318992a..e5b2e61 100755 --- a/include/mqtt_client.h +++ b/include/mqtt_client.h @@ -67,6 +67,7 @@ typedef struct { char lwt_msg[MQTT_MAX_LWT_MSG]; int lwt_qos; int lwt_retain; + int lwt_msg_len; int disable_clean_session; int keepalive; bool disable_auto_reconnect; diff --git a/mqtt_client.c b/mqtt_client.c index f54a19c..3117dfa 100644 --- a/mqtt_client.c +++ b/mqtt_client.c @@ -127,7 +127,10 @@ static esp_err_t esp_mqtt_set_config(esp_mqtt_client_handle_t client, const esp_ if (config->lwt_msg[0]) { 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; From 1b0ef3925536ca088cdea4cad76311ca0ef41a24 Mon Sep 17 00:00:00 2001 From: Tijn Kooijmans Date: Thu, 22 Feb 2018 13:16:55 +0100 Subject: [PATCH 2/6] updated config --- include/mqtt_config.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/include/mqtt_config.h b/include/mqtt_config.h index 7daec77..a8dcf68 100644 --- a/include/mqtt_config.h +++ b/include/mqtt_config.h @@ -12,9 +12,9 @@ #define MQTT_MAX_HOST_LEN 64 #define MQTT_MAX_CLIENT_LEN 32 #define MQTT_MAX_USERNAME_LEN 32 -#define MQTT_MAX_PASSWORD_LEN 32 +#define MQTT_MAX_PASSWORD_LEN 64 #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_STACK (6*1024) #define MQTT_KEEPALIVE_TICK (120) From 3d991229447ed6ff78e2bd0696ab05767bcc8495 Mon Sep 17 00:00:00 2001 From: Tijn Kooijmans Date: Thu, 22 Feb 2018 15:57:25 +0100 Subject: [PATCH 3/6] increased password length --- include/mqtt_config.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/include/mqtt_config.h b/include/mqtt_config.h index a8dcf68..15222c4 100644 --- a/include/mqtt_config.h +++ b/include/mqtt_config.h @@ -12,7 +12,7 @@ #define MQTT_MAX_HOST_LEN 64 #define MQTT_MAX_CLIENT_LEN 32 #define MQTT_MAX_USERNAME_LEN 32 -#define MQTT_MAX_PASSWORD_LEN 64 +#define MQTT_MAX_PASSWORD_LEN 65 #define MQTT_MAX_LWT_TOPIC 32 #define MQTT_MAX_LWT_MSG 128 #define MQTT_TASK_PRIORITY 5 From 8c34c8df688020fb1a147e9856ccb5c6df68d8a7 Mon Sep 17 00:00:00 2001 From: JasonJiaJie Date: Mon, 26 Feb 2018 16:06:42 +0800 Subject: [PATCH 4/6] Keppalive issue There is no keepalive packget if current time is very large. Caused by integer overflow. --- lib/include/platform_esp32_idf.h | 2 +- lib/platform_esp32_idf.c | 2 +- mqtt_client.c | 8 ++++---- 3 files changed, 6 insertions(+), 6 deletions(-) diff --git a/lib/include/platform_esp32_idf.h b/lib/include/platform_esp32_idf.h index f8585f3..fa117a9 100644 --- a/lib/include/platform_esp32_idf.h +++ b/lib/include/platform_esp32_idf.h @@ -27,5 +27,5 @@ char *platform_create_id_string(); int platform_random(int max); -int platform_tick_get_ms(); +long long platform_tick_get_ms(); #endif diff --git a/lib/platform_esp32_idf.c b/lib/platform_esp32_idf.c index daee511..4a536b3 100644 --- a/lib/platform_esp32_idf.c +++ b/lib/platform_esp32_idf.c @@ -19,7 +19,7 @@ int platform_random(int max) return esp_random()%max; } -int platform_tick_get_ms() +long long platform_tick_get_ms() { struct timeval te; gettimeofday(&te, NULL); // get current time diff --git a/mqtt_client.c b/mqtt_client.c index f54a19c..5b06501 100644 --- a/mqtt_client.c +++ b/mqtt_client.c @@ -61,8 +61,8 @@ struct esp_mqtt_client { mqtt_state_t mqtt_state; mqtt_connect_info_t connect_info; mqtt_client_state_t state; - int keepalive_tick; - int reconnect_tick; + long long keepalive_tick; + long long reconnect_tick; int wait_timeout_ms; int auto_reconnect; esp_mqtt_event_t event; @@ -310,8 +310,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->keepalive_tick = 0; - client->reconnect_tick = 0; + client->keepalive_tick = platform_tick_get_ms(); + client->reconnect_tick = platform_tick_get_ms(); int buffer_size = config->buffer_size; if (buffer_size <= 0) { From a8c78d5cbf8058672d467c6f7f0b8a16ccc7a218 Mon Sep 17 00:00:00 2001 From: Tuan PM Date: Tue, 27 Feb 2018 10:52:35 +0700 Subject: [PATCH 5/6] Remove Paypal donate --- README.md | 1 - 1 file changed, 1 deletion(-) diff --git a/README.md b/README.md index fbacaa3..4a4f264 100644 --- a/README.md +++ b/README.md @@ -2,7 +2,6 @@ [![](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) ![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 From 7322fc79e9a9fb905d64cff60c9fb47e9774df45 Mon Sep 17 00:00:00 2001 From: Tijn Kooijmans Date: Tue, 27 Feb 2018 16:54:13 +0100 Subject: [PATCH 6/6] fixed indents and bracets --- mqtt_client.c | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/mqtt_client.c b/mqtt_client.c index 3117dfa..60b8d11 100644 --- a/mqtt_client.c +++ b/mqtt_client.c @@ -127,10 +127,12 @@ static esp_err_t esp_mqtt_set_config(esp_mqtt_client_handle_t client, const esp_ if (config->lwt_msg[0]) { client->connect_info.will_message = strdup(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); + 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;