mirror of
https://github.com/espressif/esp-mqtt.git
synced 2025-08-02 12:15:11 +02:00
Merge branch 'bugfix/set_error_on_subscribe_failure' into 'master'
Adds error code to MQTT_EVENT_SUBSCRIBED in case of failure See merge request espressif/esp-mqtt!143
This commit is contained in:
@@ -46,12 +46,12 @@ typedef enum esp_mqtt_event_id_t {
|
|||||||
MQTT_EVENT_DISCONNECTED, /*!< disconnected event */
|
MQTT_EVENT_DISCONNECTED, /*!< disconnected event */
|
||||||
MQTT_EVENT_SUBSCRIBED, /*!< subscribed event, additional context:
|
MQTT_EVENT_SUBSCRIBED, /*!< subscribed event, additional context:
|
||||||
- msg_id message id
|
- msg_id message id
|
||||||
- data pointer to the received
|
- error_handle `error_type` in case subscribing failed
|
||||||
data
|
- data pointer to broker response, check for errors.
|
||||||
- data_len length of the data for this
|
- data_len length of the data for this
|
||||||
event
|
event
|
||||||
*/
|
*/
|
||||||
MQTT_EVENT_UNSUBSCRIBED, /*!< unsubscribed event */
|
MQTT_EVENT_UNSUBSCRIBED, /*!< unsubscribed event, additional context: msg_id */
|
||||||
MQTT_EVENT_PUBLISHED, /*!< published event, additional context: msg_id */
|
MQTT_EVENT_PUBLISHED, /*!< published event, additional context: msg_id */
|
||||||
MQTT_EVENT_DATA, /*!< data event, additional context:
|
MQTT_EVENT_DATA, /*!< data event, additional context:
|
||||||
- msg_id message id
|
- msg_id message id
|
||||||
@@ -112,6 +112,7 @@ typedef enum esp_mqtt_error_type_t {
|
|||||||
MQTT_ERROR_TYPE_NONE = 0,
|
MQTT_ERROR_TYPE_NONE = 0,
|
||||||
MQTT_ERROR_TYPE_TCP_TRANSPORT,
|
MQTT_ERROR_TYPE_TCP_TRANSPORT,
|
||||||
MQTT_ERROR_TYPE_CONNECTION_REFUSED,
|
MQTT_ERROR_TYPE_CONNECTION_REFUSED,
|
||||||
|
MQTT_ERROR_TYPE_SUBSCRIBE_FAILED
|
||||||
} esp_mqtt_error_type_t;
|
} esp_mqtt_error_type_t;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@@ -1,5 +1,7 @@
|
|||||||
#include "esp_log.h"
|
#include "mqtt_client.h"
|
||||||
#include "mqtt_client_priv.h"
|
#include "mqtt_client_priv.h"
|
||||||
|
#include "esp_log.h"
|
||||||
|
#include <stdint.h>
|
||||||
|
|
||||||
_Static_assert(sizeof(uint64_t) == sizeof(outbox_tick_t), "mqtt-client tick type size different from outbox tick type");
|
_Static_assert(sizeof(uint64_t) == sizeof(outbox_tick_t), "mqtt-client tick type size different from outbox tick type");
|
||||||
#ifdef ESP_EVENT_ANY_ID
|
#ifdef ESP_EVENT_ANY_ID
|
||||||
@@ -588,7 +590,8 @@ void esp_mqtt_destroy_config(esp_mqtt_client_handle_t client)
|
|||||||
client->config = NULL;
|
client->config = NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
static inline bool has_timed_out(uint64_t last_tick, uint64_t timeout) {
|
static inline bool has_timed_out(uint64_t last_tick, uint64_t timeout)
|
||||||
|
{
|
||||||
uint64_t next = last_tick + timeout;
|
uint64_t next = last_tick + timeout;
|
||||||
return (int64_t)(next - platform_tick_get_ms()) <= 0;
|
return (int64_t)(next - platform_tick_get_ms()) <= 0;
|
||||||
}
|
}
|
||||||
@@ -1079,7 +1082,15 @@ static esp_err_t deliver_suback(esp_mqtt_client_handle_t client)
|
|||||||
ESP_LOGE(TAG, "Failed to acquire suback data");
|
ESP_LOGE(TAG, "Failed to acquire suback data");
|
||||||
return ESP_FAIL;
|
return ESP_FAIL;
|
||||||
}
|
}
|
||||||
|
client->event.error_handle->esp_tls_stack_err = 0;
|
||||||
|
client->event.error_handle->esp_tls_last_esp_err = 0;
|
||||||
|
client->event.error_handle->esp_tls_cert_verify_flags = 0;
|
||||||
|
client->event.error_handle->error_type = MQTT_ERROR_TYPE_NONE;
|
||||||
|
client->event.error_handle->connect_return_code = MQTT_CONNECTION_ACCEPTED;
|
||||||
// post data event
|
// post data event
|
||||||
|
if ((uint8_t)*msg_data >= 0x80) {
|
||||||
|
client->event.error_handle->error_type = MQTT_ERROR_TYPE_SUBSCRIBE_FAILED;
|
||||||
|
}
|
||||||
client->event.data_len = msg_data_len;
|
client->event.data_len = msg_data_len;
|
||||||
client->event.total_data_len = msg_data_len;
|
client->event.total_data_len = msg_data_len;
|
||||||
client->event.event_id = MQTT_EVENT_SUBSCRIBED;
|
client->event.event_id = MQTT_EVENT_SUBSCRIBED;
|
||||||
|
Reference in New Issue
Block a user