Revert-RPCs (RRPCs) support using custom topics for communication between IoT Platform and devices. An RRPC-specific topic includes an entire custom topic that is defined in IoT Platform. This article describes RRPC-specific topics that include custom topics and how to initiate an RRPC request.

Prerequisites

Devices are integrated with Link SDK for C.

Custom topics

Topic Format Description
RRPC subscription topic /ext/rrpc/+/${topic} Subscribes to RRPC request messages that are 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}: Replace this variable with your custom topic. For more information, see Edit a topic category.
  • ${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.

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.
    • For devices that use Link SDK for C, no additional configuration is required.
    • clientId:`${this.clientId}|securemode=${this.securemode },signmethod=hmac${this.signAlgorithm},timestamp=${this.timestamp},${extra}`,

      clientId:`${this.clientId}|securemode=${this.securemode },signmethod=hmac${this.signAlgorithm},timestamp=${this.timestamp},${extra},ext=1`,
  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.