wait for the entire connack message with the configured timeout

Configured network timeout was used to receive separate characters
in the message. This change waits for the configured timeout if reading
the mqtt packet was left in progress (mqtt_message_receive() returns 0)

Closes FCS-254
This commit is contained in:
David Cermak
2019-12-04 11:32:36 +01:00
parent 716b8625ba
commit 97f91eda5c

View File

@ -343,7 +343,11 @@ static esp_err_t esp_mqtt_connect(esp_mqtt_client_handle_t client, int timeout_m
client->mqtt_state.message_length = 0;
/* wait configured network timeout for broker connection response */
read_len = mqtt_message_receive(client, client->config->network_timeout_ms);
uint64_t connack_recv_started = platform_tick_get_ms();
do {
read_len = mqtt_message_receive(client, client->config->network_timeout_ms);
} while (read_len == 0 && platform_tick_get_ms() - connack_recv_started < client->config->network_timeout_ms);
if (read_len <= 0) {
ESP_LOGE(TAG, "%s: mqtt_message_receive() returned %d", __func__, read_len);
return ESP_FAIL;