如何使用节点 js sdk 'azure-iothub' 从 IOT HUB 获取 "connectionStateUpdatedTime"

how to get "connectionStateUpdatedTime" from IOT HUB using node js sdk 'azure-iothub'

我正在使用“('azure-iothub').Registry”获取设备孪生数据。

strQuery = `SELECT * FROM devices where deviceId IN [${deviceIds}]`;
query = registry.createQuery(strQuery, 500);

但设备孪生没有“connectionStateUpdatedTime”属性。 根据 MS 文档,它位于设备标识中。 https://docs.microsoft.com/en-us/azure/iot-hub/iot-hub-devguide-identity-registry#device-identity-properties

有没有办法获取“connectionStateUpdatedTime”属性?

您将无法使用 above approach 获得 connectionStateUpdatedTime,因为它 returns 下面的架构:

{
    "deviceId": "myDeviceId",
    "etag": "AAAAAAAAAAc=",
    "status": "enabled",
    "statusUpdateTime": "0001-01-01T00:00:00",
    "connectionState": "Disconnected",
    "lastActivityTime": "0001-01-01T00:00:00",
    "cloudToDeviceMessageCount": 0,
    "authenticationType": "sas",
    "x509Thumbprint": {
        "primaryThumbprint": null,
        "secondaryThumbprint": null
    },
    "version": 2,
    "tags": {
        "location": {
            "region": "US",
            "plant": "Redmond43"
        }
    },
    "properties": {
        "desired": {
            "telemetryConfig": {
                "configId": "db00ebf5-eeeb-42be-86a1-458cccb69e57",
                "sendFrequencyInSecs": 300
            },
            "$metadata": {
            ...
            },
            "$version": 4
        },
        "reported": {
            "connectivity": {
                "type": "cellular"
            },
            "telemetryConfig": {
                "configId": "db00ebf5-eeeb-42be-86a1-458cccb69e57",
                "sendFrequencyInSecs": 300,
                "status": "Success"
            },
            "$metadata": {
            ...
            },
            "$version": 7
        }
    }
}

您指的是身份注册表,它是一个支持 REST 的设备或模块身份资源集合。在身份注册表中添加条目时,IoT 中心会创建一组每设备资源,例如包含正在运行的云到设备消息的队列。有关导入和导出 API 的详细信息,请参阅 IoT Hub resource provider REST APIs

根据您的要求,您可以使用Devices - Get Devices API:

GET https://fully-qualified-iothubname.azure-devices.net/devices?api-version=2020-05-31-preview

将以 Device 数组的形式给出响应,其中包含 connectionStateUpdatedTime.

如果您有后续问题或者我对您的问题的理解有误,请告诉我。