0

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

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.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.