mirror of
https://github.com/espressif/esp-mqtt.git
synced 2025-07-29 18:28:24 +02:00
Config: Add configurable retransmit timeout
sometime user want to configure retransmit timeout due to network or other requirement Merges https://github.com/espressif/esp-mqtt/pull/199
This commit is contained in:
@ -206,6 +206,7 @@ typedef struct {
|
||||
int network_timeout_ms; /*!< Abort network operation if it is not completed after this value, in milliseconds (defaults to 10s) */
|
||||
bool disable_keepalive; /*!< Set disable_keepalive=true to turn off keep-alive mechanism, false by default (keepalive is active by default). Note: setting the config value `keepalive` to `0` doesn't disable keepalive feature, but uses a default keepalive period */
|
||||
const char *path; /*!< Path in the URI*/
|
||||
int message_retransmit_timeout; /*!< timeout for retansmit of failded packet */
|
||||
} esp_mqtt_client_config_t;
|
||||
|
||||
/**
|
||||
|
@ -89,6 +89,7 @@ typedef struct {
|
||||
bool skip_cert_common_name_check;
|
||||
bool use_secure_element;
|
||||
void *ds_data;
|
||||
int message_retransmit_timeout;
|
||||
} mqtt_config_storage_t;
|
||||
|
||||
typedef enum {
|
||||
@ -364,6 +365,11 @@ esp_err_t esp_mqtt_set_config(esp_mqtt_client_handle_t client, const esp_mqtt_cl
|
||||
});
|
||||
}
|
||||
|
||||
client->config->message_retransmit_timeout = config->message_retransmit_timeout;
|
||||
if (config->message_retransmit_timeout <= 0) {
|
||||
client->config->message_retransmit_timeout = 1000;
|
||||
}
|
||||
|
||||
client->config->task_prio = config->task_prio;
|
||||
if (client->config->task_prio <= 0) {
|
||||
client->config->task_prio = MQTT_TASK_PRIORITY;
|
||||
@ -1420,10 +1426,10 @@ static void esp_mqtt_task(void *pv)
|
||||
outbox_set_pending(client->outbox, client->mqtt_state.pending_msg_id, TRANSMITTED);
|
||||
}
|
||||
// resend other "transmitted" messages after 1s
|
||||
} else if (platform_tick_get_ms() - last_retransmit > 1000) {
|
||||
} else if (platform_tick_get_ms() - last_retransmit > client->config->message_retransmit_timeout) {
|
||||
last_retransmit = platform_tick_get_ms();
|
||||
item = outbox_dequeue(client->outbox, TRANSMITTED, &msg_tick);
|
||||
if (item && (last_retransmit - msg_tick > 1000)) {
|
||||
if (item && (last_retransmit - msg_tick > client->config->message_retransmit_timeout)) {
|
||||
mqtt_resend_queued(client, item);
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user