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.
The Resource Access Management (RAM) users of an Alibaba Cloud account share the quota of the account.
Debugging
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
|
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: 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:
|
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
For more information, see Overview. |
Qos | Integer | No | 0 | The quality of service (QoS) level of the message. Valid values:
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:
|
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.