The answer isn't completely straightforward, unfortunately.
I'll assume you're referring to the length of the payload, which is the component of an MQTT application message that is generally used to encode data.
The anatomy of an MQTT consists of a fixed size header, a variable length header, and a payload. The fixed size header is used to indicate what kind of message is being sent (despite the name, it is not always the same size). The variable length header is used to convey information specific to each message. Section 2.3 of the MQTT 5 standard refers to the payload as the "final part of the packet" - so it's everything after the variable length header.
The size of the message is indicated in the fixed size header. This field can reach up to 268,435,455 (see section 1.5.5 and 2.1.1). However, this is not the same as the maximum size of the payload, because it also includes the variable length header.
Before I try to answer the question more specifically, I'll assume that you're talking about the maximum size of a payload in an MQTT "PUBLISH" message, which is what you use when you're publishing telemetry and what not.
For a PUBLISH packet, the variable length header consists of:
- topic name
- packet identifier
- properties
The topic name, although theoretically can take up to 2 + [0:65535]
, is usually pretty short. The packet identifier is 2 bytes long, always. The properties table can take up a wide range of sizes, so I'm not going to try and write that out as an expression.
See section 3.3.2 for this info.
So the maximum size of the payload for a MQTT publish message would be 268,435,455 - (2 + 1) - 2 - 1
, assuming the topic length is one character and there are no properties associated with the message.
Disclaimer: I have not tested this, and there's likely a soft limit defined by the broker you're using.
The sections I am referencing are from the version 5 spec: http://docs.oasis-open.org/mqtt/mqtt/v5.0/mqtt-v5.0.html