This topic describes how to initialize IoT Platform SDK for Java and the device SDK for Java. You must prepare a Java development environment, download the SDK package, import a project, and then initialize the SDKs.

Prerequisites

A gateway and a sub-device are created. For more information, see Create a gateway and a sub-device.

Prepare the development environment

In this example, the development environment consists of the following components:

Procedure

  1. Download and decompress the SDK package iotx-api-demo.
    This package contains the device SDK for Java and IoT Platform SDK for Java.
  2. Open IntelliJ IDEA and import the decompressed sample project iotx-api-demo.
  3. Add the following Maven dependencies to the pom.xml file to import the IoT Platform SDK and Link SDK:
    <!-- https://mvnrepository.com/artifact/com.aliyun/aliyun-java-sdk-iot -->
    <dependency>
        <groupId>com.aliyun</groupId>
        <artifactId>aliyun-java-sdk-iot</artifactId>
        <version>7.41.0</version>
    </dependency>
    <dependency>
        <groupId>com.aliyun</groupId>
        <artifactId>aliyun-java-sdk-core</artifactId>
        <version>4.5.6</version>
    </dependency>
    <dependency>
      <groupId>com.aliyun.alink.linksdk</groupId>
      <artifactId>iot-linkkit-java</artifactId>
      <version>1.2.0.1</version>
      <scope>compile</scope>
    </dependency>
  4. In the java/src/main/resources/ directory, open the config file and specify the required information for initialization.
    user.accessKeyID = <your accessKey ID>
    user.accessKeySecret = <your accessKey Secret>
    iot.regionId = <regionId>
    iot.productCode = Iot
    iot.domain = iot.<regionId>.aliyuncs.com
    iot.version = 2018-01-20
    Parameter Description
    accessKeyID The AccessKey ID and AccessKey secret of your Alibaba Cloud account.

    Log on to the IoT Platform console, move the pointer over the profile picture, and then click AccessKey Management to obtain the AccessKey ID and AccessKey secret.

    accessKeySecret
    regionId The ID of the region where your device resides. For information about the format of region IDs, see Regions.
    productCode The code of the cloud service. Set the value to Iot for IoT Platform.
    domain The endpoint of IoT Platform. <regionId> specifies the ID of the region where IoT Platform resides.
    version The version number of the API. The value is in the YYYY-MM-DD format.

What to do next

  1. Connect a gateway to IoT Platform: Develop the gateway and connect the gateway directly to IoT Platform.
  2. Connect the sub-device to IoT Platform: Configure the gateway to connect the sub-device to IoT Platform.