Implements the user-facing functions in core_mqtt.h. More...
#include <string.h>
#include <assert.h>
#include "core_mqtt.h"
#include "core_mqtt_state.h"
#include "core_mqtt_config_defaults.h"
Data Structures | |
struct | MQTTVec_t |
An opaque structure provided by the library to the MQTTStorePacketForRetransmit function when using MQTTStorePacketForRetransmit. More... | |
Macros | |
#define | MQTT_PRE_SEND_HOOK(pContext) |
Hook called before a 'send' operation is executed. | |
#define | MQTT_POST_SEND_HOOK(pContext) |
Hook called after the 'send' operation is complete. | |
#define | MQTT_PRE_STATE_UPDATE_HOOK(pContext) |
Hook called just before an update to the MQTT state is made. | |
#define | MQTT_POST_STATE_UPDATE_HOOK(pContext) |
Hook called just after an update to the MQTT state has been made. | |
#define | CORE_MQTT_SERIALIZED_LENGTH_FIELD_BYTES ( 2U ) |
Bytes required to encode any string length in an MQTT packet header. Length is always encoded in two bytes according to the MQTT specification. | |
#define | CORE_MQTT_SUBSCRIBE_PER_TOPIC_VECTOR_LENGTH ( 3U ) |
Number of vectors required to encode one topic filter in a subscribe request. Three vectors are required as there are three fields in the subscribe request namely: | |
#define | CORE_MQTT_UNSUBSCRIBE_PER_TOPIC_VECTOR_LENGTH ( 2U ) |
Number of vectors required to encode one topic filter in an unsubscribe request. Two vectors are required as there are two fields in the unsubscribe request namely: | |
Functions | |
static int32_t | sendBuffer (MQTTContext_t *pContext, const uint8_t *pBufferToSend, size_t bytesToSend) |
Sends provided buffer to network using transport send. | |
static MQTTStatus_t | sendConnectWithoutCopy (MQTTContext_t *pContext, const MQTTConnectInfo_t *pConnectInfo, const MQTTPublishInfo_t *pWillInfo, size_t remainingLength) |
Sends MQTT connect without copying the users data into any buffer. | |
static int32_t | sendMessageVector (MQTTContext_t *pContext, TransportOutVector_t *pIoVec, size_t ioVecCount) |
Sends the vector array passed through the parameters over the network. | |
static size_t | addEncodedStringToVector (uint8_t serializedLength[CORE_MQTT_SERIALIZED_LENGTH_FIELD_BYTES], const char *const string, uint16_t length, TransportOutVector_t *iterator, size_t *updatedLength) |
Add a string and its length after serializing it in a manner outlined by the MQTT specification. | |
static MQTTStatus_t | sendSubscribeWithoutCopy (MQTTContext_t *pContext, const MQTTSubscribeInfo_t *pSubscriptionList, size_t subscriptionCount, uint16_t packetId, size_t remainingLength) |
Send MQTT SUBSCRIBE message without copying the user data into a buffer and directly sending it. | |
static MQTTStatus_t | sendUnsubscribeWithoutCopy (MQTTContext_t *pContext, const MQTTSubscribeInfo_t *pSubscriptionList, size_t subscriptionCount, uint16_t packetId, size_t remainingLength) |
Send MQTT UNSUBSCRIBE message without copying the user data into a buffer and directly sending it. | |
static uint32_t | calculateElapsedTime (uint32_t later, uint32_t start) |
Calculate the interval between two millisecond timestamps, including when the later value has overflowed. | |
static MQTTPubAckType_t | getAckFromPacketType (uint8_t packetType) |
Convert a byte indicating a publish ack type to an MQTTPubAckType_t. | |
static int32_t | recvExact (MQTTContext_t *pContext, size_t bytesToRecv) |
Receive bytes into the network buffer. | |
static MQTTStatus_t | discardPacket (MQTTContext_t *pContext, size_t remainingLength, uint32_t timeoutMs) |
Discard a packet from the transport interface. | |
static MQTTStatus_t | discardStoredPacket (MQTTContext_t *pContext, const MQTTPacketInfo_t *pPacketInfo) |
Discard a packet from the MQTT buffer and the transport interface. | |
static MQTTStatus_t | receivePacket (MQTTContext_t *pContext, MQTTPacketInfo_t incomingPacket, uint32_t remainingTimeMs) |
Receive a packet from the transport interface. | |
static uint8_t | getAckTypeToSend (MQTTPublishState_t state) |
Get the correct ack type to send. | |
static MQTTStatus_t | sendPublishAcks (MQTTContext_t *pContext, uint16_t packetId, MQTTPublishState_t publishState) |
Send acks for received QoS 1/2 publishes. | |
static MQTTStatus_t | handleKeepAlive (MQTTContext_t *pContext) |
Send a keep alive PINGREQ if the keep alive interval has elapsed. | |
static MQTTStatus_t | handleIncomingPublish (MQTTContext_t *pContext, MQTTPacketInfo_t *pIncomingPacket) |
Handle received MQTT PUBLISH packet. | |
static MQTTStatus_t | handlePublishAcks (MQTTContext_t *pContext, MQTTPacketInfo_t *pIncomingPacket) |
Handle received MQTT publish acks. | |
static MQTTStatus_t | handleIncomingAck (MQTTContext_t *pContext, MQTTPacketInfo_t *pIncomingPacket, bool manageKeepAlive) |
Handle received MQTT ack. | |
static MQTTStatus_t | receiveSingleIteration (MQTTContext_t *pContext, bool manageKeepAlive) |
Run a single iteration of the receive loop. | |
static MQTTStatus_t | validateSubscribeUnsubscribeParams (const MQTTContext_t *pContext, const MQTTSubscribeInfo_t *pSubscriptionList, size_t subscriptionCount, uint16_t packetId) |
Validates parameters of MQTT_Subscribe or MQTT_Unsubscribe. | |
static MQTTStatus_t | receiveConnack (MQTTContext_t *pContext, uint32_t timeoutMs, bool cleanSession, MQTTPacketInfo_t *pIncomingPacket, bool *pSessionPresent) |
Receives a CONNACK MQTT packet. | |
static MQTTStatus_t | handleUncleanSessionResumption (MQTTContext_t *pContext) |
Resends pending acks for a re-established MQTT session. | |
static MQTTStatus_t | handleCleanSession (MQTTContext_t *pContext) |
Clears existing state records for a clean session. | |
static MQTTStatus_t | sendPublishWithoutCopy (MQTTContext_t *pContext, const MQTTPublishInfo_t *pPublishInfo, uint8_t *pMqttHeader, size_t headerSize, uint16_t packetId) |
Send the publish packet without copying the topic string and payload in the buffer. | |
static MQTTStatus_t | validatePublishParams (const MQTTContext_t *pContext, const MQTTPublishInfo_t *pPublishInfo, uint16_t packetId) |
Function to validate MQTT_Publish parameters. | |
static bool | matchEndWildcardsSpecialCases (const char *pTopicFilter, uint16_t topicFilterLength, uint16_t filterIndex) |
Performs matching for special cases when a topic filter ends with a wildcard character. | |
static bool | matchWildcards (const char *pTopicName, uint16_t topicNameLength, const char *pTopicFilter, uint16_t topicFilterLength, uint16_t *pNameIndex, uint16_t *pFilterIndex, bool *pMatch) |
Attempt to match topic name with a topic filter starting with a wildcard. | |
static bool | matchTopicFilter (const char *pTopicName, uint16_t topicNameLength, const char *pTopicFilter, uint16_t topicFilterLength) |
Match a topic name and topic filter allowing the use of wildcards. | |
MQTTStatus_t | MQTT_Init (MQTTContext_t *pContext, const TransportInterface_t *pTransportInterface, MQTTGetCurrentTimeFunc_t getTimeFunction, MQTTEventCallback_t userCallback, const MQTTFixedBuffer_t *pNetworkBuffer) |
Initialize an MQTT context. | |
MQTTStatus_t | MQTT_InitStatefulQoS (MQTTContext_t *pContext, MQTTPubAckInfo_t *pOutgoingPublishRecords, size_t outgoingPublishCount, MQTTPubAckInfo_t *pIncomingPublishRecords, size_t incomingPublishCount) |
Initialize an MQTT context for QoS > 0. | |
MQTTStatus_t | MQTT_InitRetransmits (MQTTContext_t *pContext, MQTTStorePacketForRetransmit storeFunction, MQTTRetrievePacketForRetransmit retrieveFunction, MQTTClearPacketForRetransmit clearFunction) |
Initialize an MQTT context for publish retransmits for QoS > 0. | |
MQTTStatus_t | MQTT_CancelCallback (const MQTTContext_t *pContext, uint16_t packetId) |
Cancels an outgoing publish callback (only for QoS > QoS0) by removing it from the pending ACK list. | |
MQTTStatus_t | MQTT_CheckConnectStatus (MQTTContext_t *pContext) |
Checks the MQTT connection status with the broker. | |
MQTTStatus_t | MQTT_Connect (MQTTContext_t *pContext, const MQTTConnectInfo_t *pConnectInfo, const MQTTPublishInfo_t *pWillInfo, uint32_t timeoutMs, bool *pSessionPresent) |
Establish an MQTT session. | |
MQTTStatus_t | MQTT_Subscribe (MQTTContext_t *pContext, const MQTTSubscribeInfo_t *pSubscriptionList, size_t subscriptionCount, uint16_t packetId) |
Sends MQTT SUBSCRIBE for the given list of topic filters to the broker. | |
MQTTStatus_t | MQTT_Publish (MQTTContext_t *pContext, const MQTTPublishInfo_t *pPublishInfo, uint16_t packetId) |
Publishes a message to the given topic name. | |
MQTTStatus_t | MQTT_Ping (MQTTContext_t *pContext) |
Sends an MQTT PINGREQ to broker. | |
MQTTStatus_t | MQTT_Unsubscribe (MQTTContext_t *pContext, const MQTTSubscribeInfo_t *pSubscriptionList, size_t subscriptionCount, uint16_t packetId) |
Sends MQTT UNSUBSCRIBE for the given list of topic filters to the broker. | |
MQTTStatus_t | MQTT_Disconnect (MQTTContext_t *pContext) |
Disconnect an MQTT session. | |
MQTTStatus_t | MQTT_ProcessLoop (MQTTContext_t *pContext) |
Loop to receive packets from the transport interface. Handles keep alive. | |
MQTTStatus_t | MQTT_ReceiveLoop (MQTTContext_t *pContext) |
Loop to receive packets from the transport interface. Does not handle keep alive. | |
uint16_t | MQTT_GetPacketId (MQTTContext_t *pContext) |
Get a packet ID that is valid according to the MQTT 3.1.1 spec. | |
MQTTStatus_t | MQTT_MatchTopic (const char *pTopicName, const uint16_t topicNameLength, const char *pTopicFilter, const uint16_t topicFilterLength, bool *pIsMatch) |
A utility function that determines whether the passed topic filter and topic name match according to the MQTT 3.1.1 protocol specification. | |
MQTTStatus_t | MQTT_GetSubAckStatusCodes (const MQTTPacketInfo_t *pSubackPacket, uint8_t **pPayloadStart, size_t *pPayloadSize) |
Parses the payload of an MQTT SUBACK packet that contains status codes corresponding to topic filter subscription requests from the original subscribe packet. | |
const char * | MQTT_Status_strerror (MQTTStatus_t status) |
Error code to string conversion for MQTT statuses. | |
size_t | MQTT_GetBytesInMQTTVec (MQTTVec_t *pVec) |
Get the bytes in a MQTTVec pointer which can store the whole array as a an MQTT packet when calling MQTT_SerializeMQTTVec( void * pAllocatedMem, MQTTVec_t *pVec ) function. | |
void | MQTT_SerializeMQTTVec (uint8_t *pAllocatedMem, MQTTVec_t *pVec) |
Serialize the bytes in an array of MQTTVec in the provided pAllocatedMem . | |
Implements the user-facing functions in core_mqtt.h.
#define CORE_MQTT_SUBSCRIBE_PER_TOPIC_VECTOR_LENGTH ( 3U ) |
Number of vectors required to encode one topic filter in a subscribe request. Three vectors are required as there are three fields in the subscribe request namely:
#define CORE_MQTT_UNSUBSCRIBE_PER_TOPIC_VECTOR_LENGTH ( 2U ) |
Number of vectors required to encode one topic filter in an unsubscribe request. Two vectors are required as there are two fields in the unsubscribe request namely:
|
static |
Sends provided buffer to network using transport send.
param[in] pContext Initialized MQTT context.
param[in] pBufferToSend Buffer to be sent to network.
param[in] bytesToSend Number of bytes to be sent.
|
static |
Sends MQTT connect without copying the users data into any buffer.
param[in] pContext Initialized MQTT context.
param[in] pConnectInfo MQTT CONNECT packet information.
param[in] pWillInfo Last Will and Testament. Pass NULL if Last Will and Testament is not used.
param[in] remainingLength the length of the connect packet.
|
static |
Sends the vector array passed through the parameters over the network.
[in] | pContext | Initialized MQTT context. |
[in] | pIoVec | The vector array to be sent. |
[in] | ioVecCount | The number of elements in the array. |
|
static |
Add a string and its length after serializing it in a manner outlined by the MQTT specification.
[in] | serializedLength | Array of two bytes to which the vector will point. The array must remain in scope until the message has been sent. |
[in] | string | The string to be serialized. |
[in] | length | The length of the string to be serialized. |
[in] | iterator | The iterator pointing to the first element in the transport interface IO array. |
[out] | updatedLength | This parameter will be added to with the number of bytes added to the vector. |
|
static |
Send MQTT SUBSCRIBE message without copying the user data into a buffer and directly sending it.
[in] | pContext | Initialized MQTT context. |
[in] | pSubscriptionList | List of MQTT subscription info. |
[in] | subscriptionCount | The count of elements in the list. |
[in] | packetId | The packet ID of the subscribe packet |
[in] | remainingLength | The remaining length of the subscribe packet. |
|
static |
Send MQTT UNSUBSCRIBE message without copying the user data into a buffer and directly sending it.
[in] | pContext | Initialized MQTT context. |
[in] | pSubscriptionList | MQTT subscription info. |
[in] | subscriptionCount | The count of elements in the list. |
[in] | packetId | The packet ID of the unsubscribe packet. |
[in] | remainingLength | The remaining length of the unsubscribe packet. |
|
static |
Calculate the interval between two millisecond timestamps, including when the later value has overflowed.
[in] | later | The later time stamp, in milliseconds. |
[in] | start | The earlier time stamp, in milliseconds. |
|
static |
Convert a byte indicating a publish ack type to an MQTTPubAckType_t.
[in] | packetType | First byte of fixed header. |
|
static |
Receive bytes into the network buffer.
[in] | pContext | Initialized MQTT Context. |
[in] | bytesToRecv | Number of bytes to receive. |
OR
|
static |
Discard a packet from the transport interface.
[in] | pContext | MQTT Connection context. |
[in] | remainingLength | Remaining length of the packet to dump. |
[in] | timeoutMs | Time remaining to discard the packet. |
|
static |
Discard a packet from the MQTT buffer and the transport interface.
[in] | pContext | MQTT Connection context. |
[in] | pPacketInfo | Information struct of the packet to be discarded. |
|
static |
Receive a packet from the transport interface.
[in] | pContext | MQTT Connection context. |
[in] | incomingPacket | packet struct with remaining length. |
[in] | remainingTimeMs | Time remaining to receive the packet. |
|
static |
Get the correct ack type to send.
[in] | state | Current state of publish. |
|
static |
Send acks for received QoS 1/2 publishes.
[in] | pContext | MQTT Connection context. |
[in] | packetId | packet ID of original PUBLISH. |
[in] | publishState | Current publish state in record. |
|
static |
Send a keep alive PINGREQ if the keep alive interval has elapsed.
[in] | pContext | Initialized MQTT Context. |
|
static |
Handle received MQTT PUBLISH packet.
[in] | pContext | MQTT Connection context. |
[in] | pIncomingPacket | Incoming packet. |
|
static |
Handle received MQTT publish acks.
[in] | pContext | MQTT Connection context. |
[in] | pIncomingPacket | Incoming packet. |
|
static |
Handle received MQTT ack.
[in] | pContext | MQTT Connection context. |
[in] | pIncomingPacket | Incoming packet. |
[in] | manageKeepAlive | Flag indicating if PINGRESPs should not be given to the application |
|
static |
Run a single iteration of the receive loop.
[in] | pContext | MQTT Connection context. |
[in] | manageKeepAlive | Flag indicating if keep alive should be handled. |
|
static |
Validates parameters of MQTT_Subscribe or MQTT_Unsubscribe.
[in] | pContext | Initialized MQTT context. |
[in] | pSubscriptionList | List of MQTT subscription info. |
[in] | subscriptionCount | The number of elements in pSubscriptionList. |
[in] | packetId | Packet identifier. |
|
static |
Receives a CONNACK MQTT packet.
[in] | pContext | Initialized MQTT context. |
[in] | timeoutMs | Timeout for waiting for CONNACK packet. |
[in] | cleanSession | Clean session flag set by application. |
[out] | pIncomingPacket | List of MQTT subscription info. |
[out] | pSessionPresent | Whether a previous session was present. Only relevant if not establishing a clean session. |
MQTTSuccess otherwise.
|
static |
Resends pending acks for a re-established MQTT session.
[in] | pContext | Initialized MQTT context. |
|
static |
Clears existing state records for a clean session.
[in] | pContext | Initialized MQTT context. |
|
static |
Send the publish packet without copying the topic string and payload in the buffer.
param[in] pContext Initialized MQTT context.
param[in] pPublishInfo MQTT PUBLISH packet parameters.
param[in] pMqttHeader the serialized MQTT header with the header byte; the encoded length of the packet; and the encoded length of the topic string.
param[in] headerSize Size of the serialized PUBLISH header.
param[in] packetId Packet Id of the publish packet.
|
static |
Function to validate MQTT_Publish parameters.
param[in] pContext Initialized MQTT context.
param[in] pPublishInfo MQTT PUBLISH packet parameters.
param[in] packetId Packet Id for the MQTT PUBLISH packet.
|
static |
Performs matching for special cases when a topic filter ends with a wildcard character.
When the topic name has been consumed but there are remaining characters to to match in topic filter, this function handles the following 2 cases:
[in] | pTopicFilter | The topic filter containing the wildcard. |
[in] | topicFilterLength | Length of the topic filter being examined. |
[in] | filterIndex | Index of the topic filter being examined. |
|
static |
Attempt to match topic name with a topic filter starting with a wildcard.
If the topic filter starts with a '+' (single-level) wildcard, the function advances the pNameIndex by a level in the topic name. If the topic filter starts with a '#' (multi-level) wildcard, the function concludes that both the topic name and topic filter match.
[in] | pTopicName | The topic name to match. |
[in] | topicNameLength | Length of the topic name. |
[in] | pTopicFilter | The topic filter to match. |
[in] | topicFilterLength | Length of the topic filter. |
[in,out] | pNameIndex | Current index in the topic name being examined. It is advanced by one level for + wildcards. |
[in,out] | pFilterIndex | Current index in the topic filter being examined. It is advanced to position of '/' level separator for '+' wildcard. |
[out] | pMatch | Whether the topic filter and topic name match. |
true
if the caller of this function should exit; false
if the caller should continue parsing the topics.
|
static |
Match a topic name and topic filter allowing the use of wildcards.
[in] | pTopicName | The topic name to check. |
[in] | topicNameLength | Length of the topic name. |
[in] | pTopicFilter | The topic filter to check. |
[in] | topicFilterLength | Length of topic filter. |
true
if the topic name and topic filter match; false
otherwise. MQTTStatus_t MQTT_Init | ( | MQTTContext_t * | pContext, |
const TransportInterface_t * | pTransportInterface, | ||
MQTTGetCurrentTimeFunc_t | getTimeFunction, | ||
MQTTEventCallback_t | userCallback, | ||
const MQTTFixedBuffer_t * | pNetworkBuffer | ||
) |
Initialize an MQTT context.
This function must be called on an MQTTContext_t before any other function.
[in] | pContext | The context to initialize. |
[in] | pTransportInterface | The transport interface to use with the context. |
[in] | getTimeFunction | The time utility function which can return the amount of time (in milliseconds) elapsed since a given epoch. This function will be used to ensure that timeouts in the API calls are met and keep-alive messages are sent on time. |
[in] | userCallback | The user callback to use with the context to notify about incoming packet events. |
[in] | pNetworkBuffer | Network buffer provided for the context. This buffer will be used to receive incoming messages from the broker. This buffer must remain valid and in scope for the entire lifetime of the pContext and must not be used by another context and/or application. |
Example
MQTTStatus_t MQTT_InitStatefulQoS | ( | MQTTContext_t * | pContext, |
MQTTPubAckInfo_t * | pOutgoingPublishRecords, | ||
size_t | outgoingPublishCount, | ||
MQTTPubAckInfo_t * | pIncomingPublishRecords, | ||
size_t | incomingPublishCount | ||
) |
Initialize an MQTT context for QoS > 0.
This function must be called on an MQTTContext_t after MQTT_Init and before any other function.
[in] | pContext | The context to initialize. |
[in] | pOutgoingPublishRecords | Pointer to memory which will be used to store state of outgoing publishes. |
[in] | outgoingPublishCount | Maximum number of records which can be kept in the memory pointed to by pOutgoingPublishRecords . |
[in] | pIncomingPublishRecords | Pointer to memory which will be used to store state of incoming publishes. |
[in] | incomingPublishCount | Maximum number of records which can be kept in the memory pointed to by pIncomingPublishRecords . |
Example
MQTTStatus_t MQTT_InitRetransmits | ( | MQTTContext_t * | pContext, |
MQTTStorePacketForRetransmit | storeFunction, | ||
MQTTRetrievePacketForRetransmit | retrieveFunction, | ||
MQTTClearPacketForRetransmit | clearFunction | ||
) |
Initialize an MQTT context for publish retransmits for QoS > 0.
This function must be called on an MQTTContext_t after MQTT_InitstatefulQoS and before any other function.
[in] | pContext | The context to initialize. |
[in] | storeFunction | User defined API used to store outgoing publishes. |
[in] | retrieveFunction | User defined API used to retreive a copied publish for resend operation. |
[in] | clearFunction | User defined API used to clear a particular copied publish packet. |
Example
MQTTStatus_t MQTT_CancelCallback | ( | const MQTTContext_t * | pContext, |
uint16_t | packetId | ||
) |
Cancels an outgoing publish callback (only for QoS > QoS0) by removing it from the pending ACK list.
[in] | pContext | Initialized MQTT context. |
[in] | packetId | packet ID corresponding to the outstanding publish. |
MQTTStatus_t MQTT_CheckConnectStatus | ( | MQTTContext_t * | pContext | ) |
Checks the MQTT connection status with the broker.
[in] | pContext | Initialized MQTT context. |
Example
MQTTStatus_t MQTT_Connect | ( | MQTTContext_t * | pContext, |
const MQTTConnectInfo_t * | pConnectInfo, | ||
const MQTTPublishInfo_t * | pWillInfo, | ||
uint32_t | timeoutMs, | ||
bool * | pSessionPresent | ||
) |
Establish an MQTT session.
This function will send MQTT CONNECT packet and receive a CONNACK packet. The send and receive from the network is done through the transport interface.
The maximum time this function waits for a CONNACK is decided in one of the following ways:
timeoutMs
is greater than 0: MQTTContext_t.getTime is used to ensure that the function does not wait more than timeoutMs
for CONNACK.timeoutMs
is 0: The network receive for CONNACK is retried up to the number of times configured by MQTT_MAX_CONNACK_RECEIVE_RETRY_COUNT.[in] | pContext | Initialized MQTT context. |
[in] | pConnectInfo | MQTT CONNECT packet information. |
[in] | pWillInfo | Last Will and Testament. Pass NULL if Last Will and Testament is not used. |
[in] | timeoutMs | Maximum time in milliseconds to wait for a CONNACK packet. A zero timeout makes use of the retries for receiving CONNACK as configured with MQTT_MAX_CONNACK_RECEIVE_RETRY_COUNT. |
[out] | pSessionPresent | This value will be set to true if a previous session was present; otherwise it will be set to false. It is only relevant if not establishing a clean session. |
timeoutMs
for CONNACK; MQTTStatusConnected if the connection is already established MQTTStatusDisconnectPending if the user is expected to call MQTT_Disconnect before calling any other API MQTTPublishRetrieveFailed if on an unclean session connection, the copied publishes are not retrieved successfully for retransmission MQTTSuccess otherwise.Example
MQTTStatus_t MQTT_Subscribe | ( | MQTTContext_t * | pContext, |
const MQTTSubscribeInfo_t * | pSubscriptionList, | ||
size_t | subscriptionCount, | ||
uint16_t | packetId | ||
) |
Sends MQTT SUBSCRIBE for the given list of topic filters to the broker.
[in] | pContext | Initialized MQTT context. |
[in] | pSubscriptionList | Array of MQTT subscription info. |
[in] | subscriptionCount | The number of elements in @ pSubscriptionList array. |
[in] | packetId | Packet ID generated by MQTT_GetPacketId. |
Example
MQTTStatus_t MQTT_Publish | ( | MQTTContext_t * | pContext, |
const MQTTPublishInfo_t * | pPublishInfo, | ||
uint16_t | packetId | ||
) |
Publishes a message to the given topic name.
[in] | pContext | Initialized MQTT context. |
[in] | pPublishInfo | MQTT PUBLISH packet parameters. |
[in] | packetId | packet ID generated by MQTT_GetPacketId. |
Example
MQTTStatus_t MQTT_Ping | ( | MQTTContext_t * | pContext | ) |
Sends an MQTT PINGREQ to broker.
[in] | pContext | Initialized and connected MQTT context. |
MQTTStatus_t MQTT_Unsubscribe | ( | MQTTContext_t * | pContext, |
const MQTTSubscribeInfo_t * | pSubscriptionList, | ||
size_t | subscriptionCount, | ||
uint16_t | packetId | ||
) |
Sends MQTT UNSUBSCRIBE for the given list of topic filters to the broker.
[in] | pContext | Initialized MQTT context. |
[in] | pSubscriptionList | List of MQTT subscription info. |
[in] | subscriptionCount | The number of elements in pSubscriptionList. |
[in] | packetId | packet ID generated by MQTT_GetPacketId. |
Example
MQTTStatus_t MQTT_Disconnect | ( | MQTTContext_t * | pContext | ) |
Disconnect an MQTT session.
[in] | pContext | Initialized and connected MQTT context. |
MQTTStatus_t MQTT_ProcessLoop | ( | MQTTContext_t * | pContext | ) |
Loop to receive packets from the transport interface. Handles keep alive.
[in] | pContext | Initialized and connected MQTT context. |
Example
MQTTStatus_t MQTT_ReceiveLoop | ( | MQTTContext_t * | pContext | ) |
Loop to receive packets from the transport interface. Does not handle keep alive.
[in] | pContext | Initialized and connected MQTT context. |
Example
uint16_t MQTT_GetPacketId | ( | MQTTContext_t * | pContext | ) |
Get a packet ID that is valid according to the MQTT 3.1.1 spec.
[in] | pContext | Initialized MQTT context. |
MQTTStatus_t MQTT_MatchTopic | ( | const char * | pTopicName, |
const uint16_t | topicNameLength, | ||
const char * | pTopicFilter, | ||
const uint16_t | topicFilterLength, | ||
bool * | pIsMatch | ||
) |
A utility function that determines whether the passed topic filter and topic name match according to the MQTT 3.1.1 protocol specification.
[in] | pTopicName | The topic name to check. |
[in] | topicNameLength | Length of the topic name. |
[in] | pTopicFilter | The topic filter to check. |
[in] | topicFilterLength | Length of topic filter. |
[out] | pIsMatch | If the match is performed without any error, that is if the return value is MQTTSuccess, then and only then the value in this parameter is valid and updated. In such a case, if the topic filter and the topic name match, then this value is set to true; otherwise if there is no match then it is set to false. |
Example
MQTTStatus_t MQTT_GetSubAckStatusCodes | ( | const MQTTPacketInfo_t * | pSubackPacket, |
uint8_t ** | pPayloadStart, | ||
size_t * | pPayloadSize | ||
) |
Parses the payload of an MQTT SUBACK packet that contains status codes corresponding to topic filter subscription requests from the original subscribe packet.
Each return code in the SUBACK packet corresponds to a topic filter in the SUBSCRIBE Packet being acknowledged. The status codes can be one of the following:
[in] | pSubackPacket | The SUBACK packet whose payload is to be parsed. |
[out] | pPayloadStart | This is populated with the starting address of the payload (or return codes for topic filters) in the SUBACK packet. |
[out] | pPayloadSize | This is populated with the size of the payload in the SUBACK packet. It represents the number of topic filters whose SUBACK status is present in the packet. |
Example
const char * MQTT_Status_strerror | ( | MQTTStatus_t | status | ) |
Error code to string conversion for MQTT statuses.
[in] | status | The status to convert to a string. |
size_t MQTT_GetBytesInMQTTVec | ( | MQTTVec_t * | pVec | ) |
Get the bytes in a MQTTVec pointer which can store the whole array as a an MQTT packet when calling MQTT_SerializeMQTTVec( void * pAllocatedMem, MQTTVec_t *pVec ) function.
[in] | pVec | The MQTTVec pointer. |
void MQTT_SerializeMQTTVec | ( | uint8_t * | pAllocatedMem, |
MQTTVec_t * | pVec | ||
) |
Serialize the bytes in an array of MQTTVec in the provided pAllocatedMem
.
[in] | pAllocatedMem | Memory in which to serialize the data in the MQTTVec array. It must be of size provided by MQTT_GetBytesInMQTTVec( MQTTVec_t *pVec ). |
[in] | pVec | The MQTTVec pointer. |