After your devices and server are connected to IoT Platform, you can use IoT Platform to implement communications between the devices and the server and between devices. This topic describes how to establish communications among devices, IoT platform, and servers.
Background information
Devices send and receive messages through topics. For information about topics, see Topics.
You must specify the format of raw data that is submitted by devices when you develop the devices. IoT Platform provides Link SDKs that you can use to easily connect devices with IoT platform and implement communications.
For information about Link SDK for C, see Examples for connection over MQTT and Examples for TSL models.Example
Link SDK also supports the Java, Python, and Node.js languages and the Android and iOS platforms. For more information, see Device connection by using Link SDK.
When IoT Platform receives a topic from a device, its rules engine converts the data format. Then, IoT Platform forwards the converted topic to the server. For more information about topics, message types and data formats, see Data formats.
Devices send data to IoT Platform
After you connect devices to IoT Platform, the devices can communicate with IoT Platform. The devices can use either of the following ways to send data to IoT Platform:
Use custom topics to send custom-format data.
On the IoT Platform console, set Allowed Operations of a custom topic to Publish. Product topics are automatically mapped to the devices under the product.
You can create custom topics by using either of the following methods:
Use the IoT Platform console. For more information, see Use custom topics for communication.
Use IoT Platform SDK. You can call the Download IoT Platform SDKs API operation to create a custom topic.
Configure devices to send messages to custom topics when you develop the devices.
You must configure custom topics and message formats for sending messages on devices. For information about how to use Link SDK that is provided by IoT Platform, see Configure the device to send a message to the server.
Use Thing Specification Language (TSL)-specific topics to send data.
For more information about TSL features, see What is a TSL model?
Devices can submit properties and events. Procedure:
In the IoT Platform console, define TSL features based on your business requirements. For more information, see Add a TSL feature.
When you develop your devices, configure the devices to submit properties and events based on the defined TSL features.
For more information about the standard data formats for properties and events that are submitted by devices, see Devices submit property data to IoT Platform and Devices submit events to IoT Platform.
IoT Platform provides predefined TSL-specific topics. You can directly use these topics. For information about how to use the Link SDK that is provided by IoT Platform, see Submit properties and events by using Link SDK.
IoT Platform forwards data to enterprise servers
IoT Platform provides the rules engine feature and supports multiple methods to forward data to your server. The data that can be forwarded includes messages submitted by devices, changes of device status, changes of device lifecycles, historical TSL data, firmware update status, information of new sub-devices that are discovered by gateways, and changes of device topologies. Messages are forwarded based on topics. For more information about the data formats of topics, see Data formats.
Server-side subscription: You can use the server-side subscription feature provided by IoT Platform to subscribe to messages of one or more types. Then, IoT Platform forwards messages of specified types from all devices in a product to a server based on your subscription settings. You can use one of the following methods to configure a server-side subscription:
Use an Advanced Message Queuing Protocol (AMQP) SDK to receive device messages that are forwarded by IoT Platform. For more information, see AMQP server-side subscription and the related documentation.
Use a Message Service (MNS) SDK to receive device messages that are forwarded by IoT Platform to MNS queues. For more information, see MNS server-side subscription.
Data forwarding: You can configure data forwarding rules provided by the data forwarding feature of the rules engine to forward device data to multiple Alibaba Cloud services. The services include Simple Message Queue (formerly MNS) (SMQ), ApsaraDB RDS, Tablestore (OTS), Function Compute, Lindorm, and Message Queue for Apache RocketMQ. For more information, see Data forwarding (old version) or Data forwarding (new version).
For information about the differences between data forwarding and server-side subscription, see Compare data forwarding features.
Perform remote control on the device
You can use IoT Platform SDK on your server to achieve remote control on devices. To perform remote control on devices, you must call API operations to send commands from IoT Platform to the devices. The server can use either of the following ways to send commands:
Use custom topics to control remote devices.
Asynchronous control: Call the Pub operation to send custom-format data to a custom topic whose Allowed Operations parameter is set to Subscribe. Devices subscribe to this topic to receive messages.
NoteYou cannot call the Pub operation to send TSL-related commands.
For more information about how to use custom topics to control remote devices, see Configure the server to send a message to the device.
Synchronous control: Call the RRpc operation to send messages to specified devices and synchronously retrieves the responses.
For more information about synchronous MQTT communication, see What is RRPC?
For more information about how to call the RRpc operation for synchronous communication, see Remotely control a Raspberry Pi server.
Batch control: Call the PubBroadcast operation to broadcast messages to all online devices.
For more information about how to achieve batch control, see Broadcast messages.
Use TSL-specific topics.
You can use TSL-specific API operations to send property setting or service calling commands from IoT Platform to devices.
Control a single device.
Call the SetDeviceProperty operation to send a property setting command to a single device.
After IoT Platform sends the command, the device receives and runs the command in an asynchronous manner. To check whether the device properties are updated, you must view the properties that are later submitted by the device.
Call the InvokeThingService operation to send a service calling command to a single device.
The Invoke Method parameter determines whether a service is called in a synchronous or asynchronous manner. This parameter is specified when you customize the service. For more information, see Add a TSL feature.
If the Invoke Method parameter is set to Synchronous, the response is synchronously returned after the InvokeThingService operation is called.
If the Invoke Method parameter is set to Asynchronous, the response is asynchronously returned after the InvokeThingService operation is called. You can use the rules engine to retrieve the response. You must set the data source of the SQL query for the rule to TSL Data Reporting and set the specific topic to
thing/downlink/reply/message
. For more information about how to configure data sources, see Configure a data forwarding rule and Create a data source.
Control multiple devices.
Call the SetDevicesProperty operation to send a property setting command to multiple devices.
Call the InvokeThingsService operation to send a service calling command to multiple devices.
For more information about how to use TSL-specific topics to control remote devices, see Establish TSL-based communication.
Implement communication between devices
You can connect devices at two ends to IoT Platform and use IoT Platform to process connection and communication requests between the devices. The following topics describe the two methods that can be used to achieve communication between devices: