espressif / esp-mqtt

ESP32 mqtt component
Apache License 2.0
603 stars 255 forks source link

esp_mqtt_client_publish() does not return -1 for QOS0 when disconnect (IDFGH-10129) #256

Closed dpslwk closed 11 months ago

dpslwk commented 1 year ago

With MQTT_SKIP_PUBLISH_IF_DISCONNECTED disabled Documentation says that a publish of qos=0 when disconnected will return -1 This is both in the notes section and in the @return

  • Client doesn't have to be connected for this API to work, enqueueing the messages with qos>1 (returning -1 for all the qos=0 messages if disconnected). If MQTT_SKIP_PUBLISH_IF_DISCONNECTED is enabled, this API will not attempt to publish when the client is not connected and will always return -1.

    @return message_id of the publish message (for QoS 0 message_id will always be zero) on success. -1 on failure.

I think the issue is here and an else { ret = -1; } on the if qos check would be all that's needed to fix it

https://github.com/espressif/esp-mqtt/blob/0e4cec94978b7bebafaa5fbab0b395f86c3c91ab/mqtt_client.c#L2003-L2016

euripedesrocha commented 1 year ago

Hi @dpslwk thanks for reporting. Already applied the fix and it should be available soon.