物联网平台 - 云端API使用方式

Step By Step

  1. OpenAPI
  2. 云端SDK


一.OpenAPI物联网平台 - 云端API使用方式

二.云端SDK(本文以Java为例)

1.添加pom依赖

<!-- https://mvnrepository.com/artifact/com.aliyun/aliyun-java-sdk-iot -->
<dependency>
    <groupId>com.aliyun</groupId>
    <artifactId>aliyun-java-sdk-iot</artifactId>
    <version>7.31.0</version>
</dependency>

<dependency>
    <groupId>com.aliyun</groupId>
    <artifactId>aliyun-java-sdk-core</artifactId>
    <version>4.5.6</version>
</dependency>


2.发起调用

String accessKey = "${accessKey}";
String accessSecret = "${accessSecret}";
IClientProfile profile = DefaultProfile.getProfile("cn-shanghai", accessKey, accessSecret);
DefaultAcsClient client = new DefaultAcsClient(profile); 

PubRequest request = new PubRequest(); 
request.setIotInstanceId("${iotInstanceId}"); 
request.setProductKey("${productKey}"); 
request.setMessageContent(Base64.encodeBase64String("hello world".getBytes())); 
request.setTopicFullName("/${productKey}/${deviceName}/user/get"); 
request.setQos(0); //目前支持QoS0和QoS1。 
try 
{ 
   PubResponse response = client.getAcsResponse(request); 
   System.out.println(response.getSuccess()); 
   System.out.println(response.getCode());
   System.out.println(response.getErrorMessage());
} 
catch (ServerException e) 
{
   e.printStackTrace();
}
catch (ClientException e)
{
   System.out.println("ErrCode:" + e.getErrCode());
   System.out.println("ErrMsg:" + e.getErrMsg());
   e.printStackTrace();
}


上一篇:阿里云物联网平台设备端响应物模型属性更新


下一篇:关于苹果开发你要知道的事