mirror of
https://github.com/espressif/esp-mqtt.git
synced 2025-07-29 18:28:24 +02:00
Merge branch 'feature/tcp_keepalive' into 'master'
feat: Add TCP keepalive configuration Closes IDF-8049 See merge request espressif/esp-mqtt!220
This commit is contained in:
@ -341,6 +341,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_keep_alive_t tcp_keep_alive_cfg; /*!< Transport keep-alive config*/
|
||||
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 */
|
||||
|
@ -100,6 +100,7 @@ typedef struct {
|
||||
uint64_t outbox_limit;
|
||||
esp_transport_handle_t transport;
|
||||
struct ifreq * if_name;
|
||||
esp_transport_keep_alive_t tcp_keep_alive_cfg;
|
||||
} mqtt_config_storage_t;
|
||||
|
||||
typedef enum {
|
||||
|
@ -429,6 +429,10 @@ esp_err_t esp_mqtt_set_config(esp_mqtt_client_handle_t client, const esp_mqtt_cl
|
||||
client->config->port = config->broker.address.port;
|
||||
}
|
||||
|
||||
if (config->network.tcp_keep_alive_cfg.keep_alive_enable) {
|
||||
client->config->tcp_keep_alive_cfg = config->network.tcp_keep_alive_cfg;
|
||||
}
|
||||
|
||||
err = ESP_ERR_NO_MEM;
|
||||
ESP_MEM_CHECK(TAG, esp_mqtt_set_if_config(config->broker.address.hostname, &client->config->host), goto _mqtt_set_config_failed);
|
||||
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)
|
||||
esp_mqtt_set_ssl_transport_properties(client->transport_list, client->config);
|
||||
#endif
|
||||
|
||||
if(client->config->tcp_keep_alive_cfg.keep_alive_enable) {
|
||||
esp_transport_tcp_set_keep_alive(client->transport, &client->config->tcp_keep_alive_cfg);
|
||||
}
|
||||
|
||||
client->event.event_id = MQTT_EVENT_BEFORE_CONNECT;
|
||||
esp_mqtt_dispatch_event_with_msgid(client);
|
||||
|
||||
|
Reference in New Issue
Block a user