marvinroger/async-mqtt-client

Subscription Example (Getting value)

Sergio-tix opened this issue · 1 comments

There is no code in the examples, how to get the value sent by a third-party server.
I used this code where I added "payload"

void onMqttMessage(char* topic, char* payload, AsyncMqttClientMessageProperties properties, size_t len, size_t index, size_t total) {
  Serial.println("Publish received.");
  Serial.print("  topic: ");
  Serial.println(topic);
  Serial.print("  qos: ");
  Serial.println(properties.qos);
  Serial.print("  dup: ");
  Serial.println(properties.dup);
  Serial.print("  retain: ");
  Serial.println(properties.retain);
  Serial.print("  len: ");
  Serial.println(len);
  Serial.print("  index: ");
  Serial.println(index);
  Serial.print("  total: ");
  Serial.println(total);
//----------------------------------------
     Serial.print("payload ");
     Serial.println(payload);
}

As a result, when the server sends data, I get the sent value and garbage at the end.
Looks like this:
Server sent
0
2
01235
ESP32 out
0⸮
2⸮⸮?�
01235⸮⸮?̎⸮?|⸮⸮D⸮⸮
Where does it come from? What am I doing wrong?