Skip to content

Commit 9de024c

Browse files
Merge branch 'feature/tcp_keepalive' into 'master'
feat: Add TCP keepalive configuration Closes IDF-8049 See merge request espressif/esp-mqtt!220
2 parents e89f239 + 7c3227a commit 9de024c

File tree

3 files changed

+10
-0
lines changed

3 files changed

+10
-0
lines changed

include/mqtt_client.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -341,6 +341,7 @@ typedef struct esp_mqtt_client_config_t {
341341
int refresh_connection_after_ms; /*!< Refresh connection after this value (in milliseconds) */
342342
bool disable_auto_reconnect; /*!< Client will reconnect to server (when errors/disconnect). Set
343343
`disable_auto_reconnect=true` to disable */
344+
esp_transport_keep_alive_t tcp_keep_alive_cfg; /*!< Transport keep-alive config*/
344345
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. */
345346
struct ifreq * if_name; /*!< The name of interface for data to go through. Use the default interface without setting */
346347
} network; /*!< Network configuration */

lib/include/mqtt_client_priv.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -100,6 +100,7 @@ typedef struct {
100100
uint64_t outbox_limit;
101101
esp_transport_handle_t transport;
102102
struct ifreq * if_name;
103+
esp_transport_keep_alive_t tcp_keep_alive_cfg;
103104
} mqtt_config_storage_t;
104105

105106
typedef enum {

mqtt_client.c

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -429,6 +429,10 @@ esp_err_t esp_mqtt_set_config(esp_mqtt_client_handle_t client, const esp_mqtt_cl
429429
client->config->port = config->broker.address.port;
430430
}
431431

432+
if (config->network.tcp_keep_alive_cfg.keep_alive_enable) {
433+
client->config->tcp_keep_alive_cfg = config->network.tcp_keep_alive_cfg;
434+
}
435+
432436
err = ESP_ERR_NO_MEM;
433437
ESP_MEM_CHECK(TAG, esp_mqtt_set_if_config(config->broker.address.hostname, &client->config->host), goto _mqtt_set_config_failed);
434438
ESP_MEM_CHECK(TAG, esp_mqtt_set_if_config(config->broker.address.path, &client->config->path), goto _mqtt_set_config_failed);
@@ -1627,6 +1631,10 @@ static void esp_mqtt_task(void *pv)
16271631
esp_mqtt_set_ssl_transport_properties(client->transport_list, client->config);
16281632
#endif
16291633

1634+
if(client->config->tcp_keep_alive_cfg.keep_alive_enable) {
1635+
esp_transport_tcp_set_keep_alive(client->transport, &client->config->tcp_keep_alive_cfg);
1636+
}
1637+
16301638
client->event.event_id = MQTT_EVENT_BEFORE_CONNECT;
16311639
esp_mqtt_dispatch_event_with_msgid(client);
16321640

0 commit comments

Comments
 (0)