All Products
Search
Document Center

IoT Platform:Device jobs

Last Updated:Oct 31, 2024

Alibaba Cloud's IoT Platform offers configuration and management services for device jobs. It utilizes the Alink protocol for both device batch service invocation tasks and device batch property setting tasks. This topic outlines the customization of the task update message topic and Alink data format, including the updating of device job status, device requests for the latest job information, and subtask status updates.

Background information

  • To implement custom tasks, you must develop task management capabilities on the device side. For detailed operations, refer to Device Jobs.

  • For device batch service invocation tasks and device batch property setting tasks, if the device-side Link SDK has integrated service invocation and property setting functions, there is no need to develop additional task management capabilities to execute device jobs.

    For methods on integrating service invocation and property setting functions into the device-side Link SDK, see the Thing Specification Language development methods for the respective Link SDK in Device Access Overview.

    For an explanation of the Alink protocol used for service invocation and property setting, see Device Properties, Events, and Services.

Device job status update notification

Note

Notifications are sent to the device only when the device job status changes to in progress, canceled, or deleted.

Downstream.

Topic: /sys/${productKey}/${deviceName}/thing/job/notify.

Sample request in Alink JSON format:

{
    "id": "7542940",
    "version": "1.0",
    "params": {
        "task": {
            "taskId": "i5Ks6***pF010101",
            "status": "SENT",
            "jobDocument": {},
            "jobFile":{
                "signMethod":"Md5",
                "sign":"wssxff56dhdsd***",
                "fileUrl": "https://iotx-***.oss-cn-shanghai.aliyuncs.com/***.zip"
            }
        }
    }
}

Table 1. Request Parameter Description

Parameter

Type

Description

id

String

The ID of the message. Valid values: 0 to 4294967295. Each message ID must be unique for the current device.

version

String

The version of the protocol. Set this parameter to 1.0.

params

Object

The list of request parameters.

task

Object

Parameters of the subtask.

taskId

String

The ID of the subtask, which is a globally unique identifier.

status

String

The status of the subtask.

  • SENT: Scheduled.

  • REMOVED: Deleted.

  • CANCELLED: Canceled.

jobDocument

Object

The job document that describes the task execution rules.

Note

If status is REMOVED or CANCELLED, this field is empty.

jobFile

Object

The file information uploaded when creating a custom task.

  • signMethod: The signature method. Currently supports Md5 and Sha256.

  • sign: The signature parameter generated according to the corresponding signature method.

  • fileUrl: The download URL of the task file, valid for 1 hour.

Note

