Size limit ? of a JSON object ? (Arduino -> MQTT -> Node-Red)

Hi there !

I'm facing a weird problem which I don't understand (well, I'm still some king of a newbee ...).

I'm sending a JSON formatted string to a MQTT broker (local, hosted on a Debian Buster server where Node-Red also resides) with an Arduino and retrieve it with Node-Red.

The code is like follows :

String jsonPayload = "{"DHT_1_t":"";
jsonPayload += t_1;
jsonPayload +="","DHT_1_h":"";
jsonPayload += h_1;
jsonPayload +="","YF-S201_1":"";
jsonPayload += l_min_1;
jsonPayload +="","phR_1":"";
jsonPayload += phR_1;
jsonPayload +="","PIR_1":"";
jsonPayload += pir_1;
jsonPayload +="","AS-103_1":"";
jsonPayload += Irms;
jsonPayload +="","MQ-2_1":"";
jsonPayload += mq2_1Value;
//jsonPayload +="","MQ-7_1":"";
//jsonPayload += mq7_1Value;
//jsonPayload +="","MQ-135_1":"";
//jsonPayload += mq135_1Value;
jsonPayload +=""}";

Like this, it works. But if I uncomment the 4 lines .. it stops working ... I don't get anything anymore (while the serial output from the arduino is correct, it's not a problem with the Arduino sketch.

Any idea ? Are there some limitations I missed ?

Thnaks in advance for your valuable help

That doesn't look like valid code though it is difficult to be certain what sort of quotes they are. Some of the earlier lines don't look valid either. In the editor do you see an error indicator against that line? If not then feed the output into a debug node and see what it looks like before and after uncommenting the lines.

What mqtt library are you using?

don't you need a backslash to escape the double quotes? So your first line should be
String jsonPayload = "{\"DHT_1_t\":\"";
it may be that they were removed because you didn't enclose your code with three back tic's (```) before and after your code.

p.s. if you are using PubSubClient then I beleive the limit is 128 which you can change

// MQTT_MAX_PACKET_SIZE : Maximum packet size
#ifndef MQTT_MAX_PACKET_SIZE
#define MQTT_MAX_PACKET_SIZE 384 // need to fix this here, because this define cannot be overruled within the Arduino sketch...
#endif

Just for anyone who finds this by title later: If your using the PubSubClient for the Arduino, they DO have a limit:

The maximum message size, including header, is 128 bytes by default. This is configurable via MQTT_MAX_PACKET_SIZE

1 Like

Just realised that Is Arduino code not node-red code. Has @i8beef's post sorted it?

It must be the problem !! I will check this tomorrow morning.

Thanks a lot already !!!

It worked perfectly !!

Thanks a lot for your help !!