[英]IoT Hub Device Provisioning Service (DPS) for Azure IoT Central (SaaS)
[英]How come a call to Twin.DeviceId is null after provisioning is successful in IoT Hub using DPS?
我有以下代码:
DeviceRegistrationResult dpsRegistrationWithEnrollmentGroupResult = await ProvisionDeviceViaEnrollmentGroupAsync(parameters, devicePrimaryKey, deviceSecondaryKey, cancellationToken);
// Create Device Client
var authMethodWithEnrollmentGroup = new DeviceAuthenticationWithRegistrySymmetricKey(dpsRegistrationWithEnrollmentGroupResult.DeviceId, devicePrimaryKey);
var options = new ClientOptions
{
ModelId = modelId,
};
DeviceClient deviceClient = DeviceClient.Create(hostname, authenticationMethod, TransportType.Mqtt, options);
var twin = await deviceClient .GetTwinAsync();
DeviceId = twin.DeviceId;
设备已配置,但 DeviceId 为 null。
我需要做什么才能获得实际的 DeviceId?
Twin.DeviceId
在设备 IoT 中心 SDK 上为 null,因为它是共享类型(位于 Microsoft.Azure.Devices.Shared.dll 中),由 IoT 中心服务 SDK 和预配服务 SDK 使用。 Twin class 具有所有 3 种场景中所有可用属性的超集。
设备 IoT 中心 API 只能访问孪生的所需和报告的属性。
如果您想知道设备 ID,它应该已经在DeviceRegistrationResult.DeviceId中的 DPS 注册调用中提供。
在 v2 预览版中,共享程序集被移除,因为这是一种糟糕的体验。 每个 SDK package 都有自己的类型,只包含与 package 相关的属性和功能。
客户端方法已从GetTwinAsync(...)
更改为GetTwinPropertiesAsync(...) ,返回类型现在称为TwinProperties ,只有两个子属性: Desired
和Reported
。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.