The Message Queuing Telemetry Transport (MQTT) protocol uses the asynchronous publish/subscribe model. This model is not applicable to the scenarios in which a server needs to synchronously control devices and obtain results. IoT Platform provides a synchronous communication mechanism based on MQTT. This allows you to synchronously obtain a response after you initiate a request. You do not need to modify the MQTT protocol. The following procedure is used: 1. A user server calls an operation that is provided by IoT Platform. 2. A device publishes a response message to a specified topic. 3. IoT Platform synchronously sends the device response to the server.
- RRPC: 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 request: The message that IoT Platform sends to a device.
- RRPC response: The message that the device sends to IoT Platform.
- RRPC message ID: The ID of the message that IoT Platform sends to the device.
- RRPC subscription topic: The topic that is used by the device to subscribe to RRPC messages. The topic includes a wildcard.
Message communication by using RRPC
- IoT Platform receives an RRPC call from a server. Then, IoT Platform sends an RRPC request to the specified device. The message body includes the specified data. The topic that is used by the device to receive RRPC messages is predefined in IoT Platform. The ID of the RRPC message in the topic is unique.
- After the device receives the downstream message, the device sends an RRPC response to IoT Platform based on the specified topic format. The response includes the unique ID of the RRPC message that is sent by IoT Platform. IoT Platform extracts the message ID from the topic. If the message ID is the same as the message ID of the RRPC request, IoT Platform sends a response to the server.
- If the device is disconnected from IoT Platform when a call is initiated, IoT Platform returns an error message to the server. The error message indicates that the device is offline. If the device fails to respond to an RRPC call within the specified timeout period (8 seconds), IoT Platform returns a timeout error to the server.
Implement RRPC calls based on the following topics:
- System topics. For more information, see RRPC-specific topics.
- Custom topics. For more information, see Custom topics.
For more information about how to implement RRPC calls, see Control Raspberry Pi servers from IoT Platform.