UpdateTwinAsync failing

强颜欢笑 提交于 2021-01-29 05:20:34

问题


I am trying to update the Module twin of an edge device. I can now retrieve the Device Twin for the module, but I cannot save the updated Desired properties back into the IoT Hub.

var moduleTwin = await registryManager.GetTwinAsync("DeviceId", "ModuleId");

moduleTwin.Properties.Desired["key"] = "value";

var updatedTwin = await registryManager.UpdateTwinAsync("DeviceId", moduleTwin, moduleTwin.ETag)

When this runs, I get the following exception

Where "DeviceId" is the value obscured in red.

I have tried using the device's ETag, but that just updated the device's twin and I have tried using the ModuleId rather then DeviceId and that raises a DeviceNotFoundException.

How do I update the ModuleTwin here?


回答1:


It seems that registryManager.UpdateTwinAsync can only update device twin. So when you use edge device twin Etag instead of moduleTwin.ETag, the operation will succeed. You can check your edge device, the desired property updated is under device twin not module twin.

Update module twin via Azure Portal seems also not working.

Here is a similar issue about this on Azure IOT SDK for C# you can monitor its update.



来源:https://stackoverflow.com/questions/51768883/updatetwinasync-failing

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!