After your devices and servers are connected to Alibaba Cloud IoT Platform, they can communicate with each other by using IoT Platform.

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.
    1. In the IoT Platform console, set the Device Operation Authorizations parameter 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:

    2. 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 configure the Link SDK that is provided by Alibaba Cloud, see the "Devices send messages to the server" section in the Use custom topics for communication topic.

  • Use topics related to Thing Specification Language (TSL) features to send standard TSL data.

    For more information about TSL features, see Overview.

    Devices can submit properties and events.

    Procedure

    1. In the IoT Platform console, define a TSL based on your business requirements. For more information, see Add a TSL feature.
    2. When you develop your devices, configure the devices to submit properties and events based on the defined TSL.

      For more information about the standard data formats for properties and events that are submitted by devices, see Devices report properties and Devices report events.

      Note IoT Platform provides predefined topics related to TSL features. You can directly use these topics.

      For information about how to use the Link SDK that is provided by Alibaba Cloud, see Report properties and events by using the device SDK.

IoT Platform forwards data to the server

You can configure IoT Platform to use either of the following methods to forward data to your server. The data that can be forwarded includes messages submitted by devices, changes in device status, changes in device lifecycles, historical TSL data, firmware update status, information of new sub-devices that are discovered by gateways, and changes in device topology.

Forwards data to the server
  • Service subscription: You can use the service subscription feature provided by IoT Platform to subscribe to messages of one or more types. IoT Platform can forward messages of specified types from all devices under the product to your server based on your subscription settings. You can use either of the following methods to subscribe to the service:
    • Use the AMQP SDK to receive device data forwarded by IoT Platform. For more information, see AMQP service subscription and other related topics.
    • Use the Message Service (MNS) SDK to receive device data that is forwarded by IoT Platform to MNS queues. For more information, see MNS service subscription.
  • Data forwarding: You can use the data forwarding feature of the rule engine to forward specified device data to MNS topics or RocketMQ queues based on data forwarding rules. The server receives messages by using the MNS SDK.
    1. Create a rule to forward device data to an MNS topic or RocketMQ queue. For more information, see Configure data forwarding rules.
    2. Use the MNS SDK to receive messages. For more information, see the message subscription section of User guide for MNS topics.

For information about the differences between data forwarding and service subscription, see Compare data forwarding solutions.

The server controls remote devices

The server uses the IoT Platform SDK to call cloud API operations to send commands to devices to achieve remote control. The server can use either of the following ways to send commands:

Control devices
  • Use custom topics to control remote devices.
    • Asynchronous control: The server calls the Pub operation to send custom format data to a custom topic whose Device Operation Authorizations parameter is set to Subscribe. Devices subscribe to this topic to receive messages.
      Note You cannot call the Pub operation to send TSL-related commands.

      For more information about how to use custom topics to control remote devices, see Use custom topics for communication.

    • Synchronous control: The server calls the RRpc operation to send messages to specified devices and synchronously retrieves the response.

      For more information about MQTT synchronous communication, see What is RRPC?.

      For more information about how to call the RRPC operation for synchronous communication, see Control Raspberry Pi servers from IoT Platform.

    • Batch control: The server calls the PubBroadcast operation to broadcast messages to all online devices.

      For more information about how to achieve batch control, see Broadcast messages.

  • Use a TSL to control remote devices.

    You can use TSL-specific API operations to publish property values and call service commands on the cloud.

    • Control a single device.
      • The server calls the SetDeviceProperty operation to send a command for configuring property values to a device.

        The cloud sends a command for configuring properties. The device receives and runs the command asynchronously. To check whether the properties are updated, see the properties that are later submitted by the device.

      • The server calls the InvokeThingService operation to send a service call command to a single device.

        Whether a service is called synchronously or asynchronously depends on the call method that is specified when you customize the service.

        If the Invoke Method parameter is set to Synchronous, the response is returned synchronously after the server calls the InvokeThingService operation.

        If the Invoke Method parameter is set to Asynchronous, the response is returned asynchronously after the server calls the InvokeThingService operation. You can use the rule 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 forwarding rules, see Configure data forwarding rules.

    • Control multiple devices.
      • The server calls the SetDevicesProperty operation to send commands for configuring properties to multiple devices.
      • The server calls the InvokeThingsService operation to send commands for calling services to multiple devices.

    For more information about how to use a TSL to control remote devices, see TSL model communication.

Communication between devices

You can connect devices at both ends to IoT Platform and use IoT Platform to handle connection and communication requests between the devices. The following topics describe the two methods that can be used to enable communication between devices:

Sample scenarios of using device data

Integrate with a weather service

Upload temperature and humidity data to DingTalk chatbots