To set property values for multiple devices at the same time, use the batch property setting task feature of IoT Platform. This topic describes how to create the task, the topics and data formats used during its execution, and how to view its status.
Prerequisites
- A TSL model property has been added to the product to which the devices belong. The devices must have the same property identifier. For more information, see Add a TSL model.
- The devices have been programmed to set TSL model properties. For more information, see Set properties of a TSL model.
Workflow
- Create a batch property setting task.
- In the IoT Platform console, navigate to your instance. In the left-side navigation pane, choose . On the Tasks page, click Create Task.
- On the Create Task page, configure the task and sub-tasks. You can click the help icon next to a parameter name for more information.
- Task configuration
Parameter Description Task Name Enter a custom name for the task that complies with the naming conventions. Task Type Select Batch Property Setting Task. Task Description Enter a description, such as the purpose of the task. This helps you identify different tasks. Target Device, Product, or Group Select the target devices for the task. You can select them by device, product, or group.Important If you select devices by group, you cannot select a dynamic group.Task Execution Rules for Devices Upload a rule file in .jsonformat. The file size cannot exceed 64 KB.You can click Download Template to obtain a rule file template.
For example, a TSL model property of a product is Temperature. The identifier is temperature, and the data type is double. The following code provides an example:
{ "params": { "temperature": 30.5 } }- params: the parameters for setting properties. Multiple properties can be included.
- temperature and 30.5: the property identifier and its value. You can view the property identifier on the Define Feature tab of the product in the IoT Platform console.
For the property
temperatureunder a custom moduletestFb(not a default module), the parameter is"testFb:temperature":30.5.
- Sub-task configuration
Parameter Description Sub-task Execution Rate Specify the number of sub-tasks to push per minute. This parameter is required. Sub-task Execution Timeout This parameter applies only to custom tasks. You do not need to configure it. Sub-task Start Time This parameter is optional. The time is relative to when you configure this setting.
After a task is created, it is initialized and waits for the scheduled time to start.
- Task configuration
- Click Complete.
- After the task is created, IoT Platform calls the SetDeviceProperty or SetDevicesProperty API operation to send property setting commands to the devices. The devices then return responses to IoT Platform.
Data format (mobile terminated)
Request and response topics
Pass-through/custom
-
Request topic:
/sys/${productKey}/${deviceName}/thing/model/down_raw -
Response topic:
/sys/${productKey}/${deviceName}/thing/model/down_raw_reply
Alink JSON
-
Request topic:
/sys/${productKey}/${deviceName}/thing/service/property/set -
Response topic:
/sys/${productKey}/${deviceName}/thing/service/property/set_reply
The following code shows a sample message:
{ "id": "123", "version": "1.0", "params": { "temperature": "30.5" }, "method": "thing.service.property.set" }The params field contains the same data as the params field in the task rule file.
For more information about the Alink protocol for setting device properties, see Set device properties.
-
- On the page for your instance, view the created tasks and their current status.
Important A task with a status of timed out cannot be scheduled for execution again.
The timer starts when the task is created. If not all sub-tasks are completed within seven days, the task status changes to timed out.
You can perform the following operations:
- Cancel a task that is in the processing state.
- Click View next to a task to open its details page, where you can view task information and sub-task execution statistics.
Tab Description Task Information You can view task information, modify the task description and sub-task configuration, and download the device task file. Task Summary You can view statistics on sub-tasks grouped by status. -
Click View next to a device to go to its Device Details page:
- On the Task tab, view the list of all tasks for the device.
- On the Device Log tab, click Go to View. On the cloud run log tab, select cloud-to-device message from the workload type drop-down list to view device task logs.
- If a sub-task failed, click Execution Details to view the cause of failure.
- If a sub-task is in the timed out or failed state, click the corresponding status button to view the list of sub-tasks in that state.
You can click Rerun above the list to re-execute all sub-tasks that timed out or failed for the current task.
-
Click View next to a device to go to its Device Details page:
- Click Delete next to the target task, then click OK.Warning After you delete a device task, all related data is cleared. If any services depend on this task, they may become unavailable or your business may be affected. Proceed with caution.