V2.1 Get Device


获取设备信息。

如果你在使用 API 批量更新相关设备后调用当前 API,建议两次调用间隔 2 秒左右,以免获取到未更新数据。


当前 API 支持在 EnOS 2.1.0 及以上环境中使用,并已新增 V2.4 版本。推荐使用最新版本,参见 V2.4 Get Device

请求格式

GET https://{apigw-address}/connect-service/v2.1/devices?action=get

请求参数(URI)

备注

以下非必需字段中,必须提供 assetIdproductKey + deviceKey 的组合,用于指定设备。

名称

位置(Path/Query)

必需/可选

数据类型

描述

orgId

Query

必需

String

设备所属的 OU ID。如何获取 orgId 信息>>

assetId

Query

可选(见上述注解)

String

设备的 asset ID。如何获取 assetId 信息>>

productKey

Query

可选(见上述注解)

String

设备的 product key,需与 deviceKey 一起使用。如何获取设备的三元组信息>>

deviceKey

Query

可选(见上述注解)

String

设备的 device key,需与 productKey 一起使用。如何获取设备的三元组信息>>

响应参数

名称

数据类型

描述

data

Device 结构体

网关设备信息,其结构参见 Device 结构体

Device 结构体

名称

数据类型

描述

orgId

String

设备所属的 OU ID。

assetId

String

设备的 asset ID。

modelId

String

设备所属模型 ID。

modelIdPath

String

模型 ID 的路径。

productKey

String

设备的 product Key。如何获取设备的 productKey 信息>>

productName

StringI18n

产品名称。

productType

String

产品类型。

dataFormat (弃用)

String

数据格式。Json 表示只支持 EnOS 设备协议格式。

deviceKey

String

设备的 Device Key。如何获取设备的 deviceKey 信息>>

deviceName

StringI18n

设备名称。

deviceSecret

String

设备的 device secret。

deviceDesc

String

设备描述。

timezone

String

设备所在时区。

deviceAttributes

Map(Key 和 Value 为 string)

设备的属性。

deviceTags

Map(Key 和 Value 为 string)

设备的标签。

createTime

Long

设备的创建时间。

status

String

设备的状态(online、offline、inactive、disable)。

注:EnOS Edge 仅支持 online 或 offline。

activeTime

Long

设备的激活时间。

lastOnlineTime

Long

设备最后一次上线时间。

lastOfflineTime

Long

设备最后一次离线时间。

measurepointLastUpdate

Long

设备测点最近一次更新的时间。

attributeLastUpdate

Long

设备属性最近一次更新的时间。

featureLastUpdate

Long

设备最近一次更新的时间,以上述三个时间( measurepointLastUpdateattributeLastUpdate )里最近的时间为准。

firmwareVersion

String

固件版本号。

错误码

代码

错误信息

描述

11404

Device cannot be found

用于指定设备的 assetIdproductKeydeviceKey 不存在。

示例

请求示例

url: https://{apigw-address}/connect-service/v2.1/devices?action=get&orgId=yourOrgId&assetId=yourAssetId
method: GET

返回示例

{
    "code": 0,
    "msg": "OK",
    "requestId": "835a5cc4-4487-4bf2-961a-55bc0ee77d02",
    "data": {
        "orgId": "yourOrgId",
        "assetId": "yourAssetId",
        "modelId": "yourModelId",
        "modelIdPath": "yourModelIdPath",
        "productKey": "yourProductKey",
        "productName": {
            "defaultValue": "test_product_name",
            "i18nValue": {}
        },
        "productType": "Device",
        "dataFormat": "Json",
        "deviceKey": "yourDeviceKey",
        "deviceName": {
            "defaultValue": "testforname",
            "i18nValue": {}
        },
        "deviceSecret": "yourDeviceSecret",
        "deviceDesc": "test for undatedevice",
        "timezone": "+08:00",
        "deviceAttributes": {
            "int11": 617
        },
        "deviceTags": {
            "test": "test for tags"
        },
        "createTime": 1557905107199,
        "status": "offline",
        "activeTime": 1557909526473,
        "lastOnlineTime": 1560743931658,
        "lastOfflineTime": 1560744111658,
        "measurepointLastUpdate": 1565875705704,
        "attributeLastUpdate": 1547793776699,
        "featureLastUpdate": 1565875705856,
        "firmwareVersion": "2.2"
    }
}

SDK 示例


你可以在 Github 上获取接入服务的 SDK 示例: