diff --git a/include/mqtt_client.h b/include/mqtt_client.h index e365cb8..203bdab 100644 --- a/include/mqtt_client.h +++ b/include/mqtt_client.h @@ -179,7 +179,7 @@ typedef struct { int refresh_connection_after_ms; /*!< Refresh connection after this value (in milliseconds) */ const struct psk_key_hint* psk_hint_key; /*!< Pointer to PSK struct defined in esp_tls.h to enable PSK authentication (as alternative to certificate verification). If not NULL and server/client certificates are NULL, PSK is enabled */ bool use_global_ca_store; /*!< Use a global ca_store for all the connections in which this bool is set. */ - int reconnect_timeout_ms; /*!< Reconnect to the broker after this value in miliseconds if auto reconnect is not disabled */ + int reconnect_timeout_ms; /*!< Reconnect to the broker after this value in miliseconds if auto reconnect is not disabled (defaults to 10s) */ const char **alpn_protos; /*!< NULL-terminated list of supported application protocols to be used for ALPN */ const char *clientkey_password; /*!< Client key decryption password string */ int clientkey_password_len; /*!< String length of the password pointed to by clientkey_password */ @@ -188,6 +188,7 @@ typedef struct { bool skip_cert_common_name_check; /*!< Skip any validation of server certificate CN field, this reduces the security of TLS and makes the mqtt client susceptible to MITM attacks */ bool use_secure_element; /*!< enable secure element for enabling SSL connection */ void *ds_data; /*!< carrier of handle for digital signature parameters */ + int network_timeout_ms; /*!< Abort network operation if it is not completed after this value, in milliseconds (defaults to 10s) */ } esp_mqtt_client_config_t; /** diff --git a/mqtt_client.c b/mqtt_client.c index aff0809..4b25736 100644 --- a/mqtt_client.c +++ b/mqtt_client.c @@ -431,7 +431,11 @@ esp_err_t esp_mqtt_set_config(esp_mqtt_client_handle_t client, const esp_mqtt_cl #endif } - cfg->network_timeout_ms = MQTT_NETWORK_TIMEOUT_MS; + cfg->network_timeout_ms = config->network_timeout_ms; + if (cfg->network_timeout_ms <= 0) { + cfg->network_timeout_ms = MQTT_NETWORK_TIMEOUT_MS; + } + if (config->user_context) { cfg->user_context = config->user_context; }