@@ -1831,6 +1831,14 @@ static esp_err_t send_disconnect_msg(esp_mqtt_client_handle_t client)
18311831}
18321832
18331833esp_err_t esp_mqtt_client_stop (esp_mqtt_client_handle_t client )
1834+ {
1835+ esp_err_t result = esp_mqtt_client_initiate_stop (client );
1836+ if (result == ESP_OK )
1837+ xEventGroupWaitBits (client -> status_bits , STOPPED_BIT , false, true, portMAX_DELAY );
1838+ return result ;
1839+ }
1840+
1841+ esp_err_t esp_mqtt_client_initiate_stop (esp_mqtt_client_handle_t client )
18341842{
18351843 if (!client ) {
18361844 ESP_LOGE (TAG , "Client was not initialized" );
@@ -1857,7 +1865,7 @@ esp_err_t esp_mqtt_client_stop(esp_mqtt_client_handle_t client)
18571865 client -> run = false;
18581866 client -> state = MQTT_STATE_DISCONNECTED ;
18591867 MQTT_API_UNLOCK (client );
1860- xEventGroupWaitBits ( client -> status_bits , STOPPED_BIT , false, true, portMAX_DELAY );
1868+
18611869 return ESP_OK ;
18621870 } else {
18631871 ESP_LOGW (TAG , "Client asked to stop, but was not started" );
@@ -1866,6 +1874,17 @@ esp_err_t esp_mqtt_client_stop(esp_mqtt_client_handle_t client)
18661874 }
18671875}
18681876
1877+ bool esp_mqtt_client_is_stopped (esp_mqtt_client_handle_t client )
1878+ {
1879+ if (!client ) {
1880+ ESP_LOGE (TAG , "Client was not initialized" );
1881+ return ESP_ERR_INVALID_ARG ;
1882+ }
1883+
1884+ EventBits_t bits = xEventGroupClearBits (client -> status_bits , 0 );
1885+ return bits & STOPPED_BIT ;
1886+ }
1887+
18691888static esp_err_t esp_mqtt_client_ping (esp_mqtt_client_handle_t client )
18701889{
18711890 mqtt_msg_pingreq (& client -> mqtt_state .connection );
0 commit comments