Skip to content

Allowing for larger MQTT messages #100

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

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
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
11 changes: 7 additions & 4 deletions Adafruit_MQTT_Client.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -76,16 +76,19 @@ 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 : ");
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();
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