Skip to content

Commit

Permalink
Added function to extend default size of tx_payload_buffer
Browse files Browse the repository at this point in the history
  • Loading branch information
Kacp3r3 committed Jul 28, 2020
1 parent e74cc1a commit 79f512f
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 5 deletions.
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

0 comments on commit 79f512f

Please sign in to comment.