Sending commands with larger payloads


If you’re using a Losant Builder Kit or the losant-sdk-arduino on another board, you’ll likely hit the default mqtt packet size limit defined in the underlying pubsubclient library. Unfortunately the packet is blocked before reaching any of your code, so it’s hard to debug. It simply looks like the command was never received. For example:

{ "foo" : "bar" } works, whereas { "somethingLarger" : "with a longer value" } doesn’t work. This is because the default packet size is 128, which provides enough room for the command meta info and a small payload. Once you increase the payload, the packets will start being dropped. Fortunately this is easy to fix:

  1. Open the pubsubclient.h file from the Arduino libraries folder. On a Mac, this will be located at ~/Documents/Arduino/libraries/pubsubclient/src/PubSubClient.h
  2. Edit the MQTT_MAX_PACKET_SIZE to something larger. Increasing it to 256 seems to work pretty well.
  3. Recompile and reupload the firmware to the device.

If you plan on sending even larger payloads, you can increase the value as needed. Just remember many boards don’t have a ton of memory, and the entire payload will have to fit.

No data/payload with connected device
String "Command received: " not shown on the serial monitor output
Json payload strange behaivour [Solved]
[Solved] Cant send command with a payload
Unable to extract payload of type string shipped to Arduino via Device Command
Payload length, formatting label in indicator block
No data/payload with connected device

Works perfectly - I compiled the example code for an ESP8266 and found the maximum command size was 18 characters. I made this change and everything seems to work as expected.