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.
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.
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.