AWS IoT Device Shadow  v1.0.0
AWS IoT Device Shadow client library
Shadow_MatchTopic

Given the topic string of an incoming message, determine whether it is related to a device shadow; if it is, return information about the type of device shadow message, and a pointer to the Thing Name inside of the topic string. See ShadowMessageType_t for the list of message types. Those types correspond to Device Shadow Topics.

ShadowStatus_t Shadow_MatchTopic( const char * pTopic,
uint16_t topicLength,
ShadowMessageType_t * pMessageType,
const char ** pThingName,
uint16_t * pThingNameLength );
Note
When this function returns, the pointer pThingName points at the first character of the <thingName> segment inside of the topic string. Caller is responsible for keeping the memory holding the topic string around while accessing the Thing Name through pThingName.
Parameters
[in]pTopicPointer to the MQTT topic string. Does not have to be null-terminated.
[in]topicLengthLength of the MQTT topic string.
[out]pMessageTypePointer to caller-supplied memory for returning the type of the shadow message.
[out]pThingNamePoints to the 1st character of Thing Name inside of the topic string, and can be null if caller does not need to know the Thing Name contained in the topic string.
[out]pThingNameLengthPointer to caller-supplied memory for returning the length of the Thing Name, and can be null if caller does not need to know the Thing Name contained in the topic string.
Returns
One of the following:
  • SHADOW_SUCCESS if the message is related to a device shadow;
  • An error code defined in ShadowStatus_t if the message is not related to a device shadow, if any input parameter is invalid, or if the function fails to parse the topic string.

Example

// Variables used in this example.
#define SHADOW_TOPIC_MAX_LENGTH ( 256U )
ShadowStatus_te shadowStatus = SHADOW_STATUS_SUCCESS;
char * pTopicName; //usually supplied by MQTT stack
uint16_t topicNameLength; //usually supplied by MQTT stack
ShadowMessageType_t messageType;
shadowStatus = Shadow_MatchTopic( pTopicName,
topicNameLength,
& messageType,
NULL,
NULL );
if( shadowStatus == SHADOW_STATUS_SUCCESS )
{
// It is a device shadow message. And the type of the message has been returned in messageType.
// Now we can act on the message.
}
ShadowMessageType_t
ShadowMessageType_t
Each of these values describes the type of a shadow message. https://docs.aws.amazon....
Definition: shadow.h:54
ShadowStatus_t
ShadowStatus_t
Return codes from Shadow functions.
Definition: shadow.h:94
Shadow_MatchTopic
ShadowStatus_t Shadow_MatchTopic(const char *pTopic, uint16_t topicLength, ShadowMessageType_t *pMessageType, const char **pThingName, uint16_t *pThingNameLength)
Given the topic string of an incoming message, determine whether it is related to a device shadow; if...
Definition: shadow.c:430