Overview of communication methods in IoT Platform

更新时间:
复制 MD 格式

After your devices and servers are connected to Alibaba Cloud IoT Platform, they can communicate with each other and with business servers through the platform. This topic describes the communication methods among devices, IoT Platform, and servers.

Background information

Devices send and receive messages through message topics. For more information about the definition, use, and categorization of message topics, see What is a topic?.

You must define the raw data format for data that is reported by your devices. The device-side Link software development kit (SDK) provided by Alibaba Cloud IoT Platform allows devices to quickly connect to and communicate with IoT Platform.

For example, to use the C Link SDK to develop communication capabilities for a device, see MQTT connection example, Custom topic communication example, and Thing Specification Language model topic communication example.

The device-side Link SDK also supports development in Java, Python, Node.js, Android, and iOS. For more information about the features, see Functions and features.

When raw topic messages from a device are forwarded to a server, the IoT Platform rules engine converts the data format. For more information about communication topics, message types, and data formats, see Data formats.

Devices send data to IoT Platform

After a device is connected to IoT Platform, it can communicate with the platform. A device can send data to IoT Platform in the following ways:

  • Use a custom topic to send data in a custom format.

    1. In IoT Platform, create a custom topic category for a product and set the Operation Permission to Publish. This topic category is automatically mapped to all devices that belong to the product.

      You can create a custom topic category in two ways:

    2. When you develop the device client, configure the device to send messages to the custom topic.

      You must configure the custom topic and message format on the device. For a configuration example that uses the Alibaba Cloud Link SDK, see Device sends a message to a server.

  • Use topics related to the Thing Specification Language (TSL) model to send standardized TSL model data.

    For more information about the TSL model, see What is a Thing Specification Language model?.For an example, see Use IoT Studio to build a monitoring dashboard.

    Devices can proactively report properties and events. The procedure is as follows:

    1. Add a TSL model for a single product: Define a TSL model in the IoT Platform console.

    2. Develop the device client: Based on the defined TSL model, configure the device to report property and event data.

      For more information about the standard data formats for reporting properties and events, see Device reports properties and Device reports an event.

      IoT Platform has predefined topics for TSL model features that you can use directly. For a development example that uses the Alibaba Cloud Link SDK, see Device SDK reports properties and events.

IoT Platform forwards data to servers

IoT Platform provides a rules engine. You can use the rules engine to forward various messages to your servers. These messages include reported device messages, device status notifications, device lifecycle changes, historical TSL model data reports, over-the-air (OTA) update status notifications, reports of sub-devices discovered by gateways, and device topology changes. Messages are transmitted based on topics. For more information about the data format in topics, see Data formats.

Data to Server

For a comparison between data forwarding and server-side subscription, see Comparison of data forwarding solutions.

Remotely control devices from a server

On your server, you can use the cloud SDK provided by IoT Platform to call cloud APIs and send commands to remotely control devices. A server can send commands to a device in the following ways.

Control Devices

  • Use a custom topic to remotely control a device.

    • Asynchronous control: You can call the Pub API to send a message in a custom format to a custom topic for which the device has Subscribe permissions. The device receives the message by subscribing to this topic.

      Note

      You cannot use the Pub API to send TSL model-related commands.

      For a practical example of using a custom topic to remotely control a device, see Server sends a message to a device.

    • Synchronous control: Call the RRpc API to send a message to a specific device and synchronously receive the response.

      For more information about synchronous communication over MQTT, see What is revert-RPC?.

      For a practical example of how to use the RRpc API to synchronously control a device, see Remotely control a Raspberry Pi server.

    • Batch control: Call the PubBroadcast API to publish a broadcast message to all online devices under a product. This lets you control multiple devices at once.

      For more information about controlling devices in a batch, see Broadcast communication.

  • Use the TSL model to remotely control a device.

    You can call specific cloud APIs to send TSL model data. This lets you publish commands to set property values and call services.

    • Control a single device.

      • Call the SetDeviceProperty API to send a command to a single device to set a property value.

        Sending a property setting command from the cloud is an asynchronous operation. The device receives and executes the command. The operation is considered successful only after the device reports the new property value.

      • Call the InvokeThingService API to send a command to a single device to call a service.

        Whether a service is called synchronously or asynchronously depends on the invocation method that you select when you define the TSL model service. For more information, see Define a custom TSL model service.

        If the service is set to synchronous invocation, the InvokeThingService call returns a result synchronously.

        If the service is set to asynchronous invocation, the InvokeThingService call does not return a result synchronously. You can obtain the device's response message through the rules engine. To do this, set the data source topic to TSL model data reporting and specify the topic as thing/downlink/reply/message. To set the data source topic, see Set a data forwarding rule or Add a data source.

    • Control multiple devices in a batch.

    For a practical example of using the TSL model to remotely control a device, see TSL model communication.

Device-to-device communication

To enable device-to-device communication, you must connect both devices to IoT Platform. The platform then handles the connections and communication requests between them. You can enable device-to-device communication in the following two ways: