3

I am using the API:

RegistryManager.UpdateTwinAsync(string deviceId, Twin twinPatch, string etag);

However, it need to call device's twin first:

Twin twin= await _registryManager.GetTwinAsync(deviceId);
var etag = twin.Etag

So I need to 2 I/O call, that decreases application performance.

Is there any way to set device's twin without getting Etag first?

Thanks,

Phat Huynh
  • 43
  • 3
  • In the case of device twin at the service-facing side such as tags and desired properties, the REST PATCH can be used, see more details: https://learn.microsoft.com/en-us/rest/api/iothub/service/updatetwin In the case of initialize a device, I do recommend to use registryManager.ImportDevicesAsync job method. Note, that the runtime owner of the device twin reported properties is a device-facing endpoint. – Roman Kiss Oct 08 '18 at 06:19

1 Answers1

1

You could use DeviceClient's UpdateReportedPropertiesAsync or, if you want to serialize you data yourself, SendEventAsync(Message message).

DeviceClient is in Microsoft.Azure.Devices.Client library.

Also, you can cache the etag to improve performance (but that depends on how you app works).

tymtam
  • 31,798
  • 8
  • 86
  • 126