marvinroger / async-mqtt-client

📶 An Arduino for ESP8266 asynchronous MQTT client implementation
MIT License
848 stars 268 forks source link

Subscription Example (Getting value) #292

Closed Sergio-tix closed 1 year ago

Sergio-tix commented 1 year ago

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?

bertmelis commented 1 year ago

https://github.com/marvinroger/async-mqtt-client/blob/develop/docs/5.-Troubleshooting.md

This is literally in the docs.