I have an ESP based device operating fine. It sends two MQTT messages to node red running on a pi zero.
The first message comes in and goes through a JSON node to convert from a string to JSON object.
The second message is sent in the same way, from the same device, using the same function (all worked out with the arduinoJSON assistant) but the second message returns the error after the JSON node
"msg : string[28]"
"Unexpected end of JSON input"
Ive used mqttfx to pick up the message and can see the issue.
The expected message is something like
{
"heaterDemand":false,
"heaterStarts":123456,
"heaterStartsPerDay":12345,
"heaterRunTime":123456.0,
"heaterRunTimePerDay":12346.0
}
but the actual message is
{"heaterDemand":false,"heaterStarts":0,"heaterStartsPerDay":0,"heaterRunTime":0
So the end of the message is being cut off.
I suspect if I increase the buffer object size it should work but the arduinoJSON assistant has worked out the value. So Im a bit stuck.
This is the sending program in case its of interest.
const size_t capacity4 = JSON_OBJECT_SIZE(5);
DynamicJsonDocument doc4(capacity4);
doc4["heaterDemand"] = heaterDemand;
doc4["heaterStarts"] = heaterStarts;
doc4["heaterStartsPerDay"] = heaterStartsPerDay;
doc4["heaterRunTime"] = heaterRunTime;
doc4["heaterRunTimePerDay"] = heaterRunTimePerDay;
char buffer4[capacity4];
serializeJson(doc4, buffer4, sizeof(buffer4));
sendValues(buffer4, mqtt_publish_topic2);
The send function works as its sending the first message. unless this is some kind of memory issue on the device (wemos D1 mini, or maybe a clone, cant remember)?
I guess I could try to increase the buffer size by the following or something similar, but as I say, this was worked out the same way as the first message which is much larger and works fine.
const size_t capacity4 = JSON_OBJECT_SIZE(5) + 80;
Any direction appreciated. Thanks