I have a problem updating a property attribute with DeviceTwin in c #.
The code I execute is the following:
var registryManager = RegistryManager.CreateFromConnectionString(AppSettings.KeyIoT);
var twin = await registryManager.GetTwinAsync(dto.DeviceIdorId);
TwinCollection s = twin.Properties.Reported["Power"];
Power toRet = JsonConvert.DeserializeObject<Power>(s.ToJson());
toRet.MaximumAvailable = 50;
var patch =
@"{
properties: {
reported:{
Power:" + JsonConvert.SerializeObject(toRet) +
@"}
}
}";
await registryManager.UpdateTwinAsync(twin.DeviceId, patch, twin.ETag);
I tried also with the following code :
var registryManager = RegistryManager.CreateFromConnectionString(AppSettings.KeyIoT);
var twin = await registryManager.GetTwinAsync(dto.DeviceIdorId);
TwinCollection s = twin.Properties.Reported["Power"];
Power toRet = JsonConvert.DeserializeObject<Power>(s.ToJson());
toRet.MaximumAvailable = 50;
twin.Properties.Reported["Power"] = JsonConvert.SerializeObject(toRet);
Twin updatedTwin = await registryManager.UpdateTwinAsync(twin.DeviceId, twin, twin.ETag);
The problem is that after the update, if I do a reread, the property MaximumAvailable is not updated. What am I doing wrong? Thanks.