monstrenyatko / ArduinoMqtt

MQTT client for Arduino
MIT License
72 stars 12 forks source link

PubSub Example message.payloadLen #16

Closed abaskin closed 6 years ago

abaskin commented 6 years ago

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);

monstrenyatko commented 6 years ago

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.