arduino-libraries / ArduinoMqttClient

ArduinoMqttClient Library for Arduino
GNU Lesser General Public License v2.1
187 stars 73 forks source link

make TX_PAYLOAD_BUFFER_SIZE overridable #10

Closed ravelab closed 3 years ago

ravelab commented 5 years ago

Hi, is it possible to make TX_PAYLOAD_BUFFER_SIZE overridable, as an instance variable, or compile build option? I was surprised to find that it is only 256 bytes. Thanks

sandeepmistry commented 5 years ago

Hi @ravelab,

I'm ok with merging the changes you proposed in #11.

One note, before I do, if you happen to know the size of your message before hand you can pass it into beginMessage(...): https://github.com/arduino-libraries/ArduinoMqttClient/blob/master/examples/WiFiAdvancedCallback/WiFiAdvancedCallback.ino#L147-L149

Would this cover your use case?

ravelab commented 5 years ago

Hi, @sandeepmistry

It does cover my use case, I missed that beginMessage(...) option. It's up to you if you want to make TX_PAYLOAD_BUFFER_SIZE overridable.

Thanks.

sandeepmistry commented 5 years ago

Hi @ravelab,

Great! I'm going to close your pull request for now, if someone requests the feature in the future we can re-open the your pull request and merge.

sakurai-youhei commented 4 years ago

Hi @sandeepmistry and @ravelab, Time has come. :)

Could you re-open this issue, merge the PR #11 and release it as next version, please?

I hit one issue when uploading JSON document of ArduinoJson.

#include <ArduinoJson.h>

DynamicJsonDocument doc(256);
for (int i = 0; i < 100; i++) {
  doc["I"]["am"]["creating"]["big"]["JSON"]["document"][String(i)] = "which size can't be estimated beforehand.";
}
mqtt.beginMessage("topic");
serializeJson(doc, mqtt);
mqtt.endMessage();

See also: How to use ArduinoJson with ArduinoMqttClient?

Thank you.

OldGreyCells commented 3 years ago

Hi @ravelab,

Great! I'm going to close your pull request for now, if someone requests the feature in the future we can re-open the your pull request and merge.

It would be much appreciated if you could reopen this. The payload for auto discovery in Home Assistant is often > 256! If possible via a setPayloadBufferSize() method or a bufferSize arg in beginMessage() rather than via a #define, so it can be set per message (payload for most messages is small, only occasionally does the buffer need to be enlarged). Many thanks

tbaust commented 3 years ago

Hi @ravelab,

Great! I'm going to close your pull request for now, if someone requests the feature in the future we can re-open the your pull request and merge.

please reopen this - I had the issue that (depending on the floating point conversion) sporadic the MQTT messages are invalid. This is really hard to find if it occurs roughly once per day...

Thank you.

aentinger commented 3 years ago

Fixed by #44.