Sends a message to a device.
Usage notes
If you use a device that is connected to IoT Platform over Message Queuing Telemetry Transport (MQTT) by using an MQTT gateway or a GB/T 32960 gateway, you can call the AsyncRRpc operation to send a message from IoT Platform to the device.
QPS limits
You can call this operation up to 1,000 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 | AsyncRRpc | The operation that you want to perform. Set the value to AsyncRRpc. |
DeviceName | String | Yes | device1 | The DeviceName of the device to which you want to send the message. |
ProductKey | String | Yes | aldfeSe**** | The ProductKey of the product to which the device belongs. |
MessageContent | String | Yes | eyJ0ZXN0IjoidGFzayBwdWIgYnJvYWRjYXN0In0= | The body of the message that you want to publish. 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. |
TopicFullName | String | No | /a1uZfYb****/A_Vol****/user/update | The name of the custom topic of the device. If you want to send a message to a device that is connected over MQTT, you must specify this parameter. The device must have the Subscribe or Publish and Subscribe permissions on the topic. If you want to send a message to a device that is connected by using a GB/T 32960 gateway, you do not need to specify this parameter. |
ExtInfo | String | No | {"commandType": 128} | The type of the command in the message. This parameter is required if you want to send a message to a device that is connected by using a GB/T 32960 gateway. Valid values:
For more information about how to connect a device to IoT Platform by using a GB/T 32960 gateway, see GB/T 32960 gateways. |
IotInstanceId | String | No | iot-v64******** | The instance ID. You can view the ID of the instance on the Overview page in the IoT Platform console. Important
For more information, see Overview. |
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.device.InvalidFormattedDeviceName | The error code returned if the request failed. For more information, see the Error codes section of this topic. |
ErrorMessage | String | The format of DeviceName is invalid. | The error message returned if the request failed. |
MessageId | Long | 889455942124347392 | The message ID that is generated by IoT Platform when the message is sent. |
RequestId | String | E55E50B7-40EE-4B6B-8BBE-D3ED55CCF565 | The request ID. |
Success | Boolean | true | Indicates whether the request was successful. Valid values:
|
Examples
Sample requests
https://iot.cn-shanghai.aliyuncs.com/?Action=AsyncRRpc
&DeviceName=device1
&MessageContent=dGhpcyBpcyBhbiBleGFtcGxl
&ProductKey=aldfeSe****
&IotInstanceId=iot-v64********
&<Common request parameters>
Sample success responses
XML
format
<AsyncRRpcResponse>
<RequestId>E55E50B7-40EE-4B6B-8BBE-D3ED55CCF565</RequestId>
<Success>true</Success>
<MessageId>889455942124347400</MessageId>
</AsyncRRpcResponse>
JSON
format
{
"RequestId": "E55E50B7-40EE-4B6B-8BBE-D3ED55CCF565",
"Success": true,
"MessageId": 889455942124347400
}
Error codes
HTTP status code |
Error code |
Error message |
Description |
400 | iot.prod.NullProductKey | The ProductKey is empty. | ProductKey is left empty. |
400 | iot.prod.InvalidFormattedProductkey | The ProductKey format is incorrect. | The value of the ProductKey parameter is invalid. |
400 | iot.device.NullDeviceName | The deviceName is empty. | DeviceName is left empty. |
400 | iot.device.InvalidFormattedDeviceName | The deviceName format is incorrect. | The format of DeviceName is invalid. |
400 | iot.device.InactiveDevice | The device is inactive. | The device is not activated, which means that the device has never been connected to IoT Platform. |
400 | iot.device.OfflineDevice | The device is offline. | The device is disconnected. |
400 | iot.Device.NotExistedDevice | This device does not exist. | The device does not exist or is not activated. |
For a list of error codes, see Service error codes.