knolleary / pubsubclient

A client library for the Arduino Ethernet Shield that provides support for MQTT.
http://pubsubclient.knolleary.net/
MIT License
3.83k stars 1.47k forks source link

Changing MQTT_MAX_PACKET_SIZE has no effect #765

Open RobertHolscher opened 4 years ago

RobertHolscher commented 4 years ago

I am using the library in an ESP8622 and Arduino IDE. I am using a Mosquitto broker on RaspberryPI and Mosquitto client for reference. I had trouble with receiving all messages on my ESP. Small messages came through in the callback but bigger messages were ignored. The Raspberry client shows all. Then I incrementally made my MQTT json messages bigger. From 1 to 106 bytes message (without headers) the Callback routine was fired. Messages over the 106 were ignored. So it must be a buffer acceptance. Looking at solutions I have changed the param MQTT_MAX_PACKET_SIZE in the PubSubClient.h file and recompiled and uploaded my program to the esp. Unfortunately still the callback stopped receiving messages bigger than 106 bytes. What needs to be changed? My free heap is big enough to handle a larger buffer. Currently running 2.7 of your library

knolleary commented 4 years ago

Editing the value of MQTT_MAX_PACKET_SIZE in PubSubClient.h is the right way to modify the internal buffer size with 2.7.

Make sure you are editing the right file - maybe add a Serial.println(MQTT_MAX_PACKET_SIZE) so you can confirm that the change in value has been picked up.

With the 2.8 release, you can change the buffer size in your sketch using setBufferSize - https://pubsubclient.knolleary.net/api#setBufferSize

RobertHolscher commented 4 years ago

Thank you for your quick reply. I have put the Serial.println in my sketch and it shows 128 instead of the 1024 which meant indeed that there must be another file Pubsubclient.h on my computer somewhere. I finally found it and changed the buffer and it changed. Now I will continue testing. Thanks for the pointer and I really feel a bit stupid not to think of it myself ....

sebashb commented 4 years ago

This is somehow related to issue #764 I have tried serBufferSize with release 2.8 and it did not work. Could you give issue #764 a check @knolleary ?