You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: articles/digital-twins/how-to-manage-twin.md
+13-13Lines changed: 13 additions & 13 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -44,9 +44,9 @@ To create a digital twin, you need to provide:
44
44
* An ID value you want to assign to the digital twin (you're defining that ID when the twin is created)
45
45
* The [model](concepts-models.md) you want to use
46
46
* Any desired initialization of twin data, including...
47
-
- Properties (optional to initialize): You can set initial values for properties of the digital twin if you want. Properties are treated as optional and can be set later, but note that **they won't show up as part of a twin until they've been set**.
48
-
- Telemetry (recommended to initialize): You can also set initial values for telemetry fields on the twin. Although initializing telemetry isn't required, telemetry fields also won't show up as part of a twin until they've been set. This means that **you'll be unable to edit telemetry values for a twin unless they've been initialized first**.
49
-
- Components (required to initialize if present on twin): If your twin contains any [components](concepts-models.md#model-attributes), these must be initialized when the twin is created. They can be empty objects, but the components themselves have to exist.
47
+
- Properties (initialization optional): You can set initial values for properties of the digital twin if you want. Properties are treated as optional and can be set later, but note that **they won't show up as part of a twin until they've been set**.
48
+
- Telemetry (initialization recommended): You can also set initial values for telemetry fields on the twin. Although initializing telemetry isn't required, telemetry fields also won't show up as part of a twin until they've been set. This means that **you'll be unable to edit telemetry values for a twin unless they've been initialized first**.
49
+
- Components (initialization required if they're present on a twin): If your twin contains any [components](concepts-models.md#model-attributes), these must be initialized when the twin is created. They can be empty objects, but the components themselves have to exist.
50
50
51
51
The model and any initial property values are provided through the `initData` parameter, which is a JSON string containing the relevant data. For more information on structuring this object, continue to the next section.
52
52
@@ -86,7 +86,7 @@ You can access the details of any digital twin by calling the `GetDigitalTwin()`
Thiscallreturnstwindataasastrongly-typedobjecttypesuchas `BasicDigitalTwin`. `BasicDigitalTwin` isaserializationhelperclassincludedwiththeSDK, whichwillreturnthecoretwinmetadataandpropertiesinpre-parsedform. YoucanalwaysdeserializetwindatausingtheJSONlibraryofyourchoice, like `System.Text.Json` or `Newtonsoft.Json`. Forbasicaccesstoatwin, however, thehelperclassescanmakethismoreconvenient.
89
+
Thiscallreturnstwindataasastronglytypedobjecttypesuchas `BasicDigitalTwin`. `BasicDigitalTwin` isaserializationhelperclassincludedwiththeSDK, whichwillreturnthecoretwinmetadataandpropertiesinpre-parsedform. YoucanalwaysdeserializetwindatausingtheJSONlibraryofyourchoice, like `System.Text.Json` or `Newtonsoft.Json`. Forbasicaccesstoatwin, however, thehelperclassescanmakethismoreconvenient.
Thedefinedpropertiesofthedigitaltwinarereturnedastop-levelpropertiesonthedigitaltwin. Metadataorsysteminformationthatisn't part of the DTDL definition is returned with a `$` prefix. Metadata properties include the following values:
* `$etag`:AstandardHTTPfieldassignedbythewebserver. Thisisupdatedtoanewvalueeverytimethetwinisupdated, whichcanbeusefultodeterminewhetherthetwin's data has been updated on the server since a previous check. You can use `If-Match` to perform updates and deletes that only complete if the entity'setagmatchestheetagprovided. Formoreinformationontheseoperations, seethedocumentationfor [DigitalTwinsUpdate](/rest/api/digital-twins/dataplane/twins/digitaltwins_update) and [DigitalTwinsDelete](/rest/api/digital-twins/dataplane/twins/digitaltwins_delete).
140
140
* `$metadata`:Asetofotherproperties, including:
141
141
-TheDTMIofthemodelofthedigitaltwin.
142
-
-Synchronizationstatusforeachwritableproperty. Thisismostusefulfordevices, whereit's possible that the service and the device have diverging statuses (for example, when a device is offline). Currently, this property only applies to physical devices connected to IoT Hub. With the data in the metadata section, it is possible to understand the full status of a property, as well as the last modified timestamps. For more information about sync status, see this [IoT Hub tutorial](../iot-hub/tutorial-device-twins.md) on synchronizing device state.
142
+
-Synchronizationstatusforeachwritableproperty. Thisismostusefulfordevices, whereit's possible that the service and the device have diverging statuses (for example, when a device is offline). Currently, this property only applies to physical devices connected to IoT Hub. With the data in the metadata section, it'spossibletounderstandthefullstatusofaproperty, aswellasthelastmodifiedtimestamps. Formoreinformationaboutsyncstatus, seethis [IoTHubtutorial](../iot-hub/tutorial-device-twins.md) onsynchronizingdevicestate.
Youcanreadmoreabouttheserializationhelperclasseslike `BasicDigitalTwin` in [AzureDigitalTwinsAPIsandSDKs](concepts-apis-sdks.md#serialization-helpers).
@@ -148,7 +148,7 @@ You can read more about the serialization helper classes like `BasicDigitalTwin`
@@ -165,11 +165,11 @@ A single patch call can update as many properties on a single twin as you want (
165
165
> [!TIP]
166
166
>Aftercreatingorupdatingatwin, theremaybealatencyofupto10secondsbeforethechangeswillbereflectedin [queries](how-to-query-graph.md). The `GetDigitalTwin` API (described [earlierinthisarticle](#get-data-for-a-digital-twin)) doesnotexperiencethisdelay, sousetheAPIcallinsteadofqueryingtoseeyournewly-updatedtwinsifyouneedaninstantresponse.
Here's an example of JSON Patch code. This document replaces the *mass* and *radius* property values of the digital twin it'sappliedto. ThisexampleshowstheJSONPatch `replace` operation, whichreplacesthevalueofanexistingproperty.
Whenupdatingatwinfromacodeprojectusingthe .NETSDK, youcancreateJSONpatchesusingtheAzure .NETSDK's [JsonPatchDocument](/dotnet/api/azure.jsonpatchdocument?view=azure-dotnet&preserve-view=true). Here is an example of creating a JSON Patch document and using `UpdateDigitalTwin()` in project code.
Whenatwiniscreatedusingthismodel, it's not necessary to instantiate the `ObjectProperty` at that time. If the object property is not instantiated during twin creation, there is no default path created to access `ObjectProperty` and its `StringSubProperty` for a patch operation. You will need to add the path to `ObjectProperty` yourself before you can update its properties.
193
+
Whenatwiniscreatedusingthismodel, it's not necessary to instantiate the `ObjectProperty` at that time. If the object property isn'tinstantiatedduringtwincreation, there's no default path created to access `ObjectProperty` and its `StringSubProperty` for a patch operation. You'llneedtoaddthepathto `ObjectProperty` yourselfbeforeyoucanupdateitsproperties.
Althoughthefirststepisn't necessary in cases where `ObjectProperty` was instantiated when the twin was created, it'srecommendedtouseiteverytimeyouupdateasub-propertyforthefirsttime, sinceyoumaynotalwaysknowforsurewhethertheobjectpropertywasinitiallyinstantiatedornot.
210
+
Althoughthefirststepisn't necessary in cases where `ObjectProperty` was instantiated when the twin was created, it'srecommendedtouseiteverytimeyouupdateasub-propertyforthefirsttime, sinceyoumaynotalwaysknowwithcertaintywhethertheobjectpropertywasinitiallyinstantiatedornot.
211
211
212
212
### Update a digital twin's model
213
213
@@ -230,15 +230,15 @@ The patch for this situation needs to update both the model and the twin's tempe
230
230
231
231
### Update a property's sourceTime
232
232
233
-
Youmayoptionallydecidetousethe `sourceTime` fieldontwinpropertiestorecordtimestampsforwhenpropertyupdatesareobservedintherealworld. AzureDigitalTwinsnativelysupports `sourceTime` inthemetadataforeachtwinproperty. The `sourceTime` valuemustcomplytoISO8601dateandtimeformat. Formoreinformationaboutthisfieldandotherfieldsondigitaltwins, see [DigitaltwinJSONformat](concepts-twins-graph.md#digital-twin-json-format).
233
+
Youmayoptionallydecidetousethe `sourceTime` fieldontwinpropertiestorecordtimestampsforwhenpropertyupdatesareobservedintherealworld. AzureDigitalTwinsnativelysupports `sourceTime` inthemetadataforeachtwinproperty. The `sourceTime` valuemustcomplywithISO8601dateandtimeformat. Formoreinformationaboutthisfieldandotherfieldsondigitaltwins, see [DigitaltwinJSONformat](concepts-twins-graph.md#digital-twin-json-format).
234
234
235
235
TheminimumstableRESTAPIversiontosupportthisfieldisthe [2022-05-31](https://github.com/Azure/azure-rest-api-specs/tree/main/specification/digitaltwins/data-plane/Microsoft.DigitalTwins/stable/2022-05-31) version. To work with this field using the [Azure Digital Twins SDKs](concepts-apis-sdks.md), we recommend using the latest version of the SDK to make sure this field is included.
0 commit comments