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 ?
1 Answer 1
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.