arduino-mqtt
arduino-mqtt copied to clipboard
Set separate read and write buffer sizes
It isn't clear from the README.md
, but setting a larger buffer size. eg, MQTTClient client(2048)
creates TWO buffers: a read buffer of 2049 bytes and a separate write buffer of 2048 bytes.
It would be worth updating the documentation to mention this, and also to provide an optional 2nd argument for setting different buffer sizes. eg,
MQTTClient::MQTTClient(int readbufSize, int writebufSize) {
// allocate buffers
this->readbufSize = (size_t)readbufSize;
this->writebufSize = (size_t)writebufSize;
this->readBuf = (uint8_t *)malloc((size_t)readbufSize + 1);
this->writeBuf = (uint8_t *)malloc((size_t)writebufSize);
}
MQTTClient::MQTTClient(int bufSize) {
this(bufSize, bufSize);
}
...
void MQTTClient::begin(Client &_client) {
...
lwmqtt_init(&this->client, this->writeBuf, this->writebufSize, this->readBuf, this->readbufSize);
A typical use case would be IoT devices that publish large packets of data but don't subscribe to anything, or only ever receive small packets. For large buffers this would give a useful memory saving.
Agree on this, i'm trying to send a large base64 image from PSRAM to the cloud, and my device subscribe nothing. So I need maximum memory buffer to send not to receive.
This has been added in e7c5bb0. Will be available with the next release (2.6).