user48730: I'm using an ESP32, and I want to rule out a probable MQTT error. In PubSubClient , MQTT_MAX_PACKET_SIZE is set to 256. Is 256 the size for message only ? if not, what is left for message only ?

user4143: It is the maximum size of an entire packet.  In publish() this check is done:
if (MQTT_MAX_PACKET_SIZE < MQTT_MAX_HEADER_SIZE + 2+strlen(topic) + plength) {

So the maximum length of a message payload will be
MQTT_MAX_PACKET_SIZE - MQTT_MAX_HEADER_SIZE - 2 - strlen(topic)

MQTT_MAX_HEADER_SIZE is defined as 5, so if you have, for example, a 20 character topic you would have 256 - 5 - 2 - 20 = 229 bytes left for your payload.

48730: <p>I'm using an ESP32, and I want to rule out a probable MQTT error. In <code>PubSubClient</code> , <code>MQTT_MAX_PACKET_SIZE</code> is set to 256. Is 256 the size for message only ? if not, what is left for message only ?</p>
 4143: <p>It is the maximum size of an entire packet.  In <code>publish()</code> this check is done:</p>
<pre><code>if (MQTT_MAX_PACKET_SIZE &lt; MQTT_MAX_HEADER_SIZE + 2+strlen(topic) + plength) {
</code></pre>
<p>So the maximum length of a message payload will be</p>
<pre><code>MQTT_MAX_PACKET_SIZE - MQTT_MAX_HEADER_SIZE - 2 - strlen(topic)
</code></pre>
<p><code>MQTT_MAX_HEADER_SIZE</code> is defined as 5, so if you have, for example, a 20 character topic you would have <code>256 - 5 - 2 - 20 = 229</code> bytes left for your payload.</p>
