1

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

enter image description here

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?

Colin Desmond
  • 4,824
  • 4
  • 46
  • 67
  • So I solved this myself, it looks like I was using the wrong overload of UpdateTwinAsync, it should have been the UpdateTwinAsync(deviceId, MODULEID, module, module.etag) version. – Colin Desmond Aug 16 '18 at 10:38

2 Answers2

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.

Rita Han
  • 9,574
  • 1
  • 11
  • 24
0

I passed by this old thread and saw this message so I wanted to give an update: We can now update the modules twin.

see: https://learn.microsoft.com/en-us/dotnet/api/microsoft.azure.devices.registrymanager.updatetwinasync?view=azure-dotnet