Device twins are JSON documents that have device state information including metadata, configurations, and conditions. A device twin is created and managed for each device connected to your IOT project that is added to the IoT Hub. The following article summarizes the key parts and functions of the Device Twin. For more detailed information visit the cited Microsoft Documentation.
The Device twin is used for several key applications and these include:
The Device Twin as a JSON document consists of the following elements: device twin tags for the backend to read and write to, desired properties which can be set so the device app can read these desired properties and apply those accordingly. The device app can also receive notifications of changes to the desired properties. In conjunction with desired properties, reported properties synchronize device configuration and settings. The device can also present reported properties so that the backend can read and query them. And the root of the JSON document contains device identity properties stored in the device identity registry which holds the information about which modules and devices are allowed to connect to IoT Hub.
On the high level the Device twin is a way to configure the device and to query information flowing from the device to the backend. In the typical scenario one needs two components: an application running on the device and the solution backend.
The solution backend can retrieve the Device twin from a given device by unique device ID together with tags and reported properties. Tags and desired properties can also be partially updated by the solution backend where the partial update is expressed as a JSON. The solution backend can also replace desired properties, tags and receive notifications as and when the Device twin is modified.
The device can retrieve the Device twin with desired properties which are supposed to be applied and processed by the device app to configure the device. In response, the device app can send its status as a set of the reported properties which are processed by the backend to update the latest device configuration and status. The Device twin and its reported properties should be only used though in scenarios when the backend is supposed to be updated with the information about the state of the device, not as a way of sending more frequent telemetry data for which different solutions should be used.
A full tutorial on how to get started with Device twins is available in the Microsoft Documentation.
Mender has an existing integration with Azure to synchronize device credentials for simplifying the device provisioning and management including device updates amongst other things. This integration is currently being further improved so that Mender users can provision and inspect devices registered in Azure IoT Hub through the Mender Web UI, and synchronize information about the device such as its software update status or configuration with the Azure Device Twin. This means that devices only need to be provisioned and managed in one place while the users get the benefits of both Mender and Azure for device fleet management at scale.
If you would like a sneak preview of these upcoming integration improvements, please visit our preview page and leave your email address.
To learn about device updating and device provisioning in Azure IoT, check our the following articles: