adafruit / Adafruit_MQTT_Library

Arduino library for MQTT support
MIT License
566 stars 292 forks source link

Message length limit when publishing #200

Open mikycol opened 2 years ago

mikycol commented 2 years ago

Through the sketch in the library I'm trying to publish the following message {"unique_id": "TAVERNETTA-temperature","device_class": "temperature", "name": "TAVERNETTA Temperature", "state_topic": "homeassistant/sensor/TAVERNETTA/state", "unit_of_measurement": "°C", "value_template": "{{ value_json.temperature}}"}, but the message that arrives is truncated with a length of 147 characters.

I'm pretty sure I made some mistakes, but I can't figure it out.

Any suggestions?

gak commented 2 years ago

I'm having a similar issue, but it's only sending 89 chars. It's on an ESP32-S2. Using 2.4.2 installed via the Arduino IDE.

If I set QoS to 1 or 2, it fails to send at all.

char encoded[2000];

// Some JSON generation here.
// I've tried this with just creating a long string by hand, e.g.:
// char *encoded = "very long string";
// with exactly the same truncation.

Serial.println(motion_config_topic.c_str());
Serial.println(encoded);
Serial.println(strlen(encoded));

if (!messages->publish(motion_config_topic.c_str(), encoded, 0)) {
    Serial.println("Failed to send motion config.");
}

The related output:

16:50:01.893 -> homeassistant/binary_sensor/esp32s2-0edc60-motion/config
16:50:01.893 -> {"name":"esp32s2-0edc60","unique_id":"esp32s2-0edc60-motion","device_class":"motion","state_topic":"homeassistant/binary_sensor/esp32s2-0edc60-motion/state"}
16:50:01.893 -> 157

I've successfully sent a longer message using using another MQTT client. I've received the truncation using two separate clients (home assistant and a rust app). Here is the truncated message for completeness:

{"name":"esp32s2-0edc60","unique_id":"esp32s2-0edc60-motion","device_class":"motion","sta
gak commented 2 years ago

Increasing MAXBUFFERSIZE does the trick. Not sure how stable this solution is but it works for me so far.

Edit: Still had issues. Went with https://github.com/plapointe6/EspMQTTClient which allows changing the max packet size and worked first go.

SaberShip commented 2 years ago

I have this exact issue, seems to always send 88 characters for me before truncating my message. Seems like a pretty big issue.

MEHUL95 commented 1 year ago

Exactly same issue, I am facing. Now moving back to move to pubsub client lib again.

jsphuebner commented 12 months ago

Increasing MAXBUFFERSIZE also "fixed" it for me. Should be configurable or larger in the first place, maybe depending on platform.