Skip to content

Possibility to change tx_payload_buffer_size #44

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Aug 18, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 11 additions & 5 deletions src/MqttClient.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,8 @@ MqttClient::MqttClient(Client* client) :
_willBuffer(NULL),
_willBufferIndex(0),
_willMessageIndex(0),
_willFlags(0x00)
_willFlags(0x00),
_tx_payload_buffer_size(TX_PAYLOAD_BUFFER_SIZE)
{
setTimeout(0);
}
Expand Down Expand Up @@ -282,7 +283,7 @@ int MqttClient::beginWill(const String& topic, unsigned short size, bool retain,

int MqttClient::beginWill(const char* topic, bool retain, uint8_t qos)
{
return beginWill(topic, TX_PAYLOAD_BUFFER_SIZE, retain, qos);
return beginWill(topic, _tx_payload_buffer_size, retain, qos);
}

int MqttClient::beginWill(const String& topic, bool retain, uint8_t qos)
Expand Down Expand Up @@ -653,12 +654,12 @@ size_t MqttClient::write(const uint8_t *buf, size_t size)
return clientWrite(buf, size);
}

if ((_txPayloadBufferIndex + size) >= TX_PAYLOAD_BUFFER_SIZE) {
size = (TX_PAYLOAD_BUFFER_SIZE - _txPayloadBufferIndex);
if ((_txPayloadBufferIndex + size) >= _tx_payload_buffer_size) {
size = (_tx_payload_buffer_size - _txPayloadBufferIndex);
}

if (_txPayloadBuffer == NULL) {
_txPayloadBuffer = (uint8_t*)malloc(TX_PAYLOAD_BUFFER_SIZE);
_txPayloadBuffer = (uint8_t*)malloc(_tx_payload_buffer_size);
}

memcpy(&_txPayloadBuffer[_txPayloadBufferIndex], buf, size);
Expand Down Expand Up @@ -793,6 +794,11 @@ void MqttClient::setConnectionTimeout(unsigned long timeout)
_connectionTimeout = timeout;
}

void MqttClient::setTxPayloadSize(unsigned short size)
{
_tx_payload_buffer_size = size;
}

int MqttClient::connectError() const
{
return _connectError;
Expand Down
2 changes: 2 additions & 0 deletions src/MqttClient.h
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,7 @@ class MqttClient : public Client {

void setKeepAliveInterval(unsigned long interval);
void setConnectionTimeout(unsigned long timeout);
void setTxPayloadSize(unsigned short size);

int connectError() const;
int subscribeQoS() const;
Expand Down Expand Up @@ -142,6 +143,7 @@ class MqttClient : public Client {

unsigned long _keepAliveInterval;
unsigned long _connectionTimeout;
unsigned short _tx_payload_buffer_size;

int _connectError;
bool _connected;
Expand Down