In my testing with the MQTT library, I’ve noticed that messages greater than 223 bytes get truncated. I wrote the following program to demonstrate the problem.
The program sends three MQTT messages and subscribers receive the output shown below the code. I include the output that subscribers see when I send the 300-byte message from MQTTlens. This proves that the broker and the subscriber ends are working properly.
So, I believe this isolated the problem to the “publish” end of things, but I don’t know if it is a issue with the MQTT library or “more likely” how I am attempting to use it. Please help if you can.
#include "Particle.h"
#include "MQTT.h"
MQTT* mqtt;
char clientName[] = "testClient1";
byte brokerIP[] = {192,168,86,53};
char topic[] = "garage_door_state_refresh";
char m200bytes[] = "12345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890";
char m223bytes[] = "1234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123";
char m300bytes[] = "123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890";
void setup() {
mqtt = new MQTT(brokerIP, 1883, 15, callback);
mqtt->connect(clientName);
mqtt->publish(topic, m200bytes);
mqtt->publish(topic, m223bytes);
mqtt->publish(topic, m300bytes);
}
void loop() {
}
void callback(char* topic, byte* payload, unsigned int length) {
}
MQTT MESSAGES RECEIVED FROM THE ABOVE PROGRAM
Note: Subscriber received a trucated 300 byte message.
12345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890
1234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123
1234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123
300 BYTE MESSAGE RECEIVED FROM MQTT_LENS
Note: Subscriber received a complete 300 byte message
123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890