In the PubSub example the payloadLen property of the message object is set to the length of the message string + 1.
message.payloadLen = strlen(buf) + 1;
This results in the MQTT payload published containing the string's terminating null character. In my case the added null character was causing the JSON payload parsing to fail. Unless you have a reason for the MQTT message to contain the terminating null character there is no need to add one to the string length.
You are totally right. No need to have the null character into the payload. The receiving application should take care of that. I'll remove the + 1.
Thank you.
In the PubSub example the payloadLen property of the message object is set to the length of the message string + 1.
message.payloadLen = strlen(buf) + 1;
This results in the MQTT payload published containing the string's terminating null character. In my case the added null character was causing the JSON payload parsing to fail. Unless you have a reason for the MQTT message to contain the terminating null character there is no need to add one to the string length.
message.payloadLen = strlen(buf);