```html

If status is REMOVED or CANCELLED, this field is empty.

Sample response in Alink JSON format:

{
    "id": "7542940",
    "code": 200,
    "data": {}
}

Table 2. Response Parameter Description

Parameter

Type

Description

id

String

The ID of the message. Valid values: 0 to 4294967295. Each message ID must be unique for the current device.

code

Integer

The HTTP status code in the response. The value 200 indicates that the request was successful. Other values indicate the request failed. For more information, see Common codes returned by devices.

data

Object

The data returned by the device. The result data returned by the device job update notification is empty.

Get device job details

Upstream.

  • Request topic: /sys/${productKey}/${deviceName}/thing/job/get.

  • Response topic: /sys/${productKey}/${deviceName}/thing/job/get_reply.

Sample request in Alink JSON format:

{
    "id": "123",
    "version": "1.0",
    "params": {
        "taskId": "i5Ks***F010101"
    }
}

Table 3. Request Parameter Description

Parameter

Type

Description

id

String

The ID of the message. Valid values: 0 to 4294967295. Each message ID must be unique for the current device.

version

String

The version of the protocol. Set this parameter to 1.0.

params

Object

The list of request parameters.

taskId

String

Three value methods can return task information with different statuses.

  • The ID of the subtask: Returns detailed information about the task corresponding to the job ID.

  • $next: Returns information about an executable task.

  • $list: Returns a list of executable tasks, with a maximum of 10 by default.

taskId values differ, and the Alink response data format differs.

  • taskId is the ID of the subtask:

    {
        "id": "1234",
        "code": 200,
        "data": {
            "statusDetails":{"devs":"test","status":"init"},
            "taskId": "i5Ks***F010101",
            "task":{
                "taskId": "i5Ks***F010101",
                "status": "IN_PROGRESS",
                "jobDocument": {},
                "jobFile":{
                    "signMethod":"Md5",
                    "sign":"wssxff56dhdsd***",
                    "fileUrl": "https://iotx-***.oss-cn-shanghai.aliyuncs.com/***.zip"
                }
            }
        }
    }
  • taskId is $next:

    {
        "id": "1234",
        "code": 200,
        "data": {
            "statusDetails":{"devs":"test","status":"init"},
            "taskId": "$next",
            "task":{
                "taskId": "i5Ks***F010101",
                "status": "IN_PROGRESS",
                "jobDocument": {},
                "jobFile":{
                    "signMethod":"Md5",
                    "sign":"wssxff56dhdsd***",
                    "fileUrl": "https://iotx-***.oss-cn-shanghai.aliyuncs.com/***.zip"
                }
            }
        }
    }
  • taskId is $list:

    {
        "id": "1234",
        "code": 200,
        "data": {
            "statusDetails":{"devs":"test","status":"init"},
            "taskId": "$list",
            "task":[
                {
                    "taskId": "i5Ks***",
                    "status": "IN_PROGRESS"
                },
                {
                    "taskId": "i61s***",
                    "status": "IN_PROGRESS"
                }
            ]
        }
    }

Table 4. Response Parameter Description

Parameter

Type

Description

id

String

The ID of the message. Valid values: 0 to 4294967295. Each message ID must be unique for the current device.

code

Integer

The HTTP status code in the response. The value 200 indicates that the request was successful. Other values indicate the request failed. For more information, see Common codes returned by devices.

data

Object

The data returned by the device.

task

Object

Parameters of the subtask.

taskId

String

The ID of the subtask, which is a globally unique identifier.

status

String

The status of the subtask.

  • QUEUED: Queued.

  • SENT: Scheduled.

  • IN_PROGRESS: In progress.

  • TIMED_OUT: Timed out.

  • FAILED: Failed.

  • SUCCEEDED: Succeeded.

  • CANCELLED: Canceled.

  • REJECTED: Rejected.

statusDetails

JSON

User-defined configuration when creating a task on the device.

jobDocument

Object

The job document that describes the task execution rules.

jobFile

Object

The file information uploaded when creating a custom task.

  • signMethod: The signature method. Currently supports Md5 and Sha256.

  • sign: The signature parameter generated according to the corresponding signature method.

  • fileUrl: The download URL of the task file, valid for 1 hour.

Update subtask status

Upstream.

  • Request topic: /sys/${productKey}/${deviceName}/thing/job/update.

  • Response topic: /sys/${productKey}/${deviceName}/thing/job/update_reply.

Sample request in Alink JSON format:

{
    "id": "123",
    "version": "1.0",
    "params": {
        "taskId": "i5Ks***F010101",
        "status": "IN_PROGRESS",
        "statusDetails": {
            "key": "value"
        },
        "progress": 50
    }
}

Table 5. Request Parameter Description

Parameter

Type

Description

id

String

The ID of the message. Valid values: 0 to 4294967295. Each message ID must be unique for the current device.

version

String

The version of the protocol. Set this parameter to 1.0.

params

Object

The list of request parameters.

taskId

String

The ID of the subtask, which is a globally unique identifier.

status

String

The status of the subtask. Valid values:

  • SUCCEEDED: Successfully completed.

  • FAILED: Execution failed.

  • IN_PROGRESS: Currently being executed.

  • REJECTED: Rejected execution.

statusDetails

Object

Customizable user-defined status details. These can be viewed on the Device Management > Tasks > Task Details page in the IoT Platform console.

progress

Integer

The execution progress percentage of the subtask.

Sample response in Alink JSON format:

{
    "id":"123",
    "code":200,
    "data":{
        "taskId":"i5Ks***F010101"
    }
}

Table 6. Response Parameter Description

Parameter

Type

Description

id

String

The ID of the message. Valid values: 0 to 4294967295. Each message ID must be unique for the current device.

code

Integer

The HTTP status code in the response. The value 200 indicates that the request was successful. Other values indicate the request failed. For more information, see Common codes returned by devices.

data

Object

The data returned by the device.

taskId

String

The ID of the subtask, which is a globally unique identifier.