From c3c4cb9a2a69d1f9897e6a3608ea30a52d6083b3 Mon Sep 17 00:00:00 2001 From: Jackson Ming Hu Date: Mon, 1 Jul 2024 15:29:38 +1000 Subject: [PATCH] fix: set TCP transport every time when setting the config --- include/mqtt_client.h | 2 +- mqtt_client.c | 5 ++--- 2 files changed, 3 insertions(+), 4 deletions(-) diff --git a/include/mqtt_client.h b/include/mqtt_client.h index 66558aa..f835107 100644 --- a/include/mqtt_client.h +++ b/include/mqtt_client.h @@ -336,7 +336,7 @@ typedef struct esp_mqtt_client_config_t { int refresh_connection_after_ms; /*!< Refresh connection after this value (in milliseconds) */ bool disable_auto_reconnect; /*!< Client will reconnect to server (when errors/disconnect). Set `disable_auto_reconnect=true` to disable */ - esp_transport_handle_t transport; /*!< Custom transport handle to use. Warning: The transport should be valid during the client lifetime and is destroyed when esp_mqtt_client_destroy is called. */ + esp_transport_handle_t transport; /*!< Custom transport handle to use, leave it NULL to allow MQTT client create or recreate its own. Warning: The transport should be valid during the client lifetime and is destroyed when esp_mqtt_client_destroy is called. */ struct ifreq * if_name; /*!< The name of interface for data to go through. Use the default interface without setting */ } network; /*!< Network configuration */ /** diff --git a/mqtt_client.c b/mqtt_client.c index bcd1a74..15dadac 100644 --- a/mqtt_client.c +++ b/mqtt_client.c @@ -526,9 +526,8 @@ esp_err_t esp_mqtt_set_config(esp_mqtt_client_handle_t client, const esp_mqtt_cl } else { client->config->reconnect_timeout_ms = MQTT_RECON_DEFAULT_MS; } - if (config->network.transport) { - client->config->transport = config->network.transport; - } + + client->config->transport = config->network.transport; if (config->network.if_name) { client->config->if_name = calloc(1, sizeof(struct ifreq) + 1);