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 |
How communication over RRPC works
Process:
- Optional. A device subscribes to the RRPC subscription topic.
IoT Platform can only send RRPC request messages and receive RRPC response messages based on MQTT. If a device needs to obtain and process RRPC data that is sent from IoT Platform, the device must subscribe to the preceding topic and implement the developed data processing logic.
- The device can send the SUB command to subscribe to specified topics and obtain messages from IoT Platform. For information about the sample code that can be used to subscribe to a topic for a device, see Link SDKs.
- For information about how a device processes RRPC data, see RRPC overview.
- A user server calls the RRpc operation of IoT Platform.
- 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.
- 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.
- IoT Platform extracts the response message ID to match the previous RRPC request message.
- IoT Platform returns the response to the user server.
- Optional. The device processes messages from the topic to which the device subscribes to
- 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:
- Use custom topics (recommended): Use RRPC together with custom topics to meet the requirements of various scenarios.
- Use RRPC-specific topics (not recommended): If you do not use custom topics, IoT Platform uses RRPC-specific topics. We recommend that you do not use this method because the method applies only to a limited number of scenarios.
For information about the example of implementing an RRPC, see Remotely control a Raspberry Pi server.