Function esp_idf_sys::esp_mqtt_client_publish

source ·
pub unsafe extern "C" fn esp_mqtt_client_publish(
    client: esp_mqtt_client_handle_t,
    topic: *const c_char,
    data: *const c_char,
    len: c_int,
    qos: c_int,
    retain: c_int,
) -> c_int
Expand description

@brief Client to send a publish message to the broker

Notes:

  • This API might block for several seconds, either due to network timeout (10s) or if publishing payloads longer than internal buffer (due to message fragmentation)
  • 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.
  • It is thread safe, please refer to esp_mqtt_client_subscribe for details

@param client MQTT client handle @param topic topic string @param data payload string (set to NULL, sending empty payload message) @param len data length, if set to 0, length is calculated from payload string @param qos QoS of publish message @param retain retain flag

@return message_id of the publish message (for QoS 0 message_id will always be zero) on success. -1 on failure, -2 in case of full outbox.