Merge branch 'feature/configurable_retransmit' into 'master'

Add configurable retransmit (GitHub PR)

See merge request espressif/esp-mqtt!110
This commit is contained in:
David Čermák
2021-09-15 18:10:50 +00:00
2 changed files with 9 additions and 2 deletions

View File

@@ -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;
/**

View File

@@ -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 {
@@ -369,6 +370,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;
@@ -1438,10 +1444,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);
}
}