Alibaba Cloud Link WAN provides a Java software development kit (SDK) that lets you manage the platform using Java programs. You can add the SDK as a Maven dependency.
Install the Java development environment.
Download the Java development environment from the official Java website and install it.
Install the Alibaba Cloud Link WAN Java SDK.
Visit the official Apache Maven website and download Maven.
Add the Maven project dependency.
Dependency coordinates for the Alibaba Cloud Link WAN SDK:
<dependency> <groupId>com.aliyun</groupId> <artifactId>aliyun-java-sdk-linkwan</artifactId> <version>3.0.0</version> </dependency>Dependency coordinates for the public Alibaba Cloud SDK:
<dependency> <groupId>com.aliyun</groupId> <artifactId>aliyun-java-sdk-core</artifactId> <version>4.5.2</version> </dependency>
Initialize the SDK
Initialize the SDK by instantiating the IAcsClient interface. This creates the client object that is used in the following code snippet.
String regionId = "cn-shanghai";
// An AccessKey for an Alibaba Cloud account has full access permissions to all APIs. Use a Resource Access Management (RAM) user for API calls and daily O&M.
// Do not save your AccessKey ID and AccessKey secret in your project code. Storing them in your code can lead to an AccessKey leak, which compromises the security of all resources in your account.
// This example uses the Alibaba Cloud Credentials tool to manage the AccessKey for API identity verification. For more information about how to configure credentials or environment variables, see https://help.aliyun.com/document_detail/378657.html?spm=a2c4g.262075.0.0.74465ccdEUyxZc
EnvironmentVariableCredentialsProvider credentialsProvider = new EnvironmentVariableCredentialsProvider();
DefaultProfile profile = DefaultProfile.getProfile(regionId, credentialsProvider.getCredentials().getAccessKeyId(), credentialsProvider.getCredentials().getAccessKeySecret());
IAcsClient client = new DefaultAcsClient(profile);
The accessKeyId parameter is the AccessKey ID of your Alibaba Cloud account. The accessKeySecret parameter is the AccessKey secret that corresponds to the AccessKey ID. You can create or view your AccessKey in the AccessKey Management console.
Make a call
The following example shows how to call the SendUnicastCommand API to send business data to a node.
SendUnicastCommandRequest request = new SendUnicastCommandRequest();
request.setProtocol(ProtocolType.HTTPS);
request.setMethod(MethodType.POST);
// The unique device identifier (DevEUI).
request.setDevEui("0000000000000000");
// The maximum number of retries.
request.setMaxRetries(0);
// The port number of the device.
request.setFPort(0);
// Specifies whether the downlink is confirmed.
request.setConfirmed(false);
// Specifies whether to purge previous instructions.
request.setCleanUp(false);
// The content of the instruction.
request.setContent("00000000");
try {
SendUnicastCommandResponse response = client.getAcsResponse(request);
System.out.println(response);
} catch (ClientException e) {
e.printStackTrace();
}