Search code examples
c#azureazure-iot-hubazure-iot-sdk

What is the difference between Microsoft.Azure.Devices.Device and Microsoft.Azure.Devices.Shared.Twin?


Assuming I want to load Device information using Microsoft.Azure.Devices package/SDK, does is make any difference which I call:

RegistryManager regManager = RegistryManager.CreateFromConnectionString(connectionString);

Device device = await regManager.GetDeviceAsync("Device_1");
// OR
Twin twin = (await regManager.CreateQuery("SELECT * FROM devices WHERE deviceId = 'Device_1'")
            .GetNextAsTwinAsync())
            .First();

Both Device and Twin seem to share most properties. Twin is more generic and can be used to query Modules and can be used to read Tags, Desired/Reported properties. But other than that they seem to have more or less the same information, unless I'm missing something.

So I'm just wondering, are there any underlying differences or are the two basically the same?


Solution

  • Although they share some properties, they are not the same.

    "Device" is a simple type that is available in all Hub SKUs (basic, standard and free). It reports properties about the status and identity of a device.

    "Twin" is type that exposes the powerful concept of the device twin, which enables the device to report application specific status and the backend to apply settings to the device. It does so via a JSON document that the IoTHub maintains and synchronizes for each device. This feature is only available in standard and free SKUs (not available in basic).

    Read more about it here: https://learn.microsoft.com/en-us/azure/iot-hub/iot-hub-devguide-device-twins