代码如下:
public class DeviceDemo {
public static String ACCESS_KEY_ID = "d705dc8058fb47adb14a0b40078bf36e"; // 用户的Access
// Key
// ID
public static String SECRET_ACCESS_KEY = "16ca7c2f2906417da824eed0ad83f44e"; // 用户的Secret
// Access
// Key
public static String ENDPOINT = "347c71eb7f424a4f9c6f552b72eafa41.mqtt.iot.gz.baidubce.com";
public static IotDmClient getIotDmClientHttp() {
// 创建配置
BceClientConfiguration config = new BceClientConfiguration()
.withCredentials(
new DefaultBceCredentials(ACCESS_KEY_ID,
SECRET_ACCESS_KEY)).withEndpoint(ENDPOINT);
config.withProtocol(Protocol.HTTP);
// 初始化一个IotDmClient
IotDmClient client = new IotDmClient(config);
return client;
}
public static IotDmClient getIotDmClientHttps() {
// 创建配置
BceClientConfiguration config = new BceClientConfiguration()
.withProtocol(Protocol.HTTPS) // 使用HTTPS协议
.withCredentials(
new DefaultBceCredentials(ACCESS_KEY_ID,
SECRET_ACCESS_KEY)).withEndpoint(ENDPOINT);
// 初始化一个IotDmClient
IotDmClient client = new IotDmClient(config);
return client;
}
public static List getDevices() {
DeviceAccessDetail detail = getIotDmClientHttp().getDeviceAccessDetail(
"mylight1");
// 获取通信协议,当前为mqtt
String protocol = detail.getProtocol();
// 获取设备接入的IoT Hub endpoint
List endpoints = detail.getEndpoints();
// 获取设备pub到物管理服务的topic信息
List pubTopics = detail.getPubTopics();
// 获取设备sub物管理服务的topic信息
List subTopics = detail.getSubTopics();
// System.out.println(getIotDmClientHttps().getRootGroups());
// DeviceQueryResponse response =
// getIotDmClientHttps().getDeviceProfiles(
// new DeviceQueryRequest().withCondition("{}"));
//
// // 获取设备信息列表
// List profiles = response.getDeviceProfiles();
//
return null;
}
public static void main(String[] args) {
getDevices();
}
}