Skip to content
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

connectPacket: send a second length-byte if payload is larger than >127 Byte #189

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
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: 10 additions & 1 deletion Adafruit_MQTT.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -662,7 +662,16 @@ uint8_t Adafruit_MQTT::connectPacket(uint8_t *packet) {

len = p - packet;

packet[1] = len - 2; // don't include the 2 bytes of fixed header data
if (len > (127 + 2)) {
packet[1] = ((len - 2) % 128) + 0x80; // LSB
memmove(packet + 3, packet + 2,
len - 2); // create space for an additional length-byte
packet[2] = (len - 2) / 128; // MSB
len++;
} else {
packet[1] = len - 2; // don't include the 2 bytes of fixed header data
}

DEBUG_PRINTLN(F("MQTT connect packet:"));
DEBUG_PRINTBUFFER(buffer, len);
return len;
Expand Down