Simone Spagna
Simone Spagna

Reputation: 644

DeviceTwin issue in updating properties

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.

Upvotes: 2

Views: 466

Answers (1)

Roman Kiss
Roman Kiss

Reputation: 8265

The device twin reported properties are readonly on the service-facing side. See more details here

Upvotes: 1

Related Questions