diff --git a/include/mqtt_client.h b/include/mqtt_client.h index a347f08..12bb70c 100644 --- a/include/mqtt_client.h +++ b/include/mqtt_client.h @@ -82,6 +82,7 @@ typedef struct { int topic_len; /*!< Length of the topic for this event asociated with this event */ int msg_id; /*!< MQTT messaged id of message */ int session_present; /*!< MQTT session_present flag for connection event */ + void* error_handle; /*!< esp-tls error handle referencing last error/flags captured in transports */ } esp_mqtt_event_t; typedef esp_mqtt_event_t *esp_mqtt_event_handle_t; diff --git a/include/mqtt_supported_features.h b/include/mqtt_supported_features.h index 3e9fac0..44f97f4 100644 --- a/include/mqtt_supported_features.h +++ b/include/mqtt_supported_features.h @@ -36,6 +36,7 @@ #if ESP_IDF_VERSION >= ESP_IDF_VERSION_VAL(4, 0, 0) // Features supported in 4.0 #define MQTT_SUPPORTED_FEATURE_WS_SUBPROTOCOL +#define MQTT_SUPPORTED_FEATURE_TRANSPORT_ERR_REPORTING #endif #endif diff --git a/mqtt_client.c b/mqtt_client.c index 22490eb..b06fdd6 100644 --- a/mqtt_client.c +++ b/mqtt_client.c @@ -993,6 +993,11 @@ static void esp_mqtt_task(void *pv) client->config->port, client->config->network_timeout_ms) < 0) { ESP_LOGE(TAG, "Error transport connect"); + client->event.event_id = MQTT_EVENT_ERROR; +#ifdef MQTT_SUPPORTED_FEATURE_TRANSPORT_ERR_REPORTING + client->event.error_handle = esp_transport_get_error_handle(client->transport); +#endif + esp_mqtt_dispatch_event_with_msgid(client); esp_mqtt_abort_connection(client); break; }