Add the parsing of DISCONNECT packet for MQTT 5 (IDFGH-14489) #295
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Description
In the MQTT 5 protocol the broker can disconnect the client with a DISCONNECT packet. This packet contains the reason code of the forced disconnection.
Before these patches the DISCONNECT packet was not parsed and it was not possible to know and check the disconnection reason by the broker at application level.
So now in mqtt_process_receive also the disconnect packets are processed, setting the disconnect_return_code variable in the error_handle structure (as per the connect_return_code) and sending the event to the application event loop.
Related
Testing
I tested it with a mqtt 5 server and 2 ESP32-S3-WROOM-1-N16R8V modules.
When the two modules were connected to the broker with same client ID, the first one was kicked out (as per specification). I wanted to have the reason code of the DISCONNECT packet so if it was 0x8E (MQTT5_SESSION_TAKEN_OVER), the first client is not continuing reconnecting in my application (it was creating a loop of connection and disconnection between the first and the second client).
I found this solutions, but I am open to suggestion! Thanks!
Checklist
Before submitting a Pull Request, please ensure the following: