adafruit / Adafruit_MQTT_Library

Arduino library for MQTT support
MIT License
573 stars 291 forks source link

Fixed length calculation when payload exceeds 128bytes #196

Closed xdylanm closed 3 years ago

xdylanm commented 3 years ago

Further testing of my recent patch uncovered a new issue: the packet length calculation is off by +1 when the payload size is greater than 128 bytes. This length is stored in the MQTT packet header, so the broker is expecting a packet that is one byte longer than what gets sent (and times out or otherwise fails). The length stored in the MQTT packet header is the "remaining length" (see e.g. http://www.steves-internet-guide.com/mqtt-protocol-messages-overview/) and shouldn't include itself in the calculation.

axello commented 3 years ago

I encountered the same bug. The publish command kept adding a '0' to the end of my 175 byte package. Would be nice if this patch could be included. This patch fixed the bug for me.