Problem with number of json key value pairs in mqtt

Im unable to send more than 15 key-value pairs (data attributes) through a device at a time. is there any limitation to the number of json pairs we can send simultaneously? The total size of the message is approximately 1 kb. other time-related restrictions are taken care of.
please help…

Hi @Abhinav_Kumar !

Each device can have up to 256 device attributes, and an incoming message can be up to 256KB in size. Based on your description, your incoming message should be well below these limits.

Are you seeing an error in your device communication log when this message comes through? Alternatively, can you share the template of this message?

Code snippet to send data
where I’m sending 21 attributes but only receiving 15 of them…

StaticJsonDocument< 1000> jsonBuffer;
  JsonObject root =<JsonObject>();
  // root["temp"] = temperature;
  root["temp"] = 22.8;
    root["TDS"] = 33.3;
    root["pH"] = 44.4;
    root["EC"] = 55.5;
    root["ORP"] = 66.6;
    root["DO"] = 77.7;
    root["turbidity"] = 88.8;

    root["methane"] = 12.9;
    root["pm10"] = 32.4;
    root["pm1"] = 23.5;
    root["pm2_5"] = 88.4;
    root["geiger"] = 876.44;
    root["ethanol"] = 26.23;
    root["methane2"] =98.53;
    root["hydrogen"] = 57.84;
    root["ammonia"] = 85.245;
    root["co"] = 56.74;
    root["no2"] = 68.24;
    root["aqi"] = 83.64;
    root["tvoc"] = 63.84;
    root["co2"] = 28.07;

  // Send the state to Losant.

Are you using the Losant Arduino MQTT client library? If so, it looks like you may need to increase the MQTT packet size limit. Here’s a post that explains this in greater detail:

Please let me know if this fixes the issue!

looks like the default size is already set to 256.
still not working.

as soon as I increase the number of attributes to more than 14, the device connects to losant and then gets disconnected immediately.

I tried changing the size to 600. now the device remains connected but still not getting more than 15 attributes.

It’s interesting that the last 6 attributes you have listed (ammonia and onwards) are the ones getting dropped. What happens if you rearrange the order of the attributes?

One other thing to try - change this line of the local copy of our Arduino library. On Windows, this will be located at My Documents/Arduino/libraries/losant-mqtt-arduino-master/src/internal/LosantDevice.cpp:90:

StaticJsonDocument<256> doc;

Change <256> to something larger, like <1024>.

Please let us know if this resolves your issue!

Thanks a lot sir… Now it works :slightly_smiling_face: