Skip to content
Open
Show file tree
Hide file tree
Changes from 1 commit
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
Next Next commit
Allowing for larger MQTT messages
  • Loading branch information
Tobias Looker committed Nov 18, 2017
commit 17eefdf8add5d8a82bc495c831b295255a304ae2
12 changes: 8 additions & 4 deletions Adafruit_MQTT_Client.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -76,16 +76,20 @@ uint16_t Adafruit_MQTT_Client::readPacket(uint8_t *buffer, uint16_t maxlen,

bool Adafruit_MQTT_Client::sendPacket(uint8_t *buffer, uint16_t len) {
uint16_t ret = 0;

uint16_t bufferOffset = 0;
//Serial.print("Buffer recieved : "); DebugPrinter::println(len);
while (len > 0) {
if (client->connected()) {
// send 250 bytes at most at a time, can adjust this later based on Client

uint16_t sendlen = min(len, 250);
//Serial.print("Sending: "); Serial.println(sendlen);
ret = client->write(buffer, sendlen);
uint16_t sendlen = min(len, MAX_SINGLE_PACKET_SIZE);

ret = client->write(buffer + bufferOffset, sendlen);
client->flush();
//DebugPrinter::println("Sent");
DEBUG_PRINT(F("Client sendPacket returned: ")); DEBUG_PRINTLN(ret);
len -= ret;
bufferOffset += ret;

if (ret != sendlen) {
DEBUG_PRINTLN("Failed to send packet.");
Expand Down
1 change: 1 addition & 0 deletions Adafruit_MQTT_Client.h
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@

// How long to delay waiting for new data to be available in readPacket.
#define MQTT_CLIENT_READINTERVAL_MS 10
#define MAX_SINGLE_PACKET_SIZE 1200


// MQTT client implementation for a generic Arduino Client interface. Can work
Expand Down