AWSIoTPythonSDK — AWSIoTPythonSDK 1.4.0 documentation

Bases: AWSIoTPythonSDK.MQTTLib._AWSIoTMQTTDelegatingClient

The client class that specializes in handling jobs messages and accesses its functionality in AWS IoT over MQTT v3.1/3.1.1.

It delegates to the AWS IoT MQTT Client and exposes jobs related operations. It shares the same connection types, synchronous MQTT operations and partial on-top features with the AWS IoT MQTT Client:

  • Auto reconnect/resubscribe

Same as AWS IoT MQTT Client.

  • Progressive reconnect backoff

Same as AWS IoT MQTT Client.

  • Offline publish requests queueing with draining

Same as AWS IoT MQTT Client

Syntax

import AWSIoTPythonSDK.MQTTLib as AWSIoTPyMQTT# Create an AWS IoT MQTT Jobs Client using TLSv1.2 Mutual AuthenticationmyAWSIoTMQTTJobsClient = AWSIoTPyMQTT.AWSIoTMQTTThingJobsClient("testIoTPySDK")# Create an AWS IoT MQTT Jobs Client using Websocket SigV4myAWSIoTMQTTJobsClient = AWSIoTPyMQTT.AWSIoTMQTTThingJobsClient("testIoTPySDK", useWebsocket=True)

Parameters

clientID - String that denotes the client identifier and client token for jobs requests If empty string is provided, client id for this connection will be randomly generated on server side. If an awsIotMQTTClient is specified, this will not override the client ID for the existing MQTT connection and only impact the client token for jobs request payloads

thingName - String that represents the thingName used to send requests to proper topics and subscribe to proper topics.

QoS - QoS used for all requests sent through this client

awsIoTMQTTClient - An instance of AWSIoTMQTTClient to use if not None. If not None, clientID, protocolType, useWebSocket, and cleanSession parameters are not used. Caller is expected to invoke connect() prior to calling the pub/sub methods on this client.

protocolType - MQTT version in use for this connection. Could be AWSIoTPythonSDK.MQTTLib.MQTTv3_1 or AWSIoTPythonSDK.MQTTLib.MQTTv3_1_1

useWebsocket - Boolean that denotes enabling MQTT over Websocket SigV4 or not.

Returns

AWSIoTPythonSDK.MQTTLib.AWSIoTMQTTJobsClient object

createJobSubscription(callback, jobExecutionType=(7, False, '+'), jobReplyType=(1, ''), jobId=None)

Description

Synchronously creates an MQTT subscription to a jobs related topic based on the provided arguments

Syntax

Parameters

callback - Function to be called when a new message for the subscribed job topic comes in. Should be in form customCallback(client, userdata, message), wheremessage contains topic and payload. Note that client and userdata are here just to be aligned with the underneath Paho callback function signature. These fields are pending to be deprecated and should not be depended on.

jobExecutionType - Member of the jobExecutionTopicType class specifying the jobs topic to subscribe to Defaults to jobExecutionTopicType.JOB_WILDCARD_TOPIC

jobReplyType - Member of the jobExecutionTopicReplyType class specifying the (optional) reply sub-topic to subscribe to Defaults to jobExecutionTopicReplyType.JOB_REQUEST_TYPE which indicates the subscription isn’t intended for a jobs reply topic

jobId - JobId string if the topic type requires one. Defaults to None

Returns

True if the subscribe attempt succeeded. False if failed.

createJobSubscriptionAsync(ackCallback, callback, jobExecutionType=(7, False, '+'), jobReplyType=(1, ''), jobId=None)

Description

Asynchronously creates an MQTT subscription to a jobs related topic based on the provided arguments

Syntax

Parameters

ackCallback - Callback to be invoked when the client receives a SUBACK. Should be in formcustomCallback(mid, data), where mid is the packet id for the disconnect request anddata is the granted QoS for this subscription.

callback - Function to be called when a new message for the subscribed job topic comes in. Should be in form customCallback(client, userdata, message), wheremessage contains topic and payload. Note that client and userdata are here just to be aligned with the underneath Paho callback function signature. These fields are pending to be deprecated and should not be depended on.

jobExecutionType - Member of the jobExecutionTopicType class specifying the jobs topic to subscribe to Defaults to jobExecutionTopicType.JOB_WILDCARD_TOPIC

jobReplyType - Member of the jobExecutionTopicReplyType class specifying the (optional) reply sub-topic to subscribe to Defaults to jobExecutionTopicReplyType.JOB_REQUEST_TYPE which indicates the subscription isn’t intended for a jobs reply topic

jobId - JobId of the topic if the topic type requires one. Defaults to None

Returns

Subscribe request packet id, for tracking purpose in the corresponding callback.

sendJobsQuery(jobExecTopicType, jobId=None)

Description

Publishes an MQTT jobs related request for a potentially specific jobId (or wildcard)

Syntax

Parameters

jobExecutionType - Member of the jobExecutionTopicType class that correlates the jobs topic to publish to

jobId - JobId string if the topic type requires one. Defaults to None

Returns

True if the publish request has been sent to paho. False if the request did not reach paho.

sendJobsStartNext(statusDetails=None)

Description

Publishes an MQTT message to the StartNextJobExecution topic. This will attempt to get the next pending job execution and change its status to IN_PROGRESS.

Syntax

Parameters

statusDetails - Dictionary containing the key value pairs to use for the status details of the job execution

Returns

True if the publish request has been sent to paho. False if the request did not reach paho.

sendJobsUpdate(jobId, status, statusDetails=None, expectedVersion=0, executionNumber=0, includeJobExecutionState=False, includeJobDocument=False)

Description

Publishes an MQTT message to a corresponding job execution specific topic to update its status according to the parameters. Can be used to change a job from QUEUED to IN_PROGRESS to SUCEEDED or FAILED.

Syntax

Parameters

jobId - JobID String of the execution to update the status of

status - job execution status to change the job execution to. Member of jobExecutionStatus

statusDetails - new status details to set on the job execution

expectedVersion - The expected current version of the job execution. IoT jobs increments expectedVersion each time you update the job execution. If the version of the job execution stored in Jobs does not match, the update is rejected with a VersionMismatch error, and an ErrorResponse that contains the current job execution status data is returned. (This makes it unnecessary to perform a separate DescribeJobExecution request n order to obtain the job execution status data.)

executionNumber - A number that identifies a particular job execution on a particular device. If not specified, the latest job execution is used.

includeJobExecutionState - When included and set to True, the response contains the JobExecutionState field. The default is False.

*includeJobDocument - When included and set to True, the response contains the JobDocument. The default is False.

Returns

True if the publish request has been sent to paho. False if the request did not reach paho.

sendJobsDescribe(jobId, executionNumber=0, includeJobDocument=True)

Description

Publishes a method to the describe topic for a particular job.

Syntax

Parameters

jobId - jobID to describe. This is allowed to be a wildcard such as ‘$next’

executionNumber - A number that identifies a particular job execution on a particular device. If not specified, the latest job execution is used.

includeJobDocument - When included and set to True, the response contains the JobDocument.

Returns

True if the publish request has been sent to paho. False if the request did not reach paho.

You Might Also Like