V2.4 Get Device¶
获取设备信息。
如果你在使用 API 批量更新相关设备信息后调用当前 API,建议两次调用间隔 2 秒左右,以免获取到未更新数据。
请求参数(URI)¶
注解
以下非必需字段中,必须提供 assetId
,或提供 productKey
+ deviceKey
的组合,用于指定设备。
名称 | 位置(Path/Query) | 必需/可选 | 数据类型 | 描述 |
---|---|---|---|---|
orgId | Query | 必需 | String | 资产所属的组织 ID。如何获取 orgId 信息>> |
assetId | Query | 可选(见上述注解) | String | 资产 ID。如何获取 assetId 信息>> |
productKey | Query | 可选(见上述注解) | String | 设备的 product key,需与 deviceKey 一起使用。 |
deviceKey | Query | 可选(见上述注解) | String | 设备的 device key,需与 productKey 一起使用。 |
requireSecret | Query | 可选 | Boolean |
|
响应参数¶
名称 | 数据类型 | 描述 |
---|---|---|
data | Device 结构体 | 网关设备信息,其结构参见 Device 结构体。 |
Device 结构体¶
名称 | 数据类型 | 描述 |
---|---|---|
orgId | String | 资产所属的组织 ID。 |
assetId | String | 资产 ID。 |
modelId | String | 资产所属模型 ID。 |
modelIdPath | String | 模型 ID 的路径。 |
productKey | String | Product Key。 |
productName | StringI18n | 产品名称。 |
productType | String | 产品类型。 |
dataFormat | String | 数据格式。Custom 表示支持用户自定义数据格式,Json 表示只支持 EnOS 设备协议格式。 |
deviceKey | String | Device Key。 |
deviceName | StringI18n | 设备名称。 |
deviceSecret | String | 设备连接密钥,仅当 requireSecret 为 true 时返回。返回值已经过加密处理。如何解密 Device Secret >> |
sessionKey | String | 配合解密 deviceSecret 的参数,仅当 requireSecret 为 true 时返回。返回值已经过加密处理。如何解密 Device Secret >> |
deviceDesc | String | 设备描述。 |
timezone | String | 设备所在时区。 |
deviceAttributes | Map(Key 和 Value 为 string) | 设备的属性。 |
deviceTags | Map(Key 和 Value 为 string) | 设备的标志。 |
mirrorSource | String | 镜像源设备的 device key。 |
createTime | Long | 设备的创建时间。 |
status | String | 设备的状态(online、offline、inactive、disable 或 mirror)。
|
activeTime | Long | 设备的激活时间。 |
lastOnlineTime | Long | 设备最后一次上线时间。 |
lastOfflineTime | Long | 设备最后一次离线时间。 |
measurepointLastUpdate | Long | 设备测点最近一次更新的时间。 |
eventLastUpdate | Long | 设备事件最近一次更新的时间。 |
attributeLastUpdate | Long | 设备属性最近一次更新的时间。 |
featureLastUpdate | Long | 设备最近一次更新的时间,以上述三个时间( measurepointLastUpdate 、 eventLastUpdate 、 attributeLastUpdate )里最近的时间为准。 |
firmwareVersion | String | 固件版本号。 |
错误码¶
代码 | 错误信息 | 描述 |
---|---|---|
11404 | Device cannot be found | 用于指定设备的 assetId 、productKey 或 deviceKey 不存在。 |
11858 | Unable to find public key | 由于应用的服务帐号未创建 RSA 密钥对,无法获取 RSA 公钥,因此无法请求 requireSecret 。请先为服务帐号 创建 RSA 密钥对。 |
示例¶
请求示例¶
url: https://{apigw-address}/connect-service/v2.4/devices?action=get&orgId=yourOrgId&assetId=yourAssetId&requireSecret=true
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":"EncryptedDeviceSecret",
"sessionKey":"EncryptedSessionKey",
"deviceDesc": "test for undatedevice",
"timezone": "+08:00",
"deviceAttributes": {
"int11": 617
},
"deviceTags": {
"test": "test for tags"
},
"mirrorSource": "mirrorSourceAssetId",
"createTime": 1557905107199,
"status": "offline",
"activeTime": 1557909526473,
"lastOnlineTime": 1560743931658,
"lastOfflineTime": 1560744111658,
"measurepointLastUpdate": 1565875705704,
"eventLastUpdate": 1565875705856,
"attributeLastUpdate": 1547793776699,
"featureLastUpdate": 1565875705856,
"firmwareVersion": "2.2"
}
}