AWS IoT Device Shadow  v1.0.1
AWS IoT Device Shadow client library
Shadow_GetTopicString

Assemble shadow topic string when Thing Name is only known at run time. If the Thing Name is known at compile time, use SHADOW_TOPIC_STRING_* macros instead.

const char * pThingName,
uint8_t thingNameLength,
char * pTopicBuffer,
uint16_t bufferSize,
uint16_t * pOutLength );
Parameters
[in]topicTypeIndicates what topic will be written into the buffer pointed to by pTopicBuffer. can be one of:
  • ShadowTopicStringTypeGet
  • ShadowTopicStringTypeGetAccepted
  • ShadowTopicStringTypeGetRejected
  • ShadowTopicStringTypeDelete
  • ShadowTopicStringTypeDeleteAccepted
  • ShadowTopicStringTypeDeleteRejected
  • ShadowTopicStringTypeUpdate
  • ShadowTopicStringTypeUpdateAccepted
  • ShadowTopicStringTypeUpdateRejected
  • ShadowTopicStringTypeUpdateDocuments
  • ShadowTopicStringTypeUpdateDelta
[in]pThingNameThing Name string. No need to be null terminated. Must not be NULL.
[in]thingNameLengthLength of Thing Name string pointed to by pThingName. Must not be zero.
[out]pTopicBufferPointer to buffer for returning the topic string. Caller is responsible for supplying memory pointed to by pTopicBuffer. This function does not fill in the terminating null character. The app can supply a buffer that does not have space for holding the null character.
[in]bufferSizeLength of pTopicBuffer. This function will return error if bufferSize is less than the length of the assembled topic string.
[out]pOutLengthPointer to caller-supplied memory for returning the length of the topic string.
Returns
One of the following:
  • SHADOW_SUCCESS if successful.
  • An error code if failed to assemble.

Example

// Variables used in this example.
#define SHADOW_TOPIC_MAX_LENGTH ( 256U )
ShadowStatus_t shadowStatus = SHADOW_STATUS_SUCCESS;
char topicBuffer[ SHADOW_TOPIC_MAX_LENGTH ] = { 0 };
uint16_t bufferSize = SHADOW_TOPIC_MAX_LENGTH;
uint16_t outLength = 0;
const char * pThingName = "TestThingName";
uint16_t thingNameLength = ( sizeof( thingName ) - 1U );
shadowStatus = Shadow_GetTopicString( SHADOW_TOPIC_STRING_TYPE_UPDATE_DELTA,
pThingName,
thingNameLength,
& ( topicBuffer[ 0 ] ),
bufferSize,
& outLength );
if( shadowStatus == SHADOW_STATUS_SUCCESS )
{
// The assembled topic string is put in pTopicBuffer with the length outLength.
}
ShadowTopicStringType_t
ShadowTopicStringType_t
Each of these values describes the type of a shadow topic string.
Definition: shadow.h:74
ShadowStatus_t
ShadowStatus_t
Return codes from Shadow functions.
Definition: shadow.h:94
Shadow_GetTopicString
ShadowStatus_t Shadow_GetTopicString(ShadowTopicStringType_t topicType, const char *pThingName, uint8_t thingNameLength, char *pTopicBuffer, uint16_t bufferSize, uint16_t *pOutLength)
Assemble shadow topic string when Thing Name is only known at run time. If the Thing Name is known at...
Definition: shadow.c:536