coreMQTT
v2.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 );
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:2742
MQTTStatus_t
MQTTStatus_t
Return codes from MQTT functions.
Definition:
core_mqtt_serializer.h:99
MQTTContext_t
A struct representing an MQTT connection.
Definition:
core_mqtt.h:162
MQTTPublishInfo_t
MQTT PUBLISH packet parameters.
Definition:
core_mqtt_serializer.h:214
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.
}
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:3099
MQTTSuccess
@ MQTTSuccess
Definition:
core_mqtt_serializer.h:100
MQTTQoS1
@ MQTTQoS1
Definition:
core_mqtt_serializer.h:123
MQTTPublishInfo_t::qos
MQTTQoS_t qos
Quality of Service for message.
Definition:
core_mqtt_serializer.h:218
MQTTPublishInfo_t::topicNameLength
uint16_t topicNameLength
Length of topic name.
Definition:
core_mqtt_serializer.h:238
MQTTPublishInfo_t::payloadLength
size_t payloadLength
Message payload length.
Definition:
core_mqtt_serializer.h:248
MQTTPublishInfo_t::pTopicName
const char * pTopicName
Topic name on which the message is published.
Definition:
core_mqtt_serializer.h:233
MQTTPublishInfo_t::pPayload
const void * pPayload
Message payload.
Definition:
core_mqtt_serializer.h:243
Generated by
1.9.2