All Products
Search
Document Center

IoT Platform:BatchPub

更新時間:Jan 15, 2024

Sends a message to multiple devices of a product at a time by using a custom topic.

Usage notes

  • You can call this operation to send a message to a maximum of 100 devices of a product at a time.
  • The BatchPub operation cannot be used to send commands of configuring properties or calling services. If you want to configure properties, call the SetDeviceProperty or SetDevicesProperty operation. If you want to call services, call the InvokeThingService or InvokeThingsService operation.

QPS limits

You can call this operation up to 50 times per second per account.

Note

The Resource Access Management (RAM) users of an Alibaba Cloud account share the quota of the account.

Debugging

OpenAPI Explorer automatically calculates the signature value. For your convenience, we recommend that you call this operation in OpenAPI Explorer. OpenAPI Explorer dynamically generates the sample code of the operation for different SDKs.

Request parameters

Parameter

Type

Required

Example

Description

Action String Yes BatchPub

The operation that you want to perform. Set the value to BatchPub.

DeviceName.N RepeatList Yes newdevice1

The DeviceName of the device to which you want to send the message.

Note

  • This parameter is used together with the ProductKey parameter. The specified devices must belong to the same product.

  • You can specify a maximum of 100 device names in a single request. Each device name must be unique.
MessageContent String Yes eyJ0ZXN0IjoidGFzayBiYXRjaHB1YiBicm9hZGNhc3QifQ==

The body of the message that you want to send. The maximum size of a message is 256 KB.

To generate a message body, convert the raw message into binary data and perform Base64 encoding.

Note

IoT Platform decodes data by using the Base64 algorithm and then sends the decoded message to the device. This way, the device does not need to decode the Base64-encoded data.

ProductKey String Yes a1BwAGV****

The ProductKey of the product to which the device belongs.

TopicShortName String Yes get

The suffix of the custom topic. The name of a custom topic is in the following format: /${productKey}/${deviceName}/user/${TopicShortName}. ${TopicShortName} specifies the suffix.

Note

You must specify the Subscribe permission or the Publish and Subscribe permissions for the topic. Make sure that all the specified devices subscribe to the topic.

You can use the following methods to view custom topics:

  • On the Topic Categories tab of the Product Details page, view the custom topics of the product.
  • On the Topic List tab of the Device Details page, view the custom topics to which the device has subscribed.
  • Call the QueryProductTopic operation to query the custom topics of the product.
IotInstanceId String No iot-cn-0pp1n8t****

The instance ID. You can obtain the ID of the instance on the Overview page in the IoT Platform console.

Important

  • If your instance has an ID, you must specify this parameter. Otherwise, the request fails.
  • If the Overview page or the instance ID is not displayed in the IoT Platform console, you do not need to specify this parameter.

For more information, see Overview.

Qos Integer No 0

The quality of service (QoS) level of the message. Valid values:

  • 0: The system sends the message at most once.
  • 1: The system sends the message at least once.

Default value: 0.

Note

IoT Platform stores messages whose QoS level is 1 for up to seven days. IoT Platform does not store messages whose QoS level is 0.

In addition to the preceding operation-specific request parameters, you must specify common request parameters when you call this operation. For more information, see Common parameters.

Response parameters

Parameter

Type

Example

Description

Code String iot.system.SystemException

The error code returned if the request failed. For more information, see Error codes.

ErrorMessage String A system exception occurred.

The error message returned if the request failed.

RequestId String E55E50B7-40EE-4B6B-8BBE-D3ED55CCF565

The request ID.

Success Boolean true

Indicates whether the request was successful. Valid values:

  • true
  • false

Examples

Sample requests

http(s)://iot.cn-shanghai.aliyuncs.com/?Action=BatchPub
&DeviceName.1=newdevice1
&MessageContent=eyJ0ZXN0IjoidGFzayBiYXRjaHB1YiBicm9hZGNhc3QifQ==
&ProductKey=a1BwAGV****
&TopicShortName=get
&<Common request parameters>

Sample success responses

XML format

<BatchPubResponse>
  <RequestId>9E76053E-26ED-4AB4-AE58-8AFC3F1E7E8E</RequestId>
  <Success>true</Success>
</BatchPubResponse>

JSON format

{
  "RequestId": "9E76053E-26ED-4AB4-AE58-8AFC3F1E7E8E",
  "Success": true
}

Error codes

For a list of error codes, see Service error codes.