user48730: I'm trying to write code involving MQTT messages to operate an ESP8266 relay ( a Sonoff device ), using PubSub library.
For some, unknown for me, reason - messages larger than 99 chars are not sent. It this a known limitation ? can it be changed ?
void pub_msg(char *inmsg){
        char tmpmsg[255];
        // sprintf(tmpmsg,"[Cl:oc:k] [%s] %s",deviceTopic, inmsg);   ---> wish to add a time stamp
        sprintf(tmpmsg,"[][%s] %s",deviceTopic, inmsg);  ---> using this line just to find that 99 chars sent OK
        Serial.print("published MSG:");
        Serial.println(tmpmsg);
        Serial.print("Total chars:");
        Serial.println(strlen(tmpmsg));
        client.publish(msgTopic, tmpmsg);

}


user4143: The maximum MQTT packet size in PubSubClient is 128 bytes. After all the MQTT header information that leaves only 99 bytes for a message.
You can change it by editing the PubSubClient.h file:
#ifndef MQTT_MAX_PACKET_SIZE
#define MQTT_MAX_PACKET_SIZE 128
#endif

As it says in the PubSubClient README.md:


The maximum message size, including header, is 128 bytes by default. This is configurable via MQTT_MAX_PACKET_SIZE in PubSubClient.h.



48730: <p>I'm trying to write code involving MQTT messages to operate an ESP8266 relay ( a Sonoff device ), using <code>PubSub</code> library.</p>

<p>For some, unknown for me, reason - messages larger than 99 chars are not sent. It this a known limitation ? can it be changed ?</p>

<pre><code>void pub_msg(char *inmsg){
        char tmpmsg[255];
        // sprintf(tmpmsg,"[Cl:oc:k] [%s] %s",deviceTopic, inmsg);   ---&gt; wish to add a time stamp
        sprintf(tmpmsg,"[][%s] %s",deviceTopic, inmsg);  ---&gt; using this line just to find that 99 chars sent OK
        Serial.print("published MSG:");
        Serial.println(tmpmsg);
        Serial.print("Total chars:");
        Serial.println(strlen(tmpmsg));
        client.publish(msgTopic, tmpmsg);

}
</code></pre>
 4143: <p>The maximum MQTT packet size in PubSubClient is 128 bytes. After all the MQTT header information that leaves only 99 bytes for a message.</p>

<p>You can change it by editing the <code>PubSubClient.h</code> file:</p>

<pre><code>#ifndef MQTT_MAX_PACKET_SIZE
#define MQTT_MAX_PACKET_SIZE 128
#endif
</code></pre>

<p>As it says in the PubSubClient <a href="https://github.com/knolleary/pubsubclient/blob/master/README.md" rel="nofollow noreferrer">README.md</a>:</p>

<blockquote>
  <ul>
  <li>The maximum message size, including header, is <strong>128 bytes</strong> by default. This is configurable via <code>MQTT_MAX_PACKET_SIZE</code> in <code>PubSubClient.h</code>.</li>
  </ul>
</blockquote>
