AWS IoT Jobs v1.5.1
Client library for AWS IoT Jobs
 
Loading...
Searching...
No Matches
Jobs_GetTopic
JobsStatus_t Jobs_GetTopic( char * buffer,
size_t length,
const char * thingName,
uint16_t thingNameLength,
size_t * outLength );
JobsTopic_t
Topic values for subscription requests.
Definition: jobs.h:301
JobsStatus_t
Return codes from jobs functions.
Definition: jobs.h:255
JobsStatus_t Jobs_GetTopic(char *buffer, size_t length, const char *thingName, uint16_t thingNameLength, JobsTopic_t api, size_t *outLength)
Populate a topic string for a subscription request.
Definition: jobs.c:276

Populate a topic string for a subscription request.

Parameters
[in]bufferThe buffer to contain the topic string.
[in]lengthThe size of the buffer.
[in]thingNameThe device's thingName as registered with AWS IoT.
[in]thingNameLengthThe length of the thingName.
[in]apiThe desired Jobs API, e.g., JobsNextJobChanged.
[out]outLengthThe length of the topic string written to the buffer.
Returns
JobsSuccess if the topic was written to the buffer; JobsBadParameter if invalid parameters are passed; JobsBufferTooSmall if the buffer cannot hold the full topic string.

When all parameters are valid, the topic string is written to the buffer up to one less than the buffer size. The topic is ended with a NUL character.

Note
The thingName parameter does not need a NUL terminator.
The AWS IoT Jobs service does not require clients to subscribe to the "/accepted" and "/rejected" response topics for the APIs that accept requests on PUBLISH topics. The Jobs service will send responses to requests from clients irrespective of whether they have subscribed to response topics or not. For more information, refer to the AWS docs here: https://docs.aws.amazon.com/iot/latest/developerguide/jobs-mqtt-api.html

Example

// The following example shows usage of the Jobs_GetTopic API to
// generate topic string for the NextJobExecutionChanged API
// of AWS IoT Jobs service.
// Every device should have a unique thing name registered with AWS IoT Core.
// This example uses a dummy serial number for the thing name.
#define THING_NAME "11223445566"
#define THING_NAME_LENGTH ( sizeof( THING_NAME ) - 1U )
// This example allocates a buffer of maximum length for a Jobs topic
// possible for the thing name using the JOBS_API_MAX_LENGTH macro.
char topicBuffer[ JOBS_API_MAX_LENGTH( THING_NAME_LENGTH ) ] = { 0 };
uint16_t topicLength = 0U;
status = Jobs_GetTopic( topicBuffer,
sizeof( topicBuffer ),
THING_NAME,
THING_NAME_LENGTH,
&( topicLength ) );
if( status == JobsSuccess )
{
// The topic string of length, topicLength, has been
// generated in the buffer, topicBuffer, for the NextJobExecutionChanged API.
// Subscribe to this topic using an MQTT client of your choice.
}
#define JOBS_API_MAX_LENGTH(thingNameLength)
The size needed to hold the longest topic for a given thing name length.
Definition: jobs.h:245
@ JobsSuccess
The buffer was properly written or a match was found.
Definition: jobs.h:257

See jobs.h for docs.