This article describes how to connect IoT Platform to the Alibaba Cloud big data platform to collect, compute, and analyze device data, and display visualized device data in real time.

Prerequisites

  • The Alibaba Cloud services used in this example are activated, and instances and computing resources are purchased. The Alibaba Cloud big data platform is used to process data that is collected by IoT Platform devices. The platform consists of multiple Alibaba Cloud services, such as ApsaraDB RDS for MySQL , and IoT Platform.
  • You understand how to configure and use these Alibaba Cloud services.

Background information

  • Goal: Display real-time data that is collected by the devices of an IoT Platform product on a visualized screen by using DataV.
  • Procedure:
    1. IoT Platform collects device data.
    2. IoT Platform forwards device data of a product to DataHub by using the rules engine.
    3. DataHub sends the device data to Realtime Compute for Apache Flink for processing and writes the processed data to ApsaraDB RDS for MySQL. If you do not need to process the device data, you can directly synchronize the data from DataHub to ApsaraDB RDS for MySQL by using DataConnector.
    4. DataV uses an ApsaraDB RDS for MySQL database table as a data source and displays device data in the database table in real time.

Procedure

  1. Create an ApsaraDB RDS for MySQL database to store device data.
    For more information, see the What is ApsaraDB for RDS?.
    1. Log on to the ApsaraDB RDS console.
    2. On the Instances page, click Create Instance to purchase an ApsaraDB RDS for MySQL instance.
      Note The region of the ApsaraDB RDS for MySQL instance must be the same as the region of your IoT Platform devices and DataHub project.
    3. On the Instances page, find the purchased instance and click Manage in the Actions column.
    4. In the left-side navigation pane, click Accounts. On the Accounts page, click Create Account and set the parameters as required to create an account.
    5. In the left-side navigation pane, click Databases. On the Databases page, click Create Database and set the parameters as required to create a database.
    6. In the left-side navigation pane, click Data Security. On the Data Security page, click Create Whitelist to configure an IP address whitelist for the ApsaraDB RDS for MySQL instance. For more information, see Configure an IP address whitelist for an ApsaraDB RDS for MySQL instance.
    7. In the left-side navigation pane, click Basic Information to view the basic information about the instance.

      The instance information is required when you configure data synchronization to DataHub, DataV, and Realtime Compute for Apache Flink.

    8. In the top navigation bar of the Basic Information page, click Log On to Database. In the Login instance dialog box, enter account information to log on to the database.
    9. Create a database table. In this example, a database table that is named mytable is created. The database table contains two fields, as described in the following table.
      Table 1. mytable
      Field Type Description
      d_data varchar(32) The time.
      device_num int The number of active devices.
  2. In the IoT Platform console, create a product, a device, and a data forwarding rule.
    1. Log on to the IoT Platform console.
    2. In the left-side navigation pane, choose Devices > Products. On the Products page, click Create Product and set the parameters as required to create a product. For more information, see Create a product.
    3. After you create the product, you can go to the Product Details page of the product and configure the product based on your business requirements. For example, you can create a topic category or define a Thing Specification Language (TSL) model. For more information, see What is a topic? or What is a TSL model?
    4. In the left-side navigation pane, choose Devices > Devices. On the Devices page, click Add Device and set the parameters as required to create a device. For more information, see Create a device.
    5. In the left-side navigation pane, choose Rules > Data Forwarding. On the Data Forwarding page, click Create Rule and set the parameters as required to create a rule.
    6. On the Data Forwarding page, find the rule that you want and click View in the Actions column.
    7. In the Data Processing section of the Data Forwarding Rule page, click Write SQL. In the Write SQL dialog box, write SQL statements for the rule. Then, debug the SQL statements. For more information, see SQL statements.
    8. In the Data Forwarding section, click Add Operation. In the Add Operation dialog box, configure the parameters as required to forward device data to a topic in DataHub. For more information, see Configure data forwarding rules.
    9. After you configure the rule, go back to the Data Forwarding page. Find the rule that you configured and click Start in the Actions column to enable the rule.
    After you enable the rule, use a simulated device to send a message and verify that the message can be forwarded to DataHub. On the Device Log page, you can view the logs of the simulated device. On the DataHub console, you can view the changes of data size in the shards of the topic to which device data is forwarded. You can also use the data sampling feature to view message content in the shards.
  3. Develop a device program and connect the device to IoT Platform.
    In this example, the device SDK for Java is used to develop a device program in the Eclipse environment.
    1. Download the device SDK for Java.
    2. Decompress the SDK package and import the SDK into Existing Maven Projects in Eclipse. In the SimpleClient4IOT.java file, configure the device certificate and the topics for message communication.
    3. Establish a communication channel between the device and IoT Platform. In this example, a Message Queuing Telemetry Transport (MQTT) connection is established.

      You can modify the content fields that are shown in the following figure based on your business requirements.

      After the settings are complete, click Run. If a test message is successfully sent, the information shown in the following figure is returned.

    After you develop the program by using the device SDK, burn the program to the physical device. After you power on the device and connect it to IoT Platform, the device can report data to IoT Platform. IoT Platform forwards the data to DataHub by using the rules engine. After Realtime Compute for Apache Flink processes the data, the processed data is written to ApsaraDB RDS for MySQL.

  4. Run a test. After the configuration is complete, you can connect different devices to IoT Platform and send messages. The number of active devices changes in real time on the screen.