coreMQTT
v1.1.1
MQTT 3.1.1 Client Library
MQTT_Publish
Publishes a message to the given topic name.
MQTTStatus_t
MQTT_Publish
(
MQTTContext_t
* pContext,
const
MQTTPublishInfo_t
* pPublishInfo,
uint16_t packetId );
Parameters
[in]
pContext
Initialized MQTT context.
[in]
pPublishInfo
MQTT PUBLISH packet parameters.
[in]
packetId
packet ID generated by
MQTT_GetPacketId
.
Returns
MQTTNoMemory
if pBuffer is too small to hold the MQTT packet;
MQTTBadParameter
if invalid parameters are passed;
MQTTSendFailed
if transport write failed;
MQTTSuccess
otherwise.
Example
// 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.
}
MQTTPublishInfo_t::topicNameLength
uint16_t topicNameLength
Length of topic name.
Definition:
core_mqtt_serializer.h:227
MQTT_GetPacketId
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:2270
MQTTPublishInfo_t::pPayload
const void * pPayload
Message payload.
Definition:
core_mqtt_serializer.h:232
MQTTStatus_t
MQTTStatus_t
Return codes from MQTT functions.
Definition:
core_mqtt_serializer.h:91
MQTTPublishInfo_t::pTopicName
const char * pTopicName
Topic name on which the message is published.
Definition:
core_mqtt_serializer.h:222
MQTT_Publish
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:1907
MQTTContext_t
A struct representing an MQTT connection.
Definition:
core_mqtt.h:163
MQTTQoS1
@ MQTTQoS1
Definition:
core_mqtt_serializer.h:112
MQTTPublishInfo_t::qos
MQTTQoS_t qos
Quality of Service for message.
Definition:
core_mqtt_serializer.h:207
MQTTSuccess
@ MQTTSuccess
Definition:
core_mqtt_serializer.h:92
MQTTPublishInfo_t
MQTT PUBLISH packet parameters.
Definition:
core_mqtt_serializer.h:203
MQTTPublishInfo_t::payloadLength
size_t payloadLength
Message payload length.
Definition:
core_mqtt_serializer.h:237
Generated by
1.8.20