The Message Queuing Telemetry Transport (MQTT) protocol uses the asynchronous publish/subscribe model. This model is not applicable to the scenarios in which user servers need to synchronously control devices and obtain responses. IoT Platform provides a synchronous communication mechanism based on MQTT. You do not need to modify the MQTT protocol. IoT Platform provides the RRpc operation for user servers to send requests to devices. The devices only need to respond to the requests by using the specified topics and then the servers can synchronously obtain the responses.

Terms

Term Description
RRPC RRPC is short for revert-RPC. A remote procedure call (RPC) uses the client-server model. This model allows you to request a remote service without the need to understand the underlying protocol. An RRPC allows you to send a request from a server to a device and receive a response from the device.
RRPC subscription-specific topic The topic to which devices subscribe to receive RRPC messages. The topic includes a wildcard.
RRPC request message The message that IoT Platform sends to a device.
RRPC response message The message that a device sends to IoT Platform as a response.
RRPC message ID The ID that is generated by IoT Platform for each RRPC message

RRPC procedure

RRPC

Procedure:

  1. A device subscribes to the RRPC subscription-specific topic.
  2. A user server calls the RRpc operation.
  3. IoT Platform receives a server-side RRPC request and sends an RRPC request message to the device. The message body includes the payload that is sent from the user server. The topic that is used by the device to receive RRPC messages is predefined in IoT Platform. The topic includes the ID of the message.
  4. After the device receives the message, the device sends an RRPC response message to IoT Platform by using the specified topic. The topic includes the ID of the request message.
  5. IoT Platform extracts the response message ID to match the previous RRPC request message.
  6. IoT Platform returns the response to the user server.
Note When you call the RRpc operation on the user server, the following errors may occur:
  • The device is offline. In this case, IoT Platform returns an error message to the user server.
  • The device does not respond to the RRPC request within the timeout period (8 seconds). In this case, IoT Platform returns an error message to the user server.

RRPC-specific topics

You can implement RRPCs based on the following types of topics:

For information about the example of implementing an RRPC, see Remotely control Raspberry Pi servers.