To simultaneously send custom topic messages to multiple devices, utilize the IoT Platform's batch message delivery job. This topic outlines the creation of the job, the operation's topics and their data formats, and the procedures to monitor the job status.
Prerequisites
You have added a custom topic with Subscribe or Subscribe And Publish permissions for the device on the IoT Platform. For more information, see using custom topic communication.
You have successfully subscribed to the custom topic on the device and have not unsubscribed. For more information, see Link SDK's subscribe topic.
Task management process
Create a Pub service task.
- In the IoT Platform console, find the instance that you want to manage and click the instance name. In the left-side navigation pane of the Instance Details page, choose . On the Tasks page, click Create Task.
Navigate to the Create Task page, click the help icon
next to parameter names, configure the task and job as prompted, and select Complete.Task Configuration
Parameter
Description
Task Name
Enter a valid task name.
Task Type
Choose the type: Pub Batch Message Push Task.
Task Description
Provide details such as the task's purpose to facilitate identification.
Destination Device, Product, or Group
Select the devices for which you want to execute the task. You can select separate devices, devices by product, or devices by 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, ensuring the file size does not exceed 64 KB.You can click Download Template to obtain a rule template.
For instance, for multiple devices, the custom topic is:
/${productKey}/${deviceName}/user/get. An example code snippet is:{ "topicShortName": "get", "messageContent": "eyJ0ZXN0IjoidGFzayBiYXRjaHB1YiBicm9hZGNhc3QifQ==" }topicShortName: Defines the complete custom topic:
/${productKey}/${deviceName}/user/${topicShortName}. For example, the value of/${productKey}/${deviceName}/user/gettopicShortName for the topicgetis .messageContent: The message body to be sent, which must be converted to binary data and encoded in Base64.
Job Configuration
Parameter
Description
Job Execution Push Configuration
Adjust the number of jobs pushed per minute to suit your business requirements.
Set the Number Of Jobs Executed Per Minute according to your operational needs.
Choose the Push Message Type for custom tasks and Pub batch message push tasks.
Options include:
QoS0: Delivers the message at most once.
QoS1: Ensures delivery at least once. If a PUBACK response is not received after sending a QoS 1 message, the message will be resent to the device upon reconnection to the IoT Platform.
Job Execution Timeout Configuration
This optional parameter allows you to set a timeout for device tasks. If not set, tasks will not time out. This is applicable only to custom tasks.
The timer starts when the device task enters the IN_PROGRESS state. If the task exceeds the set timeout without completion, the job status changes to TIMED_OUT, and the job execution ceases.
Upon task creation, the IoT Platform dispatches messages to multiple devices using the Pub API, which then prompts the devices to return response results to the IoT Platform.
The custom message topic follows the pattern
/${productKey}/${deviceName}/user/${TopicShortName}, with a user-defined data format.- In the IoT Platform console, find the instance to which the task belongs and click the instance name. On the Instance Details page, choose . On the Tasks page, you can view the relevant details, including the status of the task that you created. Important If a task is in the Timed Out state, the task can no longer be executed based on the specified schedule.
If the sub-tasks of a task fail to be executed within seven days after the time when the task was created, the task enters the Timed Out state.
You can perform one of the following operations based on your business requirements:
- On the Tasks page, cancel a task that is in the Processing state.
- Find the task that you want to manage and click View in the Actions column. On the task details page, view the task information and task statistics.
Tab Description Task Information You can view the task information, modify the task description and task configuration, and download the rule file. Task Summary You can view statistics on sub-tasks by status. - Find the device that you want to manage and click View to go to the device details page.
- On the Task tab, you can view all tasks of the device.
- On the Device Log tab, click View. On the Device Log page, click Cloud run log. On the Cloud run log tab, select Cloud-to-device Message from the workload type drop-down list in the search bar to view task-related logs.
- If a sub-task fails to be executed, click Execution details in the Actions column to view the cause of the failure.
- If a sub-task times out or fails to be executed, click Timed Out or Failed in the Status column to view the sub-tasks in the corresponding state.
In the upper part of the Tasks page, click Rerun to re-execute the sub-tasks that are in the Timed Out and Failed states of the current task.
- Find the device that you want to manage and click View to go to the device details page.
- Click Delete in the Actions column of a task. In the message that appears, click OK. Warning After you delete a task, all data that is related to the task is deleted. If business applications run based on the task, the applications may become unavailable and your business may be affected. Proceed with caution.