mirror of
https://github.com/espressif/esp-mqtt.git
synced 2026-08-03 20:14:15 +02:00
mqtt_client: Manage disconnect packet
In the mqtt5 protocol the broker can disconnect the client with a disconnect packet. This packet contains a reason value that can be useful for certain applications in which it is important to know the reason of disconnection. While the client is connected is possible that a disconnect packet is reaceived by the broker to force a disconnection. Before this patch this approach causes a generic error on transport in case of disconnection from the broker. If the packet is managed before getting an error it is possible to save the reason code in the disconnect_return_code variable in the error_handle, and dispatch the disconnect event that can be managed by the application event loop, that now can know the reason of disconnection from the broker. Reset the variable in case of error. Signed-off-by: Flavia Caforio <flavia.caforio@amarulasolutions.com>
This commit is contained in:
@@ -18,7 +18,7 @@ typedef struct esp_mqtt_client *esp_mqtt5_client_handle_t;
|
||||
/**
|
||||
* MQTT5 protocol error reason code, more details refer to MQTT5 protocol document section 2.4
|
||||
*/
|
||||
enum mqtt5_error_reason_code {
|
||||
typedef enum mqtt5_error_reason_code_t {
|
||||
MQTT5_UNSPECIFIED_ERROR = 0x80,
|
||||
MQTT5_MALFORMED_PACKET = 0x81,
|
||||
MQTT5_PROTOCOL_ERROR = 0x82,
|
||||
@@ -59,7 +59,7 @@ enum mqtt5_error_reason_code {
|
||||
MQTT5_MAXIMUM_CONNECT_TIME = 0xA0,
|
||||
MQTT5_SUBSCRIBE_IDENTIFIER_NOT_SUPPORT = 0xA1,
|
||||
MQTT5_WILDCARD_SUBSCRIBE_NOT_SUPPORT = 0xA2,
|
||||
};
|
||||
} esp_mqtt5_error_reason_code_t;
|
||||
|
||||
/**
|
||||
* MQTT5 user property handle
|
||||
|
||||
@@ -182,6 +182,11 @@ typedef struct esp_mqtt_error_codes {
|
||||
esp_mqtt_connect_return_code_t
|
||||
connect_return_code; /*!< connection refused error code reported from
|
||||
*MQTT* broker on connection */
|
||||
#ifdef CONFIG_MQTT_PROTOCOL_5
|
||||
esp_mqtt5_error_reason_code_t
|
||||
disconnect_return_code; /*!< disconnection reason code reported from
|
||||
*MQTT* broker on disconnection */
|
||||
#endif
|
||||
/* tcp_transport extension */
|
||||
int esp_transport_sock_errno; /*!< errno from the underlying socket */
|
||||
|
||||
|
||||
Reference in New Issue
Block a user