MQTT API Reference
MQTT 3.1.1 client library
Publishes a message to the given topic name and receive an asynchronous notification when the publish completes.
This function transmits an MQTT PUBLISH packet to the server. A PUBLISH packet contains a payload and a topic name. Any clients with a subscription on a topic filter matching the PUBLISH topic name will receive a copy of the PUBLISH packet from the server.
If a PUBLISH packet fails to reach the server and it is not a QoS 0 message, it will be retransmitted. See IotMqttPublishInfo_t for a description of the retransmission strategy.
Attention QoS 2 messages are currently unsupported. Only 0 or 1 are valid for message QoS.
Parameters
[in] mqttConnection The MQTT connection to use for the publish.
[in] pPublishInfo MQTT publish parameters.
[in] flags Flags which modify the behavior of this function. See MQTT Function Flags .
[in] pCallbackInfo Asynchronous notification of this function's completion.
[out] pPublishOperation Set to a handle by which this operation may be referenced after this function returns. This reference is invalidated once the publish operation completes.
Returns This function will return IOT_MQTT_STATUS_PENDING upon success for QoS 1 publishes. For a QoS 0 publish it returns IOT_MQTT_SUCCESS upon success.
Upon completion of a QoS 1 publish (either through an IotMqttCallbackInfo_t or IotMqtt_Wait ), the status will be one of:
If this function fails before queuing an publish operation (regardless of QoS), it will return one of:
Note The parameters pCallbackInfo
and pPublishOperation
should only be used for QoS 1 publishes. For QoS 0, they should both be NULL
.
See also IotMqtt_PublishSync for a blocking variant of this function.
Example
&publishInfo,
0,
NULL,
NULL );
&publishInfo,
NULL,
&qos1Operation );
{
}
MQTT operation queued, awaiting result.
Definition: iot_mqtt_types.h:129
uint32_t retryLimit
How many times to attempt retransmission.
Definition: iot_mqtt_types.h:409
IotMqttError_t
Return codes of MQTT functions.
Definition: iot_mqtt_types.h:103
Information on a user-provided MQTT callback function.
Definition: iot_mqtt_types.h:516
IotMqttError_t IotMqtt_PublishAsync(IotMqttConnection_t mqttConnection, const IotMqttPublishInfo_t *pPublishInfo, uint32_t flags, const IotMqttCallbackInfo_t *pCallbackInfo, IotMqttOperation_t *const pPublishOperation)
Publishes a message to the given topic name and receive an asynchronous notification when the publish...
Definition: iot_mqtt_api.c:1595
const void * pPayload
Payload of PUBLISH.
Definition: iot_mqtt_types.h:405
struct _mqttOperation * IotMqttOperation_t
Opaque handle that references an in-progress MQTT operation.
Definition: iot_mqtt_types.h:88
uint16_t topicNameLength
Length of IotMqttPublishInfo_t.pTopicName.
Definition: iot_mqtt_types.h:403
const char * pTopicName
Topic name of PUBLISH.
Definition: iot_mqtt_types.h:402
uint32_t retryMs
If no response is received within this time, the message is retransmitted.
Definition: iot_mqtt_types.h:408
struct _mqttConnection * IotMqttConnection_t
Opaque handle of an MQTT connection.
Definition: iot_mqtt_types.h:66
IotMqttQos_t qos
QoS of message. Must be 0 or 1.
Definition: iot_mqtt_types.h:399
Definition: iot_mqtt_types.h:305
size_t payloadLength
Length of IotMqttPublishInfo_t.pPayload. For LWT messages, this is limited to 65535.
Definition: iot_mqtt_types.h:406
Definition: iot_mqtt_types.h:306
IotMqttError_t IotMqtt_Wait(IotMqttOperation_t operation, uint32_t timeoutMs)
Waits for an operation to complete.
Definition: iot_mqtt_api.c:1918
Information on a PUBLISH message.
Definition: iot_mqtt_types.h:397
#define IOT_MQTT_FLAG_WAITABLE
Allows the use of IotMqtt_Wait for blocking until completion.
Definition: iot_mqtt_types.h:1087
#define IOT_MQTT_PUBLISH_INFO_INITIALIZER
Initializer for IotMqttPublishInfo_t.
Definition: iot_mqtt_types.h:1063
#define IOT_MQTT_OPERATION_INITIALIZER
Initializer for IotMqttOperation_t.
Definition: iot_mqtt_types.h:1071