From e918742eddc13f39ed3c08241b79dbeb5081a871 Mon Sep 17 00:00:00 2001 From: Craig Kewley Date: Mon, 30 May 2022 21:23:27 +0100 Subject: [PATCH] mqtt_client: fix esp_mqtt_client_enqueue for len=0 Commit 372b323 (mqtt_client: Fix mqtt send long data error, 2021-12-21) removed the length calculation from esp_mqtt_client_enqueue_priv and added it to esp_mqtt_client_publish. However, esp_mqtt_client_enqueue was missed. Currently calls to esp_mqtt_client_enqueue appear to send no data, fix this by adding the length calculation to esp_mqtt_client_enqueue. --- mqtt_client.c | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/mqtt_client.c b/mqtt_client.c index 013bde7d..a589f626 100644 --- a/mqtt_client.c +++ b/mqtt_client.c @@ -1900,6 +1900,16 @@ int esp_mqtt_client_enqueue(esp_mqtt_client_handle_t client, const char *topic, ESP_LOGE(TAG, "Client was not initialized"); return -1; } + + /* Acceptable publish messages: + data == NULL, len == 0: publish null message + data valid, len == 0: publish all data, payload len is determined from string length + data valid, len > 0: publish data with defined length + */ + if (len <= 0 && data != NULL) { + len = strlen(data); + } + MQTT_API_LOCK(client); int ret = mqtt_client_enqueue_priv(client, topic, data, len, qos, retain, store); MQTT_API_UNLOCK(client);