Revert-RPC (RRPC) allows you to establish communication between IoT Platform and devices by using custom topics. An RRPC-specific topic includes a complete custom topic that you created in IoT Platform. You can use this method to meet the communication requirements of various scenarios. This topic describes RRPC-specific topics that include custom topics and how to initiate an RRPC request.

Prerequisites

A device is configured. The device can communicate with IoT Platform by using custom topics. You can use the following Link SDK to configure devices: Link SDK for C.

Custom topics

TopicFormatDescription
RRPC subscription topic/ext/rrpc/+/${topic}Subscribes to a custom topic that is included in RRPC request messages sent from IoT Platform.
RRPC request topic/ext/rrpc/${messageId}/${topic}Sends RRPC request messages from IoT Platform.
RRPC response topic/ext/rrpc/${messageId}/${topic}Sends RRPC response messages from devices.

Variables:

  • ${topic}: The name of the complete custom topic that you created in the IoT Platform console. Format: /${productKey}/${deviceName}/user/${TopicShortName}.

    ${TopicShortName} specifies a custom topic category, which is the suffix of the custom topic. For more information, see Custom topics

  • ${messageId}: Replace this variable with the ID of the RRPC message. When a server calls the RRpc operation to send a message to a device, IoT Platform generates a unique ID for the message.

For example, if a device is named device1, the name of the custom topic is a18wP***/device1/user/get and the name of the topic from which RRPC messages are sent is /ext/rrpc/121307410***/a18wP***/device1/user/get.

Initiate an RRPC request

  1. IoT Platform sends an RRPC message.

    A server calls the RRpc operation to send a message to a device. For more information, see RRpc.

    In this example, IoT Platform SDK for Java is used as an example.

    To use a custom topic, make sure that the version of your SDK for Java (aliyun-java-sdk-iot) is 6.0.0 or later.

    <dependency>
        <groupId>com.aliyun</groupId>
        <artifactId>aliyun-java-sdk-iot</artifactId>
        <version>6.0.0</version>
    </dependency>

    The following example shows how to call the RRpc operation.

    RRpcRequest request = new RRpcRequest();
    request.setProductKey("testProductKey");
    request.setDeviceName("testDeviceName");
    request.setRequestBase64Byte(Base64.getEncoder().encodeToString("hello world"));
    request.setTopic("/testProductKey/testDeviceName/user/get");// If you need to use a custom topic for communication, specify the custom topic in this function. 
    request.setTimeout(3000);
    RRpcResponse response = client.getAcsResponse(request);
    Note Log on to the OpenAPI Developer Portal and call the RRpc operation. The sample code for multiple programming languages is provided.
  2. Connect the device to IoT Platform.

    If a device is configured by using Link SDK for C, you do not need to configure additional settings for the device.

  3. The device sends an RRPC response.

    The format of an RRPC response topic is the same as the format of an RRPC request topic. Therefore, you can use an RRPC request topic as an RRPC response topic.

    Note Devices can return only the RRPC messages whose quality of service (QoS) level is 0.