Azure / azure-iot-explorer

Cross-platform UI for interacting with devices attached to Azure IoT Hub. This tool is meant for learning and testing, not for production environment.
MIT License
224 stars 71 forks source link

[QUESTION] How set desired and reported properties for device twin in IoT Plug and Play DTDL model #599

Closed sergiosolorzano closed 1 year ago

sergiosolorzano commented 1 year ago

I have this dtdl model I upload to local folder in IoT Plug and Play v0.15.4.0 (prior version behaviour is the same):


"@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"
    }
]
}````

My expectation is that because properties ledState and Alert properties are writeable, these should be both reported and desired properties. However the IoT Hub Device in Azure portal (see below) shows them differently and I don't know why. How do I set the properties in the DTDL model I upload to IoT P&P to be reported or desired?

````{
"deviceId": "mymxchip",
"etag": "AAAAAAAAAAk=",
"deviceEtag": "NDU1NDk0NDM4",
"status": "enabled",
"statusUpdateTime": "0001-01-01T00:00:00Z",
"connectionState": "Connected",
"lastActivityTime": "2023-01-09T07:26:48.611708Z",
"cloudToDeviceMessageCount": 0,
"authenticationType": "sas",
"x509Thumbprint": {
    "primaryThumbprint": null,
    "secondaryThumbprint": null
},
"modelId": "dtmi:com:sergio:devkit;1",
"version": 164,
"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-09T07:28:26.0068306Z",
            "deviceInformation": {
                "$lastUpdated": "2023-01-09T07:28:25.4599426Z",
                "__t": {
                    "$lastUpdated": "2023-01-09T07:28:25.4599426Z"
                },
                "manufacturer": {
                    "$lastUpdated": "2023-01-09T07:28:25.4599426Z"
                },
                "model": {
                    "$lastUpdated": "2023-01-09T07:28:25.4599426Z"
                },
                "swVersion": {
                    "$lastUpdated": "2023-01-09T07:28:25.4599426Z"
                },
                "osName": {
                    "$lastUpdated": "2023-01-09T07:28:25.4599426Z"
                },
                "processorArchitecture": {
                    "$lastUpdated": "2023-01-09T07:28:25.4599426Z"
                },
                "processorManufacturer": {
                    "$lastUpdated": "2023-01-09T07:28:25.4599426Z"
                },
                "totalStorage": {
                    "$lastUpdated": "2023-01-09T07:28:25.4599426Z"
                },
                "totalMemory": {
                    "$lastUpdated": "2023-01-09T07:28:25.4599426Z"
                }
            },
            "ledState": {
                "$lastUpdated": "2023-01-09T07:28:25.7411971Z"
            },
            "telemetryInterval": {
                "$lastUpdated": "2023-01-09T07:28:26.0068306Z",
                "ac": {
                    "$lastUpdated": "2023-01-09T07:28:26.0068306Z"
                },
                "av": {
                    "$lastUpdated": "2023-01-09T07:28:26.0068306Z"
                },
                "value": {
                    "$lastUpdated": "2023-01-09T07:28:26.0068306Z"
                }
            }
        },
        "$version": 155
    }
},
"capabilities": {
    "iotEdge": false
}````

**Describe the bug**
A clear and concise description of what the bug is.

**To Reproduce**
Steps to reproduce the behavior:
1. Go to '...'
2. Click on '....'
3. Scroll down to '....'
4. See error

**Expected behavior**
both ledState and Alarm properties are reported and desired properties

**Desktop (please complete the following information):**
 - OS: WIN11
 - App version 0.15.4.0

**Additional context**
sergiosolorzano commented 1 year ago

Resolved, I was confused, it's now clear the reported/desired properties in device twin is what's happened with those properties. stackoverflow answer here