Closed EGitDeveloper closed 4 months ago
Well, the value should be a double, instead of string/boolean
Can you clarify which APIs/SDKs are you using for Central and ADT?
Central: https://docs.microsoft.com/en-us/rest/api/iotcentral/1.1-previewdataplane/devices/update-properties ADT: https://docs.microsoft.com/en-us/rest/api/digital-twins/dataplane/twins/digitaltwins_update https://github.com/Azure/azure-iot-sdk-node/blob/main/service/samples/javascript/update_digital_twin.js
Well, the value should be a double, instead of
string/boolean
Can you clarify which APIs/SDKs are you using for Central and ADT?
Central: https://docs.microsoft.com/en-us/rest/api/iotcentral/1.1-previewdataplane/devices/update-properties ADT: https://docs.microsoft.com/en-us/rest/api/digital-twins/dataplane/twins/digitaltwins_update https://github.com/Azure/azure-iot-sdk-node/blob/main/service/samples/javascript/update_digital_twin.js
I'm working on my own API and solution that is neither based on IOT Central or Digital Twins service, however I'm using both of them as a reference/learning tool. That's why I'm wondering how I could design my solution to mimic IOT Central/Digital Twins service and refuse updates that break the DTDL model.
To update DT or call commands I've used the following examples. My solution is based on IoT Hub and Plug and Play Digital Twins.
Say my personal API has PATCH endpoint to update DT that accepts PATCH body - how do I validate PATCH request against DTDL model? "To update property on device with XYZ DTDL model you need to provide X type of a value, but you have provided Y, therefore you get BAD REQUEST response."
Got it,
Unfortunately, we don't have any API to validate payloads against a given DTDL interface. This is a feature that we are actively investigating.
Would you like to provide feedback in a 30 mins chat? you can reach out to me: rmpablos at microsoft dot com
-Rido
That was basically it. I was researching Plug & Play Digital Twins and wondering if there's any public API/SDK that I can use to validate update payload against DTDL model. Azure IOT Central and Digital Twins service both do it so I thought I might have missed documentation somewhere.
Thank you for clarification.
Thanks for the feedback,
I will keep this issue open until we publish some validation APIs.
Thanks, Rido
Hi @EGitDeveloper
Let me correct myself:
We have published a preview parser that includes a validation api, the following code snippet shows how to validate a payload.
var objectModel = new ModelParser().Parse(new string[] { ReadFile("geotypes-1.json") });
var rootInterface = (DTInterfaceInfo)objectModel[new Dtmi("dtmi:samplesv2:geoTypes;1")];
var myPoint = (DTTelemetryInfo)rootInterface.Contents["myPoint"];
var validPayload = myPoint.Schema.ValidateInstance(ToJs(new { type = "Point", coordinates = new double[] { 12.35, 23.56} }));
Console.WriteLine(validPayload);
var myGeopoint = (DTTelemetryInfo)rootInterface.Contents["myGeopoint"];
var validPayload2 = myGeopoint.Schema.ValidateInstance(ToJs(new { lat =12.35, lon = 23.56 }));
Console.WriteLine(validPayload2);
{
"@context": [
"dtmi:dtdl:context;2",
"dtmi:iotcentral:context;2"
],
"@id": "dtmi:samplesv2:geoTypes;1",
"@type": "Interface",
"contents": [
{
"@type": "Telemetry",
"name": "myPoint",
"schema": "point"
},
{
"@type": ["Telemetry", "Location"],
"name": "myGeopoint",
"schema": "geopoint"
}
]
}
full gist is available here
Thank you for update! Looking forward to testing it out,
Hi @EGitDeveloper
Does this API solve your problem? If so, can you close this issue?
closing due to lack of response
My apologies in advance if this is not correct place to ask the question.
In Azure IoT Central and Azure Digital Twin service, if I create and upload model with the following property:
And I try to update writable property with string/boolean - update fails.
Are there any specific libraries, SDKs or examples that I can use or reference to implement same kind of functionality in my application? That is, validate that updates conform with DTDL model.