我已经执行了这个例子
https://docs.microsoft.com/en-us/azure/iot-dps/quick-enroll-device-x509-java
它不会出现在"注册记录"在注册组下,但它会抛出此错误:
PROVISIONING_DEVICE_STATUS_FAILED,异常:com.microsoft.azure.sdk.iot.provisioning.device.internal.exceptions.ProvisioningDeviceHubException:签名证书信息与链元素不匹配
注册:
public class DeviceRegistration {
String idScope;
String globalEndpoint;
String clientCert;
String clientCertPrivateKey;
String signerCert;
public DeviceRegistration(String idScope, String globalEndpoint, String clientCert, String clientCertPrivateKey, String signerCert) {
this.idScope = idScope;
this.globalEndpoint = globalEndpoint;
this.clientCert = clientCert;
this.clientCertPrivateKey = clientCertPrivateKey;
this.signerCert = signerCert;
}
public void register(ProvisioningDeviceClientRegistrationCallback callback) throws Exception {
Collection<String> signerCertificates = new LinkedList<>();
signerCertificates.add(signerCert);
ProvisioningDeviceClient provisioningDeviceClient = null;
SecurityProvider securityProviderX509 = new SecurityProviderX509Cert(clientCert, clientCertPrivateKey, signerCertificates);
provisioningDeviceClient = ProvisioningDeviceClient.create(globalEndpoint, idScope, ProvisioningDeviceClientTransportProtocol.HTTPS,
securityProviderX509);
provisioningDeviceClient.registerDevice(callback, this);
}
private static String loadFile(String filename) throws Exception {
File f = new File(filename);
if (!f.exists())
throw new Exception("File not found: " + filename);
BufferedReader reader = new BufferedReader(new FileReader(f));
char[] buffer = new char[(int) f.length()];
reader.read(buffer);
reader.close();
return new String(buffer);
}
public static void main(String[] args){
try {
CountDownLatch countDownLatch = new CountDownLatch(1);
DeviceRegistration deviceRegistration = new DeviceRegistration(args[0], args[1], loadFile(args[2]), loadFile(args[3]), loadFile(args[4]));
deviceRegistration.register(new ProvisioningDeviceClientRegistrationCallback() {
@Override
public void run(ProvisioningDeviceClientRegistrationResult provisioningDeviceClientRegistrationResult, Exception e, Object context) {
if (provisioningDeviceClientRegistrationResult.getProvisioningDeviceClientStatus() == ProvisioningDeviceClientStatus.PROVISIONING_DEVICE_STATUS_ASSIGNED) {
System.out.println("IotHUb Uri : " + provisioningDeviceClientRegistrationResult.getIothubUri());
System.out.println("Device ID : " + provisioningDeviceClientRegistrationResult.getDeviceId());
countDownLatch.countDown();
} else {
System.out.println("Result: "+provisioningDeviceClientRegistrationResult.getProvisioningDeviceClientStatus()+", Exception: "+e);
}
}
});
countDownLatch.await();
} catch (Exception e) {
e.printStackTrace();
}
}}
答案 0 :(得分:0)
删除单个注册,并确保您已完成X.509签名证书的验证(在Azure门户的“证书”选项卡中)。如果您同时拥有注册组和设备的个人注册,则个人注册优先。