Create a batch message push task

Updated at:

Use a batch message task in IoT Platform to send custom topic messages to multiple devices simultaneously.This topic describes how to create the task, the required topic and data format, and how to check the task status.

Prerequisites

Procedure

  1. Create a task.
    1. In the IoT Platform console, navigate to your instance. In the left-side navigation pane, choose Maintenance > Tasks. On the Tasks page, click Create Task.
    2. On the Create Task page, configure the parameters for the task and the job. For help with a specific parameter, click the help icon next to its name. When you are finished, click Done.
      • Task configuration
        Parameter Description
        Task name Enter a task name that meets the naming rules.
        Task type Select Pub Batch Message Push Task.
        Task description Enter a description for the task.
        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. Only .json files are supported. The file size cannot exceed 64 KB.

        You can click Download Template to obtain a rule file template.

        For example, if the custom topic for multiple devices is /${productKey}/${deviceName}/user/get, the code looks like this:

        {
            "topicShortName": "get",
            "messageContent": "eyJ0ZXN0IjoidGFzayBiYXRjaHB1YiBicm9hZGNhc3QifQ=="
        }
        • topicShortName: Defines the full custom topic, which follows the format /${productKey}/${deviceName}/user/${topicShortName}. For the topic /${productKey}/${deviceName}/user/get, the value of topicShortName is get.
        • messageContent: The content of the message to be sent. You must convert the original message to binary data and then Base64-encode the data to generate the message content.
      • Job configuration
        Parameter Description
        Job execution push configuration
        • Jobs per minute: Set the number of jobs to push per minute.
        • Push message type: This parameter applies only to custom tasks and Pub Batch Message Push tasks.

          Valid values:

          • QoS 0: At-most-once delivery.
          • QoS 1: At-least-once delivery. If a PUBACK message is not received for a QoS 1 message, IoT Platform resends the message to the device when it reconnects.
        Job execution timeout configuration Optional. If you do not set a timeout, the job does not time out. This setting applies only to custom tasks.

        The timeout countdown starts when the job enters the In Progress state. If a job does not complete before the timeout period ends, its status is automatically set to Timed Out, and the job stops running.

        Job start time
        Optional.

        The time is calculated from when you configure this parameter.

        After a device task is created, it is initialized but does not start executing until the scheduled start time is reached.

  2. After the task is created, IoT Platform calls the Pub API to send messages to the target devices. The devices then send responses back to IoT Platform.
    The custom message topic is /${productKey}/${deviceName}/user/${topicShortName}. The data format is user-defined.
  3. On the Maintenance > Tasks 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 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.