knolleary / pubsubclient

A client library for the Arduino Ethernet Shield that provides support for MQTT.
http://pubsubclient.knolleary.net/
MIT License
3.78k stars 1.46k forks source link

Added a way to inform the user about possible discarded packets #981

Closed MathewHDYT closed 1 year ago

MathewHDYT commented 1 year ago

When a packet is bigger than the set bufferSize, the PubSubClient simply discards them and ignores the possible error, meaning a user is never informed that a packet was dropped.

This can cause confusion tough if a response or message is expected, but nothing is ever received.

Therefore I added a special topic that informs the user that their packet is dropped and how much bigger it was then expected. For that I simply used the callback method as well and called it without any data but with a topic explaining the possible issue.

Would be highly appreciated if this could be merged, so it is easier to detect future issues, when making a mistake and not increasing the size of the PubSubClient according to the needs of the system.

The changes have been tested for an ESP32 and both compile and work like expected.

@knolleary Would be nice if this could be merged or another way to inform the user about discarded packets could be found. Perhaps setting an error that could be gotten over a method could work as well.