Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Disconnect message not implemented #97

Closed
gregjesl opened this issue Feb 13, 2019 · 5 comments
Closed

Disconnect message not implemented #97

gregjesl opened this issue Feb 13, 2019 · 5 comments

Comments

@gregjesl
Copy link
Contributor

After reviewing and using the code, it does not appear that the MQTT client ever sends the DISCONNECT packet to the broker. Simply "dropping the line" can lead to undesirable behavior on the broker, especially when the client tries to reconnect.

@david-cermak
Copy link
Collaborator

Hi @gregjesl

Thank you for raising this issue!
Indeed the disconnect packet is not implemented. Will be fixed.

@gregjesl
Copy link
Contributor Author

@david-cermak Great, thank you.

After looking through the code, it appears the appropriate place to add the functionality would be here:

esp-mqtt/mqtt_client.c

Lines 776 to 782 in 99004f2

esp_err_t esp_mqtt_client_stop(esp_mqtt_client_handle_t client)
{
client->run = false;
xEventGroupWaitBits(client->status_bits, STOPPED_BIT, false, true, portMAX_DELAY);
client->state = MQTT_STATE_UNKNOWN;
return ESP_OK;
}

My suggestion would be:

esp_err_t esp_mqtt_client_stop(esp_mqtt_client_handle_t client)
{
    // Notify the broker we are disconnecting
    client->mqtt_state.outbound_message = mqtt_msg_disconnect(&client->mqtt_state.mqtt_connection);

    if (mqtt_write_data(client) != ESP_OK) {
        ESP_LOGE(TAG, "Error disconnecting");
        return ESP_FAIL;
    }

    client->run = false;
    xEventGroupWaitBits(client->status_bits, STOPPED_BIT, false, true, portMAX_DELAY);
    client->state = MQTT_STATE_UNKNOWN;
    return ESP_OK;
}

I'd submit a pull request but I never seem to have much luck with Git submodules.

@david-cermak
Copy link
Collaborator

@gregjesl Thanks for your suggestion!
Please feel free to submit a PR, but please select idf as target branch.

@gregjesl
Copy link
Contributor Author

@david-cermak I struggled with the rebase so I branched from idf and implemented the patch. The new pull request is #107

@david-cermak
Copy link
Collaborator

closed per caf5007

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants