MicrosoftDocs / azure-docs

Open source documentation of Microsoft Azure
https://docs.microsoft.com/azure
Creative Commons Attribution 4.0 International
10.27k stars 21.45k forks source link

it would really help if you say how to set a property as desired or reported in the dtdl model of the device twin or digital twin #103555

Closed sergiosolorzano closed 1 year ago

sergiosolorzano commented 1 year ago

it would really help if you say how to set a property as desired or reported in the dtdl model of the device twin or digital twin


Document Details

Do not edit this section. It is required for learn.microsoft.com ➟ GitHub issue linking.

Naveenommi-MSFT commented 1 year ago

@sergiosolorzano Thank you for bringing this to our attention. I've delegated this to content author @dominicbetts, who will review it and offer his insightful opinions.

sergiosolorzano commented 1 year ago

Thank you @Naveenommi-MSFT @dominicbetts Let me please give you an example, this is the DT DTDL model I upload to DT and Device Twin:

`{ "@id": "dtmi:com:sergio:devkit;1", "@type": "Interface", "@context": [ "dtmi:dtdl:context;2" ], "displayName": "Machine Part -v1", "description": "Machine Part data", "contents": [ { "@type": "Property", "name": "telemetryInterval", "displayName": "telemetryInterval", "description": "The time interval of this data", "schema": "double", "writable": true }, { "@type": "Property", "name": "PartId", "displayName": "PartId", "description": "The unique id of the machine part", "writable": true, "schema": "string" },

    {
        "@type": "Property",
        "name": "Alert",
        "displayName": "Alert",
        "description": "whether or not this machine part needs maintenance",
        "writable": true,
        "schema": "boolean"
    },
    {
        "@type": "Property",
        "name": "ledState",
        "displayName": "LED state",
        "description": "Returns the current state of the onboard LED.",
        "writable": true,
        "schema": "boolean"
    },
    {
        "@type": "Telemetry",
        "name": "Description",
        "schema": "string"
    },
    {
        "@type": "Telemetry",
        "name": "Code",
        "schema": "integer"
    },
    {
        "@type": "Telemetry",
        "name": "Temperature",
        "displayName": "Temperature",
        "schema": "double"
    },
    {
        "@type": "Telemetry",
        "name": "Humidity",
        "displayName": "Humidity",
        "schema": "double"
    },
    {
        "@type": "Telemetry",
        "name": "pressure",
        "displayName": "Pressure",
        "schema": "double"
    },
    {
        "@type": "Telemetry",
        "name": "magnetometerX",
        "displayName": "Magnetometer X / mgauss",
        "schema": "double"
    },
    {
        "@type": "Telemetry",
        "name": "magnetometerY",
        "displayName": "Magnetometer Y / mgauss",
        "schema": "double"
    },
    {
        "@type": "Telemetry",
        "name": "magnetometerZ",
        "displayName": "Magnetometer Z / mgauss",
        "schema": "double"
    },
    {
        "@type": "Telemetry",
        "name": "accelerometerX",
        "displayName": "Accelerometer X",
        "schema": "double"
    },
    {
        "@type": "Telemetry",
        "name": "accelerometerY",
        "displayName": "Accelerometer Y",
        "schema": "double"
    },
    {
        "@type": "Telemetry",
        "name": "accelerometerZ",
        "displayName": "Accelerometer Z",
        "schema": "double"
    },
    {
        "@type": "Telemetry",
        "name": "gyroscopeX",
        "displayName": "Gyroscope X",
        "schema": "double"
    },
    {
        "@type": "Telemetry",
        "name": "gyroscopeY",
        "displayName": "Gyroscope Y",
        "schema": "double"
    },
    {
        "@type": "Telemetry",
        "name": "gyroscopeZ",
        "displayName": "Gyroscope Z",
        "schema": "double"
    }
]

}`

Device Twin shows these Alert as desired property and ledState as reported property. By setting both these properties to writable I would have expected both properties to be reported AND desired.

"Another important thing is that we have marked both the property, and the object inside of it, as writeable. This field allows us to consider the decodedPayload as a reported and desired property." why isn't this the case?


    "deviceId": "mymxchip",
    "etag": "AAAAAAAAAAk=",
    "deviceEtag": "NDU1NDk0NDM4",
    "status": "enabled",
    "statusUpdateTime": "0001-01-01T00:00:00Z",
    "connectionState": "Connected",
    "lastActivityTime": "2023-01-08T09:24:49.6467197Z",
    "cloudToDeviceMessageCount": 0,
    "authenticationType": "sas",
    "x509Thumbprint": {
        "primaryThumbprint": null,
        "secondaryThumbprint": null
    },
    "modelId": "dtmi:com:sergio:devkit;1",
    "version": 152,
    "properties": {
        "desired": {
            "telemetryInterval": 5,
            "Alert": true,
            "$metadata": {
                "$lastUpdated": "2023-01-08T07:27:01.9659284Z",
                "$lastUpdatedVersion": 9,
                "telemetryInterval": {
                    "$lastUpdated": "2023-01-08T06:54:11.9502921Z",
                    "$lastUpdatedVersion": 8
                },
                "Alert": {
                    "$lastUpdated": "2023-01-08T07:27:01.9659284Z",
                    "$lastUpdatedVersion": 9
                }
            },
            "$version": 9
        },
        "reported": {
            "deviceInformation": {
                "__t": "c",
                "manufacturer": "MXCHIP",
                "model": "AZ3166",
                "swVersion": "1.0.0",
                "osName": "Azure RTOS",
                "processorArchitecture": "Arm Cortex M4",
                "processorManufacturer": "STMicroelectronics",
                "totalStorage": 1024,
                "totalMemory": 128
            },
            "ledState": false,
            "telemetryInterval": {
                "ac": 200,
                "av": 1,
                "value": 5
            },
            "$metadata": {
                "$lastUpdated": "2023-01-09T06:53:42.4705247Z",
                "deviceInformation": {
                    "$lastUpdated": "2023-01-09T06:53:41.9392674Z",
                    "__t": {
                        "$lastUpdated": "2023-01-09T06:53:41.9392674Z"
                    },
                    "manufacturer": {
                        "$lastUpdated": "2023-01-09T06:53:41.9392674Z"
                    },
                    "model": {
                        "$lastUpdated": "2023-01-09T06:53:41.9392674Z"
                    },
                    "swVersion": {
                        "$lastUpdated": "2023-01-09T06:53:41.9392674Z"
                    },
                    "osName": {
                        "$lastUpdated": "2023-01-09T06:53:41.9392674Z"
                    },
                    "processorArchitecture": {
                        "$lastUpdated": "2023-01-09T06:53:41.9392674Z"
                    },
                    "processorManufacturer": {
                        "$lastUpdated": "2023-01-09T06:53:41.9392674Z"
                    },
                    "totalStorage": {
                        "$lastUpdated": "2023-01-09T06:53:41.9392674Z"
                    },
                    "totalMemory": {
                        "$lastUpdated": "2023-01-09T06:53:41.9392674Z"
                    }
                },
                "ledState": {
                    "$lastUpdated": "2023-01-09T06:53:42.2048917Z"
                },
                "telemetryInterval": {
                    "$lastUpdated": "2023-01-09T06:53:42.4705247Z",
                    "ac": {
                        "$lastUpdated": "2023-01-09T06:53:42.4705247Z"
                    },
                    "av": {
                        "$lastUpdated": "2023-01-09T06:53:42.4705247Z"
                    },
                    "value": {
                        "$lastUpdated": "2023-01-09T06:53:42.4705247Z"
                    }
                }
            },
            "$version": 143
        }
    },
    "capabilities": {
        "iotEdge": false
    }
}````

Furthermore, is Alert and LedState a reported or desired property for the Digital Twin? It doesn't say in the model shown in DT in Azure:

<img width="1267" alt="image" src="https://user-images.githubusercontent.com/24430655/211255342-2d051ad1-f776-48b2-8c18-e2a391b541c8.png">
dominicbetts commented 1 year ago

Hi - I left some information for you in the StackOverflow question you posted on the same topic https://stackoverflow.com/questions/75054283/how-set-desired-and-reported-properties-for-device-twin-in-iot-plug-and-play-dtd

I'll close this issue and we can continue in StackOverflow.

dominicbetts commented 1 year ago

please-close