Skip to content

Commit

Permalink
MQTT Client: Added disconnect message on client stop
Browse files Browse the repository at this point in the history
Closes #97 and closes espressif/esp-idf#3215
  • Loading branch information
gregjesl committed Mar 27, 2019
1 parent 57d2774 commit caf5007
Showing 1 changed file with 8 additions and 0 deletions.
8 changes: 8 additions & 0 deletions mqtt_client.c
Original file line number Diff line number Diff line change
Expand Up @@ -958,6 +958,14 @@ esp_err_t esp_mqtt_client_reconnect(esp_mqtt_client_handle_t client)
esp_err_t esp_mqtt_client_stop(esp_mqtt_client_handle_t client)
{
if (client->run) {
// Notify the broker we are disconnecting
MQTT_API_LOCK_FROM_OTHER_TASK(client);
client->mqtt_state.outbound_message = mqtt_msg_disconnect(&client->mqtt_state.mqtt_connection);
if (mqtt_write_data(client) != ESP_OK) {
ESP_LOGE(TAG, "Error sending disconnect message");
}
MQTT_API_UNLOCK_FROM_OTHER_TASK(client);

client->run = false;
xEventGroupWaitBits(client->status_bits, STOPPED_BIT, false, true, portMAX_DELAY);
client->state = MQTT_STATE_UNKNOWN;
Expand Down

0 comments on commit caf5007

Please sign in to comment.