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.Development environment
In this example, the development environment consists of the following components:
Operating system: Windows 10
Java Development Kit (JDK): JDK 8
Integrated development environment (IDE): IntelliJ IDEA Community Edition
Procedure
- Download and decompress the SDK package iotx-api-demo. This package contains the device SDK for Java and IoT Platform SDK for Java.
- Open IntelliJ IDEA and import the decompressed sample project iotx-api-demo.
- 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> - 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-20Parameter 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 Iotfor 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-DDformat.
What to do next
- Connect a gateway to IoT Platform: Develop the gateway and connect the gateway directly to IoT Platform.
- Connect the sub-device to IoT Platform: Configure the gateway to connect the sub-device to IoT Platform.
该文章对您有帮助吗?