@@ -1914,6 +1914,14 @@ static esp_err_t send_disconnect_msg(esp_mqtt_client_handle_t client)
19141914}
19151915
19161916esp_err_t esp_mqtt_client_stop (esp_mqtt_client_handle_t client )
1917+ {
1918+ esp_err_t result = esp_mqtt_client_initiate_stop (client );
1919+ if (result == ESP_OK )
1920+ xEventGroupWaitBits (client -> status_bits , STOPPED_BIT , false, true, portMAX_DELAY );
1921+ return result ;
1922+ }
1923+
1924+ esp_err_t esp_mqtt_client_initiate_stop (esp_mqtt_client_handle_t client )
19171925{
19181926 if (!client ) {
19191927 ESP_LOGE (TAG , "Client was not initialized" );
@@ -1940,7 +1948,7 @@ esp_err_t esp_mqtt_client_stop(esp_mqtt_client_handle_t client)
19401948 client -> run = false;
19411949 client -> state = MQTT_STATE_DISCONNECTED ;
19421950 MQTT_API_UNLOCK (client );
1943- xEventGroupWaitBits ( client -> status_bits , STOPPED_BIT , false, true, portMAX_DELAY );
1951+
19441952 return ESP_OK ;
19451953 } else {
19461954 ESP_LOGW (TAG , "Client asked to stop, but was not started" );
@@ -1949,6 +1957,17 @@ esp_err_t esp_mqtt_client_stop(esp_mqtt_client_handle_t client)
19491957 }
19501958}
19511959
1960+ bool esp_mqtt_client_is_stopped (esp_mqtt_client_handle_t client )
1961+ {
1962+ if (!client ) {
1963+ ESP_LOGE (TAG , "Client was not initialized" );
1964+ return ESP_ERR_INVALID_ARG ;
1965+ }
1966+
1967+ EventBits_t bits = xEventGroupClearBits (client -> status_bits , 0 );
1968+ return bits & STOPPED_BIT ;
1969+ }
1970+
19521971static esp_err_t esp_mqtt_client_ping (esp_mqtt_client_handle_t client )
19531972{
19541973 mqtt_msg_pingreq (& client -> mqtt_state .connection );
0 commit comments