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.
- 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.
- Goal: Display real-time data that is collected by the devices of an IoT Platform product on a visualized screen by using DataV.
- IoT Platform collects device data.
- IoT Platform forwards device data of a product to DataHub by using the rules engine.
- 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.
- DataV uses an ApsaraDB RDS for MySQL database table as a data source and displays device data in the database table in real time.
- Create an ApsaraDB RDS for MySQL database to store device data.For more information, see the What is ApsaraDB for RDS?.
- Log on to the ApsaraDB RDS console.
- 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.
- On the Instances page, find the purchased instance and click Manage in the Actions column.
- 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.
- 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.
- 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.
- 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.
- 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.
- 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.
- In the IoT Platform console, create a product, a device, and a data forwarding 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.
- Log on to the IoT Platform console.
- In the left-side navigation pane, choose Create a product.. On the Products page, click Create Product and set the parameters as required to create a product. For more information, see
- 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?
- In the left-side navigation pane, choose Create a device.. On the Devices page, click Add Device and set the parameters as required to create a device. For more information, see
- In the left-side navigation pane, choose . On the Data Forwarding page, click Create Rule and set the parameters as required to create a rule.
- On the Data Forwarding page, find the rule that you want and click View in the Actions column.
- 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.
- 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.
- 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.
- 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.
- Download the device SDK for Java.
- 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.
- 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.
- 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.