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

Add function to disconnect from MQTT broker #272

Closed
crespum opened this issue Jun 30, 2023 · 6 comments
Closed

Add function to disconnect from MQTT broker #272

crespum opened this issue Jun 30, 2023 · 6 comments

Comments

@crespum
Copy link

crespum commented Jun 30, 2023

Rust implementation can't disconnect from a broker in a clean way.

@ivmarkov
Copy link
Collaborator

Please elaborate why the existing MQTT client destruction logic is not good enough.

@crespum
Copy link
Author

crespum commented Jun 30, 2023

In my application I publish some data and send the ESP32 to deep sleep mode right after that. If I want to do it right, I should disconnect from MQTT to make sure I can connect back after waking up.

As far as I've seen in the code, there's only a call to esp_mqtt_client_destroy() (1, 2), which does not mean there's a clean disconnection.

@ivmarkov
Copy link
Collaborator

Deep sleep means that your memory and the state of the CPU is completely gone. Once it awakes from deep sleep, it will essentially start over from the beginning of your main function. So if you want to leave your app in clean state, you should actually drop your mqtt client and it's connection (if you are using one). Ditto for the wifi, and for the http server (if you are using one).

@ivmarkov
Copy link
Collaborator

Also: are you sure that the call to destroy is not enough for a clean disconnect, and why?

@crespum
Copy link
Author

crespum commented Jun 30, 2023

Correct me if I'm wrong, but even if I drop the MQTT client object, forcing a destruction, the server side might not be aware of this event (depending on the implementation, until a certain timeout).

For instance, to avoid that issue, there's a method for WiFi disconnection exposed.

@ivmarkov
Copy link
Collaborator

ivmarkov commented Jul 1, 2023

Since you are looking at the C side of things, here's the chain of calls:
MqttClient::drop -> esp_mqtt_client_destroy -> esp_mqtt_client_stop -> send_disconnect_msg

Therefore, I'm wondering - are you experiencing an actual problem, or are you just looking at the C code and trying to figure out whether something would break if you don't do anything before going to deep sleep (or better yet - just drop the mqtt client, as I suggested - but even this might not be necessary)?

Feel free to reopen with additional details in case you experience an actual issue.

@ivmarkov ivmarkov closed this as completed Jul 1, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Archived in project
Development

No branches or pull requests

2 participants