You can use the data forwarding feature of the rules engine to forward data to Tablestore.

Prerequisites

  • A Tablestore instance and a table that is used to receive data are created. For more information, see the Tablestore documentation.
    Notice If you use an IoT Platform instance of the Enterprise Edition, the region where the Tablestore instance is deployed must be the same as that of the IoT Platform instance.
  • A data forwarding rule is created and an SQL statement that is used to process data is written. For more information, see Configure a data forwarding rule.
    In the data forwarding rule that is used in this example, the following SQL statement is defined:
    SELECT items.temperature.value as temperature, items.humidity.value as humidity,deviceName() as deviceName 
    FROM "/sys/a1ktuxe****/BZoyHO***/thing/event/property/post"

Procedure

  1. Log on to the IoT Platform console.
  2. On the Overview page, find the instance and click the instance name to go to the Instance Details page.
    Notice Enterprise Edition instances are available only in the China (shanghai) and Japan (Tokyo) region. If your IoT Platform is not activated in the China (shanghai) or Japan (Tokyo) region, skip this step.
    Overview
  3. In the left-side navigation pane, choose Rules Engine > Data Forwarding.
  4. Click View next to the rule that you want to manage. The Data Forwarding Rule page appears.
    Notice If the new version of the Data Forwarding page is displayed, you must click Back to Previous Version in the upper-right corner, and then click View in the Actions column corresponding to the rule that you want to manage.
  5. In the Forward Data section, click Add Operation.
  6. In the Add Operation dialog box, follow the instructions on the page to set parameters and click OK.
    Note You can forward data only in the JSON format.
    Tablestore
    Parameter Description
    Operation Select Store Data to Tablestore.
    Region Select a region where your Tablestore instance is deployed.
    Instance Select a Tablestore instance.

    You can click Create Instance to go to the Tablestore console and create a Tablestore instance. For more information, see the Tablestore documentation.

    Data Table Select a Tablestore table that is used to receive data.

    You can click Create Data Table to go to the Tablestore console and create a Tablestore table.

    Primary Key Specify a value for the primary key of the table. You must set this value to a field value that is specified in the SELECT statement configured in the data forwarding rule. When data is forwarded, this value is saved as the value of the primary key.
    Note
    • You can set this parameter in the ${} format. For example, set the timestamp to ${deviceName}. ${deviceName} specifies that the value of the primary key is the value of the deviceName parameter in a message.
    • If the primary key corresponds to an auto-increment column, you do not need to specify a value for the primary key. Tablestore automatically generates values for this primary key column. By default, the value of an auto-increment primary key column is set to AUTO_INCREMENT. You cannot modify the value.

      For more information about auto-increment primary key columns, see Auto-increment of primary key columns.

    Role Grant IoT Platform the permissions to write data to Tablestore.

    If no RAM roles exist, click Create RAM Role to go to the Resource Access Management (RAM) console, create a RAM role, and then grant permissions to the RAM role. For more information, see Create a RAM role.

  7. Go to the Data Forwarding page, find the rule that you managed, and then click Start in the Actions column of the rule.
  8. Perform a test.
    1. Log on to the IoT Platform console.
    2. In the left-side navigation pane, choose Maintenance > Device Simulation.
    3. Select the required device, and click Upstream Debug, Properties, and Start Device Simulation one after one.
    4. Below Default Module, set test data and click Send Command.
      Device simulation
    5. After the data is forwarded, log on to the Tablestore console. Go to the Query Data page of the table that is used to receive data and check whether the specified data is received.
      Data management