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.
With this PR I'm adding a queue for the MQTT messages, so that when a message is received it's added in a queue during the callback. Then the main loop picks up the messages and processes them asyncronously, but in order of arrival.
This avoids the watch dog timer to restart the ESP, which was the cause of occasional restarts when the messages were taking a while to process.
Then I'm adding an acknowledgment MQTT message to be sent after processing the incoming messages. This allows the other party to throttle their calls and avoid going over the available memory. In case we are approaching the end of memory we drop the message and log it.
With this approach and the throttling on the other end I've stopped encountering the random restarts or the messages not received properly, it seems pretty robust now, but a bit more testing would be good!