RegistryManager.UpdateTwins2Async method doesn't work when trying to update a module twin, instead it updates the device twin itself.
I checked with Fiddler, and the request body indeed lacks the moduleId property. I added it manually and sent the request again and the module twin updated as expected.
var twin = new Twin();
twin.ModuleId = "mymod";
twin.DeviceId = "device1";
twin.Tags = new TwinCollection();
twin.Tags["mytag"] = "tag";
var rm = RegistryManager.CreateFromConnectionString("<connstring>");
rm.UpdateTwins2Async(new List<Twin> { twin }, true).Wait();
Thanks for reporting @galmicrosoft ! We'll need to take a look to see why this isn't working.
It seems can't update module twin. I use the following code:
var moduleTwin = await registryManager.GetTwinAsync(deviceID, moduleID);
moduleTwin.Properties.Desired["key"] = "value";
var updatedTwin = await registryManager.UpdateTwinAsync(moduleTwin.DeviceId, moduleTwin, moduleTwin.ETag);
When I use moduleTwin.ETag it gives me the following error:
PreconditionFailedException: Precondition failed: {"Message":"ErrorCode:PreconditionFailed;ETag mismatch for device ID 'edgedevicev2'","ExceptionMessage":"Tracking ID:0d8be9a5ec3f4de5ac4ab7ba289ac840-G:0-TimeStamp:08/10/2018 03:23:13"}
When I use device twin Etag it update device twin but not module twin.
Is it able to update module twin?
@galmicrosoft, @CIPop, @luyaok, thank you for your contribution to our open-sourced project! Please help us improve by filling out this 2-minute customer satisfaction survey
Hello,
Wanted to point out that the fix was made to updatetwin2sync method and not updatetwinsync method which still doesn't work for me
Most helpful comment
It seems can't update module twin. I use the following code:
var moduleTwin = await registryManager.GetTwinAsync(deviceID, moduleID); moduleTwin.Properties.Desired["key"] = "value"; var updatedTwin = await registryManager.UpdateTwinAsync(moduleTwin.DeviceId, moduleTwin, moduleTwin.ETag);When I use moduleTwin.ETag it gives me the following error:
PreconditionFailedException: Precondition failed: {"Message":"ErrorCode:PreconditionFailed;ETag mismatch for device ID 'edgedevicev2'","ExceptionMessage":"Tracking ID:0d8be9a5ec3f4de5ac4ab7ba289ac840-G:0-TimeStamp:08/10/2018 03:23:13"}When I use device twin Etag it update device twin but not module twin.
Is it able to update module twin?