File tree Expand file tree Collapse file tree 5 files changed +31
-2
lines changed Expand file tree Collapse file tree 5 files changed +31
-2
lines changed Original file line number Diff line number Diff line change @@ -18,7 +18,7 @@ typedef struct esp_mqtt_client *esp_mqtt5_client_handle_t;
1818/**
1919 * MQTT5 protocol error reason code, more details refer to MQTT5 protocol document section 2.4
2020 */
21- enum mqtt5_error_reason_code {
21+ typedef enum mqtt5_error_reason_code_t {
2222 MQTT5_UNSPECIFIED_ERROR = 0x80 ,
2323 MQTT5_MALFORMED_PACKET = 0x81 ,
2424 MQTT5_PROTOCOL_ERROR = 0x82 ,
@@ -59,7 +59,7 @@ enum mqtt5_error_reason_code {
5959 MQTT5_MAXIMUM_CONNECT_TIME = 0xA0 ,
6060 MQTT5_SUBSCRIBE_IDENTIFIER_NOT_SUPPORT = 0xA1 ,
6161 MQTT5_WILDCARD_SUBSCRIBE_NOT_SUPPORT = 0xA2 ,
62- };
62+ } esp_mqtt5_error_reason_code_t ;
6363
6464/**
6565 * MQTT5 user property handle
Original file line number Diff line number Diff line change @@ -182,6 +182,11 @@ typedef struct esp_mqtt_error_codes {
182182 esp_mqtt_connect_return_code_t
183183 connect_return_code ; /*!< connection refused error code reported from
184184 *MQTT* broker on connection */
185+ #ifdef CONFIG_MQTT_PROTOCOL_5
186+ esp_mqtt5_error_reason_code_t
187+ disconnect_return_code ; /*!< disconnection reason code reported from
188+ *MQTT* broker on disconnection */
189+ #endif
185190 /* tcp_transport extension */
186191 int esp_transport_sock_errno ; /*!< errno from the underlying socket */
187192
Original file line number Diff line number Diff line change @@ -42,6 +42,7 @@ void esp_mqtt5_parse_pubcomp(esp_mqtt5_client_handle_t client);
4242void esp_mqtt5_parse_puback (esp_mqtt5_client_handle_t client );
4343void esp_mqtt5_parse_unsuback (esp_mqtt5_client_handle_t client );
4444void esp_mqtt5_parse_suback (esp_mqtt5_client_handle_t client );
45+ void esp_mqtt5_parse_disconnect (esp_mqtt5_client_handle_t client , int * disconnect_rsp_code );
4546esp_err_t esp_mqtt5_parse_connack (esp_mqtt5_client_handle_t client , int * connect_rsp_code );
4647void esp_mqtt5_client_destory (esp_mqtt5_client_handle_t client );
4748esp_err_t esp_mqtt5_client_publish_check (esp_mqtt5_client_handle_t client , int qos , int retain );
Original file line number Diff line number Diff line change @@ -76,6 +76,14 @@ void esp_mqtt5_parse_suback(esp_mqtt5_client_handle_t client)
7676 }
7777}
7878
79+ void esp_mqtt5_parse_disconnect (esp_mqtt5_client_handle_t client , int * disconnect_rsp_code )
80+ {
81+ if (client -> mqtt_state .connection .information .protocol_ver == MQTT_PROTOCOL_V_5 ) {
82+ * disconnect_rsp_code = mqtt5_msg_get_reason_code (client -> mqtt_state .in_buffer , client -> mqtt_state .in_buffer_read_len );
83+ ESP_LOGD (TAG , "MQTT_MSG_TYPE_DISCONNECT return code is %d" , * disconnect_rsp_code );
84+ }
85+ }
86+
7987esp_err_t esp_mqtt5_parse_connack (esp_mqtt5_client_handle_t client , int * connect_rsp_code )
8088{
8189 size_t len = client -> mqtt_state .in_buffer_read_len ;
Original file line number Diff line number Diff line change @@ -1511,6 +1511,18 @@ static esp_err_t mqtt_process_receive(esp_mqtt_client_handle_t client)
15111511 */
15121512 client -> keepalive_tick = platform_tick_get_ms ();
15131513 break ;
1514+ case MQTT_MSG_TYPE_DISCONNECT :
1515+ ESP_LOGD (TAG , "MQTT_MSG_TYPE_DISCONNECT" );
1516+ #ifdef MQTT_PROTOCOL_5
1517+ if (client -> mqtt_state .connection .information .protocol_ver == MQTT_PROTOCOL_V_5 ) {
1518+ int disconnect_rsp_code ;
1519+ esp_mqtt5_parse_disconnect (client , & disconnect_rsp_code );
1520+ client -> event .event_id = MQTT_EVENT_DISCONNECTED ;
1521+ client -> event .error_handle -> disconnect_return_code = disconnect_rsp_code ;
1522+ esp_mqtt_dispatch_event_with_msgid (client );
1523+ }
1524+ #endif
1525+ break ;
15141526 }
15151527
15161528 client -> mqtt_state .in_buffer_read_len = 0 ;
@@ -2274,6 +2286,9 @@ static void esp_mqtt_client_dispatch_transport_error(esp_mqtt_client_handle_t cl
22742286 client -> event .event_id = MQTT_EVENT_ERROR ;
22752287 client -> event .error_handle -> error_type = MQTT_ERROR_TYPE_TCP_TRANSPORT ;
22762288 client -> event .error_handle -> connect_return_code = 0 ;
2289+ #ifdef MQTT_PROTOCOL_5
2290+ client -> event .error_handle -> disconnect_return_code = 0 ;
2291+ #endif
22772292#ifdef MQTT_SUPPORTED_FEATURE_TRANSPORT_ERR_REPORTING
22782293 client -> event .error_handle -> esp_tls_last_esp_err = esp_tls_get_and_clear_last_error (esp_transport_get_error_handle (client -> transport ),
22792294 & client -> event .error_handle -> esp_tls_stack_err ,
You can’t perform that action at this time.
0 commit comments