0

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);
}
asked Sep 16, 2018 at 17:22

1 Answer 1

2

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.
answered Sep 16, 2018 at 18:16
8
  • Can you please refer to its location ? Commented Sep 16, 2018 at 18:59
  • The location of the file, or the location within the file? Commented Sep 16, 2018 at 18:59
  • sorry- location of the file Commented Sep 16, 2018 at 19:03
  • It's wherever you installed it to. Commented Sep 16, 2018 at 19:03
  • Is it part of pubsub library ? Commented Sep 16, 2018 at 19:04

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.