Skip to content

Commit

Permalink
bugfix: incorrect data send timer reset with lost pub ACK causing dat…
Browse files Browse the repository at this point in the history
…a send stopped

- We used to reset data_send timer without checking the message ID
- If the puback is not received for MQTT message, and the timer reset above happened,
  causes data_send_in_progress remain true for eternity, causing insights not able to send data
- Fixed by moving timer reset logic only where it is applicable
  • Loading branch information
Shardul Nalegave authored and vikramdattu committed Jan 20, 2025
1 parent 36c8bfc commit 06ef3d2
Showing 1 changed file with 16 additions and 6 deletions.
22 changes: 16 additions & 6 deletions components/esp_insights/src/esp_insights.c
Original file line number Diff line number Diff line change
Expand Up @@ -278,35 +278,45 @@ static void insights_event_handler(void* arg, esp_event_base_t event_base,
}
switch(event_id) {
case INSIGHTS_EVENT_TRANSPORT_SEND_SUCCESS:
#if INSIGHTS_DEBUG_ENABLED
ESP_LOGI(TAG, "Data send success, msg_id:%d.", data ? data->msg_id : 0);
#endif
if (data && data->msg_id) {
xSemaphoreTake(s_insights_data.data_lock, portMAX_DELAY);
if (xTimerIsTimerActive(s_insights_data.data_send_timer) == pdTRUE) {
xTimerStop(s_insights_data.data_send_timer, portMAX_DELAY);
}
if (data->msg_id == s_insights_data.data_msg_id) {
#if INSIGHTS_DEBUG_ENABLED
ESP_LOGI(TAG, "Data message send success, msg_id:%d.", data ? data->msg_id : 0);
#endif
esp_diag_data_store_critical_release(s_insights_data.data_msg_len);
s_insights_data.data_sent = true;
s_insights_data.data_send_inprogress = false;
if (xTimerIsTimerActive(s_insights_data.data_send_timer) == pdTRUE) {
xTimerStop(s_insights_data.data_send_timer, portMAX_DELAY);
}
#if SEND_INSIGHTS_META
} else if (s_insights_data.meta_msg_pending && data->msg_id == s_insights_data.meta_msg_id) {
#if INSIGHTS_DEBUG_ENABLED
ESP_LOGI(TAG, "Meta message send success, msg_id:%d.", data ? data->msg_id : 0);
#endif
esp_insights_meta_nvs_crc_set(s_insights_data.meta_crc);
s_insights_data.meta_msg_pending = false;
s_insights_data.data_sent = true;
#endif /* SEND_INSIGHTS_META */
} else if (s_insights_data.boot_msg_id > 0 && s_insights_data.boot_msg_id == data->msg_id) {
#if INSIGHTS_DEBUG_ENABLED
ESP_LOGI(TAG, "Boot message send success, msg_id:%d.", data ? data->msg_id : 0);
#endif
#if CONFIG_ESP_INSIGHTS_COREDUMP_ENABLE
esp_core_dump_image_erase();
#endif // CONFIG_ESP_INSIGHTS_COREDUMP_ENABLE
s_insights_data.boot_msg_id = 0;
}
#if INSIGHTS_CMD_RESP
else if (s_insights_data.conf_msg_id > 0 && s_insights_data.conf_msg_id == data->msg_id) {
#if INSIGHTS_DEBUG_ENABLED
ESP_LOGI(TAG, "Conf message send success, msg_id:%d.", data ? data->msg_id : 0);
#endif
s_insights_data.conf_msg_id = 0;
}
#endif

xSemaphoreGive(s_insights_data.data_lock);
}
break;
Expand Down

0 comments on commit 06ef3d2

Please sign in to comment.