设备注册
public class RegistDeviceTest {
public static void main(String[] args) {
DefaultAcsClient client = BaseTest.init();
RegistDeviceRequest request = new RegistDeviceRequest();
request.setProductKey("******");//产品Key,新建产品时可获得
request.setDeviceName("testDevice66");//设备名字
RegistDeviceResponse response = null;
try {
response = client.getAcsResponse(request);
} catch (ServerException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (ClientException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
System.out.println(ToStringBuilder.reflectionToString(response, ToStringStyle.SHORT_PREFIX_STYLE));
}
}
打印返回信息
RegistDeviceResponse[requestId=7F8B6ED5-32D4-4C8F-BC1A-E2624CEBA491,success=true,errorMessage=<null>,deviceId=******,deviceSecret=******,deviceStatus=<null>,deviceName=testDevice66]
设备注册就是在某个产品下新建一个设备。
只要设备的DeviceName参数即可,可以设空,如果名称为空则由阿里云生成设备名称默认与设备id一致。设备名称在产品内唯一,如果已存在则返回已有设备信息。
DeviceId //阿里云颁发的设备id 全局唯一
DeviceName//设备名称,用户自定义或系统生成
DeviceSecret//设备私钥
DeviceStatus//预留状态字段
ErrorMessage//错误信息
控制台显示