Revert-RPCs (RRPCs) support custom topics for communication between IoT Platform and devices. A communication topic contains an entire custom topic.

Prerequisites

Revert-RPCs allow IoT Platform to communicate with devices that are implemented through the following language-specific Link SDKs: C SDK.

Custom topics

Custom topics that are used by RRPCs for communication are in the following formats:

  • RRPC request topic: /ext/rrpc/${messageId}/${topic}
  • RRPC response topic: /ext/rrpc/${messageId}/${topic}
  • RRPC subscription topic: /ext/rrpc/+/${topic}

In the preceding topics, ${messageId} specifies a unique RRPC message ID and ${topic} specifies a custom topic.

Initiate RRPC requests

  1. IoT Platform sends an RRPC message.

    You can call the RRpc operation on your server to send messages to a device. For more information, see RRpc.

    Use the SDK for Java 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 custom topics for communication, specify a custom topic in this function.
    request.setTimeout(3000);
    RRpcResponse response = client.getAcsResponse(request);
    Note You can use different SDKs to call the RRpc operation. For more information about sample code, visit OpenAPI Explorer.
  2. Connect a device
    • You can use the SDK for Node.js to implement a device. In this case, you must download the SDK to the localhost. Modify the model.js file of the src directory, and add ext=1 to the clientId parameter of the genConnectPrarms function. Then, use the SDK to implement the device.

      The source value of the clientId parameter is

      clientId:`${this.clientId}|securemode=${this.securemode },signmethod=hmac${this.signAlgorithm},timestamp=${this.timestamp},${extra}`,

      After you add ext=1 to the clientId parameter, the destination value is

      clientId:`${this.clientId}|securemode=${this.securemode },signmethod=hmac${this.signAlgorithm},timestamp=${this.timestamp},${extra},ext=1`,
    • If a device is implemented by the SDK for C, SDK for Android, and SDK for Python, no additional operations are required.
  3. The device sends an RRPC response.

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

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