模块孪生回空

时间:2018-08-08 13:37:56

标签: azure-iot-edge

我正在尝试在Module的设备孪生节点上设置所需的属性,但是当我从IoT中心检索孪生节点时,它返回的都是空值。

var moduleClient = ModuleClient.CreateFromConnectionString(connectionString);
var moduleTwin = await moduleClient.GetTwinAsync();

当我在调试器中检查moduleTwin时,会得到

debugger showing all properties as null

连接字符串是模块的一个,是从IoT中心复制的。

知道我在做什么错吗?

1 个答案:

答案 0 :(得分:2)

这是设计使然。因此,预计会出现此问题。

在模块应用程序中,仅具有读取所需属性和读取/写入报告的属性的权限。请参阅以下内容:

enter image description here

要访问所有孪生模块,可以从解决方案后端进行操作,并且需要ServiceConnect权限。模块孪生是新添加的。您需要Microsoft.Azure.Devices V1.16.0-preview-001或更高版本。以下是控制台应用程序示例。

        RegistryManager registryManager = RegistryManager.CreateFromConnectionString(connectionString);
        Module module;

        var moduleTwin = await registryManager.GetTwinAsync(deviceID, moduleID);

enter image description here

参考:

understand and use module twins in IoT Hub

Get started with IoT Hub module identity and module twin using .NET back end and .NET device

相关问题