Sending commands with larger payloads


#1

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.


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

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.


#3

This post was very helpful - however, as a newbie I am at a loss about what to do with
“Recompile and reupload the firmware to the device.”

Any hint on where to start looking how to do this on a Mac? :slight_smile:

Thanks!


#4

OK, I found out. Get the PubSubClient separately from GitHub, then unzip, change the value and rezip. Install this library from the Arduino software (Sketch/Include Library/Add .ZIP Library)