问题
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