閱讀742 返回首頁    go 阿裏雲


使用說明-java__SDK使用參考_服務器端API_阿裏雲物聯網套件-阿裏雲

JAVA SDK使用說明

公共參數

名稱 類型 是否必須 描述
accessKeyId String 必須 阿裏雲的Access Key ID
accessKeySecret String 必須 阿裏雲的Access Key Secret

引入SDK

*1 maven坐標:

  1. <!-- https://mvnrepository.com/artifact/com.aliyun/aliyun-java-sdk-iot -->
  2. <dependency>
  3. <groupId>com.aliyun</groupId>
  4. <artifactId>aliyun-java-sdk-iot</artifactId>
  5. <version>2.1.1</version>
  6. </dependency>

依賴公共包:

  1. <dependency>
  2. <groupId>com.aliyun</groupId>
  3. <artifactId>aliyun-java-sdk-core</artifactId>
  4. <version>2.4.2</version>
  5. </dependency>

*2 sdk源碼地址參考-github https://github.com/aliyun/aliyun-openapi-java-sdk/tree/master/aliyun-java-sdk-iot

初始化

  1. String accessKey = "<your accessKey>";
  2. String accessSecret = "<your accessSecret>";
  3. IClientProfile profile = DefaultProfile.getProfile("cn-hangzhou",accessKey, accessSecret);
  4. DefaultAcsClient client = new DefaultAcsClient(profile);//初始化SDK客戶端

發起調用

以推送數據到設備為例

  1. RevertRpcRequest rpcRequest = new RevertRpcRequest();
  2. rpcRequest.setDeviceName("11a936267d2a4b6eb7b4cb8549fc1fa7");//設備接入時候得到ID
  3. rpcRequest.setProductKey(ProductKey);//設備接入時候填寫的ProductKey
  4. rpcRequest.setTimeOut(5000); //超時時間,單位毫秒.如果超過這個時間設備沒反應則返回"TIMEOUT"
  5. rpcRequest.setRpcContent("aGVsbG8gd29ybGQ=");//推送給設備的數據.數據要求二進製數據做一次BASE64編碼.(示例裏麵是"helloworld"編碼後的值)
  6. RevertRpcResponse rpcResponse = client.getAcsResponse(rpcRequest);
  7. System.out.println(rpcResponse.getResponseContent());//得到設備返回的數據信息.
  8. System.out.println(rpcResponse.getRpcCode());//對應的響應碼( TIMEOUT/SUCCESS/OFFLINE等)

最後更新:2016-12-20 11:02:13

  上一篇:go 總體說明__服務器端API_阿裏雲物聯網套件-阿裏雲
  下一篇:go 使用說明-php__SDK使用參考_服務器端API_阿裏雲物聯網套件-阿裏雲