coreMQTT v1.2.0
MQTT 3.1.1 Client Library

Publishes a message to the given topic name.

const MQTTPublishInfo_t * pPublishInfo,
uint16_t packetId );
MQTTStatus_t MQTT_Publish(MQTTContext_t *pContext, const MQTTPublishInfo_t *pPublishInfo, uint16_t packetId)
Publishes a message to the given topic name.
Definition: core_mqtt.c:1916
Return codes from MQTT functions.
Definition: core_mqtt_serializer.h:97
A struct representing an MQTT connection.
Definition: core_mqtt.h:169
MQTT PUBLISH packet parameters.
Definition: core_mqtt_serializer.h:209
[in]pContextInitialized MQTT context.
[in]pPublishInfoMQTT PUBLISH packet parameters.
[in]packetIdpacket ID generated by MQTT_GetPacketId.
MQTTNoMemory if pBuffer is too small to hold the MQTT packet; MQTTBadParameter if invalid parameters are passed; MQTTSendFailed if transport write failed; MQTTSuccess otherwise.


// Variables used in this example.
MQTTStatus_t status;
MQTTPublishInfo_t publishInfo;
uint16_t packetId;
// This context is assumed to be initialized and connected.
MQTTContext_t * pContext;
// QoS of publish.
publishInfo.qos = MQTTQoS1;
publishInfo.pTopicName = "/some/topic/name";
publishInfo.topicNameLength = strlen( publishInfo.pTopicName );
publishInfo.pPayload = "Hello World!";
publishInfo.payloadLength = strlen( "Hello World!" );
// Packet ID is needed for QoS > 0.
packetId = MQTT_GetPacketId( pContext );
status = MQTT_Publish( pContext, &publishInfo, packetId );
if( status == MQTTSuccess )
// Since the QoS is > 0, we will need to call MQTT_ReceiveLoop()
// or MQTT_ProcessLoop() to process the publish acknowledgments.
uint16_t MQTT_GetPacketId(MQTTContext_t *pContext)
Get a packet ID that is valid according to the MQTT 3.1.1 spec.
Definition: core_mqtt.c:2279
@ MQTTSuccess
Definition: core_mqtt_serializer.h:98
Definition: core_mqtt_serializer.h:118
MQTTQoS_t qos
Quality of Service for message.
Definition: core_mqtt_serializer.h:213
uint16_t topicNameLength
Length of topic name.
Definition: core_mqtt_serializer.h:233
size_t payloadLength
Message payload length.
Definition: core_mqtt_serializer.h:243
const char * pTopicName
Topic name on which the message is published.
Definition: core_mqtt_serializer.h:228
const void * pPayload
Message payload.
Definition: core_mqtt_serializer.h:238