设备数据API

查询设备列表

请求方式: POST
URL: http(s)://localhost:8844/api/v1/device/_query
http body 请求参数:
公共查询参数:请参考公共查询参数
根据设备实例(DeviceInstanceEntity)条件查询,字段名和值分别对应查询参数Term中的column和value。
设备实例(DeviceInstanceEntity)参数如下:

| 名称 | 类型 | 是否必选 | 示例值 | 描述 | | —- | —- | —- | —- | —- |

| id | String | 否 | test001 | 设备实例ID |

| name | String | 否 | 温控设备001 | 设备实例名称 |

| describe | String | 否 | | 说明 |

| productId | String | 否 | 1236859833832701952 | 型号ID |

| productName | String | 否 | 智能温控 | 型号名称 |

| configuration | Map | 否 | | 其他配置 |

| deriveMetadata | String | 否 | | 派生元数据,有的设备的属性,功能,事件可能会动态的添加 |

| state | DeviceState | 否 | online | 状态 |

| creatorId | String | 否 | 1199596756811550720 | 创建人ID |

| creatorName | String | 否 | 管理员 | 创建人名称 |

| createTime | Long | 否 | 1584586676863 | 创建时间 |

| registryTime | Long | 否 | online | 激活时间 |

| orgId | String | 否 | department | 机构ID |

| parentId | String | 否 | | 父级设备ID |

返回参数:

| 名称 | 类型 | 描述 | | —- | —- | —- |

| result | PagerResult | 分页结果 |

| status | int | 状态码 |

| code | String | 业务编码 |

PagerResult参数如下:

| 名称 | 类型 | 描述 | | —- | —- | —- |

| pageIndex | int | 页码 |

| pageSize | int | 每页数量 |

| total | int | 返回数据总数 |

| data | List | 返回数据集合 |

DeviceInfo参数如下:

| 名称 | 类型 | 描述 | | —- | —- | —- |

| id | String | 设备ID |

| name | String | 设备名称 |

| productId | String | 型号ID |

| productName | String | 型号名称 |

| state | DeviceState | 设备状态 |

| registerTime | long | 注册时间 |

| createTime | long | 创建时间 |

| parentId | String | 父级设备ID |

请求示例:

  1. //请求
  2. POST /api/v1/device/_query
  3. Content-Type: application/json
  4. X-Sign: f4823a*********e76eb1d
  5. X-Timestamp: 1586511766004
  6. X-Client-Id: kF**********HRZ
  7. {
  8. "pageSize": 25,
  9. "pageIndex": 0,
  10. "terms": [{
  11. "column": "productId",
  12. "value": "1236859833832701952"
  13. }]
  14. }
  15. //响应
  16. HTTP/1.1 200 OK
  17. X-Timestamp: 1574994269075
  18. X-Sign: c23fa********f25
  19. {
  20. "result": {
  21. "pageIndex": 0,
  22. "pageSize": 1000,
  23. "total": 3,
  24. "data": [{
  25. "id": "test0312",
  26. "name": "设备0312",
  27. "productId": "1236859833832701952",
  28. "productName": "智能温控",
  29. "state": {
  30. "text": "未激活",
  31. "value": "notActive"
  32. },
  33. "registerTime": 0,
  34. "createTime": 1583997946670
  35. }, {
  36. "id": "test001",
  37. "name": "温控设备0309",
  38. "productId": "1236859833832701952",
  39. "productName": "智能温控",
  40. "state": {
  41. "text": "离线",
  42. "value": "offline"
  43. },
  44. "registerTime": 1583805253659,
  45. "createTime": 1585809343175
  46. }, {
  47. "id": "MQTT_FX_Client",
  48. "name": "mqttfx",
  49. "productId": "1236859833832701952",
  50. "productName": "智能温控",
  51. "state": {
  52. "text": "离线",
  53. "value": "offline"
  54. },
  55. "registerTime": 1584330967254,
  56. "createTime": 1584330960918
  57. }]
  58. },
  59. "status": 200,
  60. "code": "success"
  61. }

::: tip 说明:
X-Sign为签名,body+X-Timestamp+SecuryeKeyMD5加密
X-Timestamp为时间戳
X-Client-Id为平台openApi客户端id
:::

获取设备详情

请求方式: GET
URL: http(s)://localhost:8844/api/v1/device/{deviceId}/_detail
说明:{deviceId}需要替换为设备实例的id。
返回参数:

| 名称 | 类型 | 描述 | | —- | —- | —- |

| result | DeviceDetail | 返回值 |

| status | int | 状态码 |

| code | String | 业务编码 |

DeviceDetail参数如下:

| 名称 | 类型 | 描述 | | —- | —- | —- |

| id | String | 设备ID |

| name | String | 设备名称 |

| protocol | String | 消息协议标识 |

| transport | String | 通信协议 |

| orgId | String | 所属机构ID |

| orgName | String | 所属机构名称 |

| productId | String | 型号ID |

| productName | String | 型号名称 |

| deviceType | DeviceType | 设备类型 |

| state | DeviceState | 设备状态 |

| address | String | 客户端地址 |

| onlineTime | long | 上线时间 |

| offlineTime | long | 离线时间 |

| registerTime | long | 注册时间 |

| createTime | long | 创建时间 |

| metadata | String | 设备元数据(在设备型号功能定义中定义) |

| configuration | Map | 设备配置信息 |

| tags | List | 标签 |

标签(DeviceTagEntity)参数说明:

| 名称 | 类型 | 描述 | | —- | —- | —- |

| deviceId | String | 设备ID |

| key | String | 键 |

| name | String | 标签名 |

| value | String | 值 |

| type | String | 标签类型 |

| createTime | Date | 创建时间 |

| description | String | 描述 |

请求示例:

  1. //请求
  2. GET /api/v1/device/1236859833832701952/_detail
  3. X-Sign: f4823a*********e76eb1d
  4. X-Timestamp: 1586511766004
  5. X-Client-Id: kF**********HRZ
  6. //响应
  7. HTTP/1.1 200 OK
  8. X-Timestamp: 1574994269075
  9. X-Sign: c23fa********f25
  10. {
  11. "result": {
  12. "id": "test001",
  13. "name": "温控设备0309",
  14. "protocol": "demo-v1",
  15. "transport": "MQTT",
  16. "productId": "1236859833832701952",
  17. "productName": "智能温控",
  18. "deviceType": {
  19. "text": "网关设备",
  20. "value": "gateway"
  21. },
  22. "state": {
  23. "text": "离线",
  24. "value": "offline"
  25. },
  26. "address": "/127.0.0.1:46360",
  27. "onlineTime": 1586422112901,
  28. "offlineTime": 1586424932209,
  29. "createTime": 1585809343175,
  30. "registerTime": 1583805253659,
  31. "metadata": "{\"events\":[{\"id\":\"fire_alarm\",\"name\":\"火警报警\",\"expands\":{\"eventType\":\"reportData\",\"level\":\"urgent\"},\"valueType\":{\"type\":\"object\",\"properties\":[{\"id\":\"a_name\",\"name\":\"区域名称\",\"valueType\":{\"type\":\"string\"}},{\"id\":\"b_name\",\"name\":\"建筑名称\",\"valueType\":{\"type\":\"string\"}},{\"id\":\"l_name\",\"name\":\"位置名称\",\"valueType\":{\"type\":\"string\"}}]}}],\"properties\":[{\"id\":\"temperature\",\"name\":\"温度\",\"valueType\":{\"type\":\"float\",\"min\":\"0\",\"max\":\"100\",\"step\":\"0.1\",\"unit\":\"celsiusDegrees\"},\"expands\":{\"readOnly\":\"true\"}}],\"functions\":[{\"id\":\"get-log\",\"name\":\"获取日志\",\"isAsync\":true,\"output\":{\"type\":\"string\",\"expands\":{\"maxLength\":\"2048\"}},\"inputs\":[{\"id\":\"start_date\",\"name\":\"开始日期\",\"valueType\":{\"type\":\"date\",\"dateFormat\":\"yyyy-MM-dd HH:mm:ss\"}},{\"id\":\"end_data\",\"name\":\"结束日期\",\"valueType\":{\"type\":\"date\",\"dateFormat\":\"yyyy-MM-dd HH:mm:ss\"}},{\"id\":\"time\",\"name\":\"分组\",\"valueType\":{\"type\":\"string\"}}]}]}",//在设备型号功能定义中定义
  32. "configuration": {
  33. "username": "test",
  34. "password": "test"
  35. },
  36. "tags": []
  37. },
  38. "status": 200,
  39. "code": "success"
  40. }

查询设备详情列表

请求方式: POST
URL: http(s)://localhost:8844/api/v1/device/_detail/_query
http body 请求参数:
公共查询参数:请参考公共查询参数
请求示例:

  1. //请求
  2. POST /api/v1/device/_detail/_query
  3. Content-Type: application/json
  4. X-Sign: f4823a*********e76eb1d
  5. X-Timestamp: 1586511766004
  6. X-Client-Id: kF**********HRZ
  7. {
  8. "pageSize": 25,
  9. "pageIndex": 0,
  10. "terms": [{
  11. "column": "productId",
  12. "value": "1236859833832701952"
  13. }]
  14. }
  15. //响应
  16. HTTP/1.1 200 OK
  17. X-Timestamp: 1574994269075
  18. X-Sign: c23fa********f25
  19. {
  20. "result": {
  21. "pageIndex": 0,
  22. "pageSize": 1000,
  23. "total": 3,
  24. "data": [
  25. {
  26. "id": "test001",
  27. "name": "温控设备0309",
  28. "protocol": "demo-v1",
  29. "transport": "MQTT",
  30. "productId": "1236859833832701952",
  31. "productName": "智能温控",
  32. "deviceType": {
  33. "text": "网关设备",
  34. "value": "gateway"
  35. },
  36. "state": {
  37. "text": "离线",
  38. "value": "offline"
  39. },
  40. "address": "/127.0.0.1:46360",
  41. "onlineTime": 1586422112901,
  42. "offlineTime": 1586424932209,
  43. "createTime": 1585809343175,
  44. "registerTime": 1583805253659,
  45. "metadata": "{\"events\":[{\"id\":\"fire_alarm\",\"name\":\"火警报警\",\"expands\":{\"eventType\":\"reportData\",\"level\":\"urgent\"},\"valueType\":{\"type\":\"object\",\"properties\":[{\"id\":\"a_name\",\"name\":\"区域名称\",\"valueType\":{\"type\":\"string\"}},{\"id\":\"b_name\",\"name\":\"建筑名称\",\"valueType\":{\"type\":\"string\"}},{\"id\":\"l_name\",\"name\":\"位置名称\",\"valueType\":{\"type\":\"string\"}}]}}],\"properties\":[{\"id\":\"temperature\",\"name\":\"温度\",\"valueType\":{\"type\":\"float\",\"min\":\"0\",\"max\":\"100\",\"step\":\"0.1\",\"unit\":\"celsiusDegrees\"},\"expands\":{\"readOnly\":\"true\"}}],\"functions\":[{\"id\":\"get-log\",\"name\":\"获取日志\",\"isAsync\":true,\"output\":{\"type\":\"string\",\"expands\":{\"maxLength\":\"2048\"}},\"inputs\":[{\"id\":\"start_date\",\"name\":\"开始日期\",\"valueType\":{\"type\":\"date\",\"dateFormat\":\"yyyy-MM-dd HH:mm:ss\"}},{\"id\":\"end_data\",\"name\":\"结束日期\",\"valueType\":{\"type\":\"date\",\"dateFormat\":\"yyyy-MM-dd HH:mm:ss\"}},{\"id\":\"time\",\"name\":\"分组\",\"valueType\":{\"type\":\"string\"}}]}]}",//在设备型号功能定义中定义
  46. "configuration": {
  47. "username": "test",
  48. "password": "test"
  49. },
  50. "tags": []
  51. }
  52. ]
  53. },
  54. "status": 200,
  55. "code": "success"
  56. }

批量保存设备

请求方式: POST
URL: http(s)://localhost:8844/api/v1/device
http body 请求参数为DeviceSaveDetail集合:
DeviceSaveDetail 参数如下:

| 名称 | 类型 | 是否必选 | 示例值 | 描述 | | —- | —- | —- | —- | —- |

| id | String | 是 | test002 | 设备实例ID |

| name | String | 是 | 温控设备002 | 设备实例名称 |

| productId | String | 是 | 1236859833832701952 | 型号ID |

| productName | String | 是 | 智能温控 | 型号名称 |

| configuration | Map | 否 | | 设备配置信息,根据不同的协议配置不同,如果MQTT用户名密码等 |

| creatorId | String | 否 | 1199596756811550720 | 创建人ID |

| creatorName | String | 否 | 管理员 | 创建人名称 |

| tags | List | 否 | | 标签 |

标签(DeviceTagEntity)参数说明:

| 名称 | 类型 | 描述 | | —- | —- | —- |

| deviceId | String | 设备ID |

| key | String | 键 |

| name | String | 标签名 |

| value | String | 值 |

| type | String | 标签类型 |

| createTime | Date | 创建时间 |

| description | String | 描述 |

返回参数:

| 名称 | 类型 | 描述 | | —- | —- | —- |

| result | int | 保存数量 |

| status | int | 状态码 |

| code | String | 业务编码 |

示例:

  1. // 请求
  2. POST /api/v1/device
  3. X-Sign: f4823a*********e76eb1d
  4. X-Timestamp: 1586511766004
  5. X-Client-Id: kF**********HRZ
  6. Content-Type: application/json
  7. [
  8. {
  9. "id": "test002",
  10. "name": "设备002",
  11. "productId": "1236859833832701952",
  12. "configuration": {
  13. "username": "test002",
  14. "password": "test002"
  15. },
  16. "tags": [{
  17. "deviceId": "test002",
  18. "key": "area",
  19. "name": "地区",
  20. "value": "chongqing"
  21. }]
  22. },
  23. {
  24. "id": "test003",
  25. "name": "设备名称",
  26. "productId": "1236859833832701952",
  27. "configuration": {}
  28. }
  29. ]
  30. // 响应
  31. HTTP/1.1 200 OK
  32. X-Timestamp: 1574994269075
  33. X-Sign: c23fa********f25
  34. {"result":3,"status":200,"code":"success"}

批量同步设备状态

请求方式: POST
URL: http://localhost:8844/api/v1/device/state/_sync
请求参数格式为动态查询参数
::: tip 提示
此操作将同步设备真实状态,如果一次同步数量较大,推荐使用websocket方式同步,可实时获取同步结果.
:::
请求示例:

  1. //请求
  2. POST /api/v1/device/state/_sync
  3. Content-Type: application/json
  4. X-Sign: f4823a*********e76eb1d
  5. X-Timestamp: 1586511766004
  6. X-Client-Id: kF**********HRZ
  7. {
  8. "pageSize":10
  9. }
  10. //响应
  11. HTTP/1.1 200 OK
  12. X-Timestamp: 1574994269075
  13. X-Sign: c23fa********f25
  14. {
  15. "status":200,
  16. "result":[
  17. {
  18. "deviceId":"设备ID",
  19. "state":{"value":"offline","text":"离线"}
  20. }
  21. ]
  22. }

批量激活设备

请求方式: POST
URL: http(s)://localhost:8844/api/v1/device/_deploy
http body 请求参数为设备id集合,List
返回参数:

| 名称 | 类型 | 描述 | | —- | —- | —- |

| result | int | 激活数量 |

| status | int | 状态码 |

| code | String | 业务编码 |

请求示例:

  1. //请求
  2. POST /api/v1/device/_deploy
  3. Content-Type: application/json
  4. X-Sign: f4823a*********e76eb1d
  5. X-Timestamp: 1586511766004
  6. X-Client-Id: kF**********HRZ
  7. ["test002","test003", "test004"]
  8. //响应
  9. HTTP/1.1 200 OK
  10. X-Timestamp: 1574994269075
  11. X-Sign: c23fa********f25
  12. {"result":3,"status":200,"code":"success"}

批量注销设备

请求方式: POST
URL: http(s)://localhost:8844/api/v1/device/_unDeploy
http body 请求参数为设备id集合,List
返回参数:

| 名称 | 类型 | 描述 | | —- | —- | —- |

| result | int | 注销成功数量 |

| status | int | 状态码 |

| code | String | 业务编码 |

请求示例:

  1. //请求
  2. POST /api/v1/device/_unDeploy
  3. Content-Type: application/json
  4. X-Sign: f4823a*********e76eb1d
  5. X-Timestamp: 1586511766004
  6. X-Client-Id: kF**********HRZ
  7. ["test002","test003", "test004"]
  8. //响应
  9. HTTP/1.1 200 OK
  10. X-Timestamp: 1574994269075
  11. X-Sign: c23fa********f25
  12. {"result":3,"status":200,"code":"success"}

批量删除设备

请求方式: POST
URL: http(s)://localhost:8844/api/v1/device/_delete
http body 请求参数为设备id集合,List
返回参数:

| 名称 | 类型 | 描述 | | —- | —- | —- |

| result | int | 注销成功数量 |

| status | int | 状态码 |

| code | String | 业务编码 |

请求示例:

  1. //请求
  2. POST /api/v1/device/_delete
  3. Content-Type: application/json
  4. X-Sign: f4823a*********e76eb1d
  5. X-Timestamp: 1586511766004
  6. X-Client-Id: kF**********HRZ
  7. ["test002","test003", "test004"]
  8. //响应
  9. HTTP/1.1 200 OK
  10. X-Timestamp: 1574994269075
  11. X-Sign: c23fa********f25
  12. {"result":3,"status":200,"code":"success"}

根据设备ID查询设备日志

请求方式: POST
URL: http(s)://localhost:8844/api/v1/device/{deviceId}/log/_query
说明:{deviceId}需要替换为设备实例的id。
http body 请求参数:
公共查询参数:请参考公共查询参数
根据设备操作日志(DeviceOperationLogEntity)条件查询,字段名和值分别对应查询参数Term中的column和value。
设备操作日志(DeviceOperationLogEntity)参数如下:

| 名称 | 类型 | 是否必选 | 示例值 | 描述 | | —- | —- | —- | —- | —- |

| id | String | 否 | LoymU3EBCTcV5s5DbSn7 | 设备实例ID |

| productId | String | 否 | 1236859833832701952 | 型号ID |

| type | DeviceLogType | 否 | readProperty | 类型 |

| createTime | Long | 否 | 1584586676863 | 创建时间 |

| orgId | String | 否 | department | 机构ID |

返回参数:

| 名称 | 类型 | 描述 | | —- | —- | —- |

| result | PagerResult | 分页结果 |

| status | int | 状态码 |

| code | String | 业务编码 |

PagerResult参数如下:

| 名称 | 类型 | 描述 | | —- | —- | —- |

| pageIndex | int | 页码 |

| pageSize | int | 每页数量 |

| total | int | 返回数据总数 |

| data | List | 返回数据集合 |

DeviceInfo参数如下:

| 名称 | 类型 | 描述 | | —- | —- | —- |

| id | String | 设备ID |

| name | String | 设备名称 |

| productId | String | 型号ID |

| productName | String | 型号名称 |

| state | DeviceLogType | 设备状态 |

| registerTime | long | 注册时间 |

| createTime | long | 创建时间 |

| parentId | String | 父级设备ID |

请求示例:

  1. //请求
  2. POST /api/v1/device/test001/log/_query
  3. Content-Type: application/json
  4. X-Sign: f4823a*********e76eb1d
  5. X-Timestamp: 1586511766004
  6. X-Client-Id: kF**********HRZ
  7. {
  8. "pageSize": 25,
  9. "pageIndex": 0,
  10. "terms": [{
  11. "column": "createTime$btw",
  12. "value": "2020-01-01,2020-06-01"
  13. }]
  14. }
  15. //响应
  16. HTTP/1.1 200 OK
  17. X-Timestamp: 1574994269075
  18. X-Sign: c23fa********f25
  19. {
  20. "result": {
  21. "pageIndex": 0,
  22. "pageSize": 25,
  23. "total": 4,
  24. "data": [{
  25. "id": "fa1528090a464e3f0bf3839ce0c1315",
  26. "deviceId": "test001",
  27. "productId": "1236859833832701952",
  28. "type": {
  29. "text": "上线",
  30. "value": "online"
  31. },
  32. "createTime": 1586422112000,
  33. "content": "设备上线"
  34. }, {
  35. "id": "eb7d05c8dda18bc37434bf7f98799ba7",
  36. "deviceId": "test001",
  37. "productId": "1236859833832701952",
  38. "type": {
  39. "text": "离线",
  40. "value": "offline"
  41. },
  42. "createTime": 1586419084000,
  43. "content": "设备离线"
  44. }, {
  45. "id": "34a89eb7b89646bd98fc5ab6617b370e",
  46. "deviceId": "test001",
  47. "productId": "1236859833832701952",
  48. "type": {
  49. "text": "上线",
  50. "value": "online"
  51. },
  52. "createTime": 1586413536000,
  53. "content": "设备上线"
  54. }, {
  55. "id": "2f1aaa63865afb3cdcec4aa72771ab9",
  56. "deviceId": "test001",
  57. "productId": "1236859833832701952",
  58. "type": {
  59. "text": "读取属性回复",
  60. "value": "readPropertyReply"
  61. },
  62. "createTime": 1583809148000,
  63. "content": "{\"temperature\":\"50\"}"
  64. }]
  65. },
  66. "status": 200,
  67. "code": "success"
  68. }

查询设备属性

请求方式: POST
URL: http(s)://localhost:8844/api/v1/device/{deviceId}/properties/_query
说明:{deviceId}需要替换为设备实例的id。
http body 请求参数:
公共查询参数:请参考公共查询参数
根据设备属性(DevicePropertiesEntity)条件查询,字段名和值分别对应查询参数Term中的column和value。
设备属性(DevicePropertiesEntity)参数如下:

| 名称 | 类型 | 是否必选 | 示例值 | 描述 | | —- | —- | —- | —- | —- |

| id | String | 否 | | 属性ID |

| productId | String | 否 | 1236859833832701952 | 型号ID |

| property | String | 否 | temperature | 属性标识 |

| propertyName | String | 否 | 温度 | 属性名称 |

| stringValue | String | 否 | | 字符串值 |

| formatValue | String | 否 | | 格式化值 |

| numberValue | String | 否 | | 数字值 |

| geoValue | GeoPoint | 否 | | 坐标值 |

| timestamp | long | 否 | | 时间戳 |

| objectValue | String | 否 | | 结构体值 |

| value | String | 否 | | 值 |

| timeValue | Date | 否 | | 时间值 |

| orgId | String | 否 | | 机构ID |

GeoPoint参数如下:

| 名称 | 类型 | 是否必选 | 示例值 | 描述 | | —- | —- | —- | —- | —- |

| lat | double | 否 | 106.57 | 经度 |

| lon | double | 否 | 29.52 | 纬度 |

返回参数:

| 名称 | 类型 | 描述 | | —- | —- | —- |

| result | PagerResult | 分页结果 |

| status | int | 状态码 |

| code | String | 业务编码 |

PagerResult参数如下:

| 名称 | 类型 | 描述 | | —- | —- | —- |

| pageIndex | int | 页码 |

| pageSize | int | 每页数量 |

| total | int | 返回数据总数 |

| data | List | 返回数据集合 |

DeviceInfo参数如下:

| 名称 | 类型 | 描述 | | —- | —- | —- |

| id | String | 属性ID |

| productId | String | 型号ID |

| property | String | 属性标识 |

| propertyName | String | 属性名称 |

| stringValue | String | 字符串值 |

| formatValue | String | 格式化值 |

| numberValue | String | 数字值 |

| geoValue | GeoPoint | 坐标值 |

| timestamp | long | 否 时间戳 |

| objectValue | String | 结构体值 |

| value | String | 值 |

| timeValue | Date | 时间值 |

| orgId | String | 机构ID |

请求示例:

  1. //请求
  2. POST /api/v1/device/test001/properties/_query
  3. Content-Type: application/json
  4. X-Sign: f4823a*********e76eb1d
  5. X-Timestamp: 1586511766004
  6. X-Client-Id: kF**********HRZ
  7. {
  8. "pageSize": 25,
  9. "pageIndex": 0,
  10. "terms": [{
  11. "column": "property",
  12. "value": "temperature"
  13. }]
  14. }
  15. //响应
  16. HTTP/1.1 200 OK
  17. X-Timestamp: 1574994269075
  18. X-Sign: c23fa********f25
  19. {
  20. "result": {
  21. "pageIndex": 0,
  22. "pageSize": 25,
  23. "total": 3,
  24. "data": [{
  25. "id": "amugXXEBQZKUd4flBbDN",
  26. "deviceId": "test001",
  27. "property": "temperature",
  28. "propertyName": "温度",
  29. "formatValue": "50.00℃",
  30. "numberValue": 50.0,
  31. "timestamp": 1583809148000,
  32. "value": "50",
  33. "productId": "1236859833832701952"
  34. }]
  35. },
  36. "status": 200,
  37. "code": "success"
  38. }

获取设备最新的全部属性

请求方式: GET
URL: http(s)://localhost:8844/api/v1/device/{deviceId}/properties/_latest
说明:{deviceId}需要替换为设备实例的id。
返回参数:

| 名称 | 类型 | 描述 | | —- | —- | —- |

| result | DevicePropertiesEntity | 返回值 |

| status | int | 状态码 |

| code | String | 业务编码 |

DevicePropertiesEntity参数如下:

| 名称 | 类型 | 描述 | | —- | —- | —- |

| id | String | 否 |

| productId | String | 否 |

| property | String | 否 |

| propertyName | String | 否 |

| stringValue | String | 否 |

| formatValue | String | 否 |

| numberValue | String | 否 |

| geoValue | GeoPoint | 否 |

| timestamp | long | 否 |

| objectValue | String | 否 |

| value | String | 否 |

| timeValue | Date | 否 |

| orgId | String | 否 |

| deviceId | String | 否 |

| type | String | 否 |

请求示例:

//请求
POST /api/v1/device/test001/properties/_latest
Content-Type: application/json
X-Sign: f4823a*********e76eb1d
X-Timestamp: 1586511766004
X-Client-Id: kF**********HRZ


//响应
HTTP/1.1 200 OK
X-Timestamp: 1574994269075
X-Sign: c23fa********f25

{
    "result": [{
        "id": "amugXXEBQZKUd4flBbDN",
        "deviceId": "test001",
        "property": "temperature",
        "propertyName": "温度",
        "formatValue": "50.00℃",
        "numberValue": 50.0,
        "timestamp": 1583809148000,
        "value": "50",
        "productId": "1236859833832701952"
    }],
    "status": 200,
    "code": "success"
}

聚合查询设备属性

请求方式: GET
URL: http(s)://localhost:8844/api/v1/device/{deviceId}/agg/{agg}/{property}/_query
说明:{deviceId}需要替换为设备实例的id,
{agg}需要替换为聚合类型,包含:MIN, MAX, AVG, SUM, COUNT, NONE
{property}需要替换为设备属性。
返回参数:

| 名称 | 类型 | 描述 | | —- | —- | —- |

| result | List> | 返回值 |

| status | int | 状态码 |

| code | String | 业务编码 |

请求示例:
查询过去30分钟设备test001的温度属性每分钟的平均温度。

//请求
POST /api/v1/device/test001/agg/AVG/temperature/_query
Content-Type: application/json
X-Sign: f4823a*********e76eb1d
X-Timestamp: 1598579554299
X-Client-Id: kF**********HRZ

{
    "interval": "1h",//时间间隔,单位为英文时间单位首字母,如小时h、天d等
    "format": "yyyy-MM-dd HH:mm:ss",//时间格式
    "from": "now-24h",//起始时间
    "to": "now",//终止时间
    "query": {
            "pageSize": 25//指定返回数据条数,默认25
        }
}

//响应
HTTP/1.1 200 OK
X-Timestamp: 1574994269075
X-Sign: c23fa********f25

{
    "result": [{
        "temperature": 32.8235294117647,
        "time": "2020-08-28 09:52:00"
    }, {
        "temperature": 32.13333333333333,
        "time": "2020-08-28 09:51:00"
    }, {
        "temperature": 34.11666666666667,
        "time": "2020-08-28 09:50:00"
    }, {
        "temperature": 33.9,
        "time": "2020-08-28 09:49:00"
    }, {
        "temperature": 33.85,
        "time": "2020-08-28 09:48:00"
    }, {
        "temperature": 34.45,
        "time": "2020-08-28 09:47:00"
    }, {
        "temperature": 32.75,
        "time": "2020-08-28 09:46:00"
    }, {
        "temperature": 35.6,
        "time": "2020-08-28 09:45:00"
    }, {
        "temperature": 35.06666666666667,
        "time": "2020-08-28 09:44:00"
    }, {
        "temperature": 34.15,
        "time": "2020-08-28 09:43:00"
    }, {
        "temperature": 37.629629629629626,
        "time": "2020-08-28 09:42:00"
    }, {
        "temperature": 33.8,
        "time": "2020-08-28 09:41:00"
    }, {
        "temperature": 33.42857142857143,
        "time": "2020-08-28 09:40:00"
    }, {
        "temperature": 0.0,
        "time": "2020-08-28 09:39:00"
    }, {
        "temperature": 0.0,
        "time": "2020-08-28 09:38:00"
    }, {
        "temperature": 0.0,
        "time": "2020-08-28 09:37:00"
    }, {
        "temperature": 0.0,
        "time": "2020-08-28 09:36:00"
    }, {
        "temperature": 0.0,
        "time": "2020-08-28 09:35:00"
    }, {
        "temperature": 0.0,
        "time": "2020-08-28 09:34:00"
    }, {
        "temperature": 0.0,
        "time": "2020-08-28 09:33:00"
    }, {
        "temperature": 0.0,
        "time": "2020-08-28 09:32:00"
    }, {
        "temperature": 0.0,
        "time": "2020-08-28 09:31:00"
    }, {
        "temperature": 0.0,
        "time": "2020-08-28 09:30:00"
    }, {
        "temperature": 0.0,
        "time": "2020-08-28 09:29:00"
    }, {
        "temperature": 0.0,
        "time": "2020-08-28 09:28:00"
    }],
    "code": "success",
    "status": 200
}

查询设备事件

请求方式: POST
URL: http(s)://localhost:8844/api/v1/device/{deviceId}/event/{eventId}/_query
说明:{deviceId}需要替换为设备实例的id,{eventId}需替换为设备型号中事件标识。
http body 请求参数:
公共查询参数:请参考公共查询参数
::: tip 注意
此处的参数中Term为设备型号功能定义中的事件内容
:::
返回参数:

| 名称 | 类型 | 描述 | | —- | —- | —- |

| result | PagerResult> | 分页结果 |

| status | int | 状态码 |

| code | String | 业务编码 |

PagerResult>参数如下:

| 名称 | 类型 | 描述 | | —- | —- | —- |

| pageIndex | int | 页码 |

| pageSize | int | 每页数量 |

| total | int | 返回数据总数 |

| data | List> | 返回数据集合 |

请求示例:

//请求
POST /api/v1/device/test001/event/fire_alarm/_query
Content-Type: application/json
X-Sign: f4823a*********e76eb1d
X-Timestamp: 1586511766004
X-Client-Id: kF**********HRZ

{
    "pageSize": 25,
    "pageIndex": 0,
    "terms": [{
        "column": "a_name",//型号事件定义中的结构体的属性
        "value": "南岸区"
    }]
}

//响应
HTTP/1.1 200 OK
X-Timestamp: 1574994269075
X-Sign: c23fa********f25

{
    "result": {
        "pageIndex": 0,
        "pageSize": 25,
        "total": 1,
        "data": [{
            "b_name": "C2 栋",
            "productId": "1236859833832701952",
            "pname": "智能温控",
            "event_count": 1,
            "l_name": "12-05-201",
            "alarm_describe": "火灾报警",
            "deviceId": "test001",
            "event_id": 1,
            "alarm_type": 1,
            "createTime": 1586701932647,
            "id": "Pn_ObnEBbNs2V4rRJb4F",
            "aid": 105,
            "a_name": "南岸区",
            "timestamp": 1586701932647
        }]
    },
    "status": 200,
    "code": "success"
}

设备操作API

获取设备属性

此操作将发送指令ReadPropertyMessage到设备.并获取设备返回数据ReadPropertyMessageReply.
请求方式: GET
URL: `http(s)://localhost:8844/api/v1/device/{deviceId}/property/{propertyId}
说明:{deviceId}需要替换为设备实例的id,{propertyId}需要替换成属性标识。
返回参数:

| 名称 | 类型 | 描述 | | —- | —- | —- |

| result | Map | 返回值 |

| status | int | 状态码 |

| code | String | 业务编码 |

请求示例:

//请求
GET /api/v1/device/test001/property/temperature
Content-Type: application/json
X-Sign: f4823a*********e76eb1d
X-Timestamp: 1586511766004
X-Client-Id: kF**********HRZ

//响应
HTTP/1.1 200 OK
X-Timestamp: 1574994269075
X-Sign: c23fa********f25

{
    "result": {
        "temperature": "50"
    },
    "status": 200,
    "code": "success"
}

设置设备属性

此操作将发送指令WritePropertyMessage到设备.并获取设备返回数据WritePropertyMessageReply.
请求方式: POST
URL: http(s)://localhost:8844/api/v1/device/{deviceId}/properties
说明:{deviceId}需要替换为设备实例的id。
http body 请求参数:
此处的参数为设备型号功能定义中的属性,如:

{"temperature": 50.0}//temperature为属性标识

返回参数:

| 名称 | 类型 | 描述 | | —- | —- | —- |

| result | Map | 返回数据 |

| status | int | 状态码 |

| code | String | 业务编码 |

请求示例:

//请求
POST /api/v1/device/test001/property/temperature
Content-Type: application/json
X-Sign: f4823a*********e76eb1d
X-Timestamp: 1586511766004
X-Client-Id: kF**********HRZ

{"temperature": 50.0}

//响应
HTTP/1.1 200 OK
X-Timestamp: 1574994269075
X-Sign: c23fa********f25

{
    "result": {
        "temperature": "50"
    },
    "status": 200,
    "code": "success"
}

设备功能调用

此操作将发送指令FunctionInvokeMessage到设备,并等待返回FunctionInvokeMessageReply.
请求方式: POST
URL: http(s)://localhost:8844/api/v1/device/{deviceId}/function/{functionId}
说明:{deviceId}需要替换为设备实例的id,{functionId}需要替换为设备型号中功能定义的功能标识。
请求示例:

//请求
POST /api/v1/device/test001/function/play_voice
Content-Type: application/json
X-Sign: f4823a*********e76eb1d
X-Timestamp: 1586511766004
X-Client-Id: kF**********HRZ

{
  "text": "你好" //与物模型中定义到参数一致
}

//响应
HTTP/1.1 200 OK
X-Timestamp: 1574994269075
X-Sign: c23fa********f25

{
    "result": ['ok'], //注意是集合.因为可能返回多条结果
    "status": 200,
    "code": "success"
}

地理信息管理

根据geojson保存数据

请求方式: POST
URL: http(s)://localhost:8844/api/v1/geo/object/geo.json
http body 请求参数:
GeoJson(参考GeoJSON) 参数如下:

| 名称 | 类型 | 是否必选 | 示例值 | 描述 | | —- | —- | —- | —- | —- |

| type | String | 是 | FeatureCollection | 类型,固定为FeatureCollection |

| features | List | 否 | | geo集合 |

GeoJsonFeature 参数如下:

| 名称 | 类型 | 是否必选 | 示例值 | 描述 | | —- | —- | —- | —- | —- |

| type | String | 是 | Feature | 类型,固定为Feature |

| properties | Map | 否 | | 拓展属性 |

| geometry | GeoShape | 否 | | 图形 |

properties 参数如下:

| 名称 | 类型 | 是否必选 | 示例值 | 描述 | | —- | —- | —- | —- | —- |

| objectId | String | 是 | chongqing | |

| id | String | 是 | chongqing | |

| objectType | String | 是 | city | |

GeoShape 参数如下:

| 名称 | 类型 | 是否必选 | 示例值 | 描述 | | —- | —- | —- | —- | —- |

| type | Type | 是 | Polygon | 类型 |

| coordinates | List | 是 | | 坐标集合 |

返回参数:

| 名称 | 类型 | 描述 | | —- | —- | —- |

| status | int | 状态码 |

| code | String | 业务编码 |

请求示例:

//请求
POST /api/v1/geo/object/geo.json
Content-Type: application/json
X-Sign: f4823a*********e76eb1d
X-Timestamp: 1586511766004
X-Client-Id: kF**********HRZ

{
    "type": "FeatureCollection",
    "features": [{
        "type": "Feature",
        "properties": {//拓展属性
            //必须的配置
            "id": "500242",
            "objectId": "youyang",
            "objectType": "city",

            //其他配置,将设置到 GeoObject.tags中,在查询时可通过filter进行搜索
            "name": "酉阳土家族苗族自治县",
            "group": "china"
        },
        "geometry": {
            "type": "Polygon",
            "coordinates": [//坐标列表
                [
                    [108.3142, 28.9984],
                    [108.3252, 29.0039],
                    [108.3252, 28.96],
                    [108.3142, 28.9984]
                ]
            ]
        }
    }]
}

//响应
HTTP/1.1 200 OK
X-Timestamp: 1574994269075
X-Sign: c23fa********f25

{"status":200,"code":"success"}

::: tip 注意:
可使用 http://geojson.io/#map=4/32.18/105.38 生成json.
或者获取行政区划geojson/
:::

查询geo对象

请求方式: POST
URL: http(s)://localhost:8844/api/v1/geo/object/_search
http body 请求参数:

| 名称 | 类型 | 是否必选 | 示例值 | 描述 | | —- | —- | —- | —- | —- |

| shape | Object | 否 | | 图形,如重庆市行政区域边界(扩展属性objectId为该边界的标识) |

| filter | QueryParamEntity | 否 | | 可根据GeoObject.tags中的属性进行查询 |

返回参数:

| 名称 | 类型 | 描述 | | —- | —- | —- |

| result | GeoObject | 返回数据 |

| status | int | 状态码 |

| code | String | 业务编码 |

GeoObject 参数如下:

| 名称 | 类型 | 描述 | | —- | —- | —- |

| id | String | 唯一标识 |

| objectType | String | 类型 |

| shapeType | String | 图形类型 |

| objectId | String | 图形唯一标识 |

| property | String | 属性标识 |

| point | GeoPoint | 坐标 |

| shape | GeoShape | 图形 |

| tags | String | 拓展信息 |

| timestamp | long | 时间戳: 数据更新的时间 |

GeoPoint 参数如下:

| 名称 | 类型 | 描述 | | —- | —- | —- |

| lon | double | 经度 |

| lat | double | 纬度 |

GeoShape 参数如下:

| 名称 | 类型 | 是否必选 | 示例值 | 描述 | | —- | —- | —- | —- | —- |

| type | Type | 是 | Polygon | 类型 |

| coordinates | List | 是 | | 坐标集合度 |

请求示例:
RequestUrl: http://localhost:8844/api/v1/geo/object/_search
RequestMethod: POST
RequestHeader:
X-Sign: 7d825f4************5724949
X-Timestamp: 1587460645733
X-Client-Id: kF**********HRZ
Content-Type: application/json
::: tip 说明:
X-Sign为签名,body+X-Timestamp+SecuryeKeyMD5加密
X-Timestamp为时间戳
X-Client-Id为平台openApi客户端id
:::
RequestBody:

  1. 使用shape中的objectId查询:
{
          "shape":{
              "objectId":"youyang" //查询objectId为youyang的所有geo信息
          },
          "filter":{

          }
      }

::: tip 注意:
objectId为平台对geojson进行拓展的属性,为geo对象的唯一标识,如:设备id,区域id等。
当物模型里面配置了地理位置,objectId则为该设备id,可通过objectId查询该设备的地理位置信息。
:::

  1. 使用shape的多边形的坐标集进行查询
{
    "shape": {
            "type": "Polygon",//请参考Type
            "coordinates": [
                [
                    [108.3142, 28.9984],
                    [108.3252, 29.0039],
                    [108.3252, 28.96],
                    [108.3142, 28.9984]
                ]
            ]
        },
    "filter": {

    }
}

::: tip 注意:
shape中的type请参考Type
:::

  1. filter的使用
{
    "shape": {
        "objectId": "youyang"
    },
    "filter": {
        "where": "tags.name=酉阳土家族苗族自治县 and tags.group=china"
    }

}

::: tip 注意:
filter查询的条件来自于根据geojson保存数据接口提交的数据中properties中设置到GeoObject.tags的属性,如:name、group;
filter可以单独进行查询,不需要传入shape
:::
HttpResponse:

{
    "result": [{
        "id": "youyang",
        "objectType": "city",
        "shapeType": "Polygon",
        "objectId": "youyang",
        "shape": {
            "type": "Polygon",
            "coordinates": [
                [
                    [108.3142, 28.9984],
                    [108.3252, 29.0039],
                    [108.3252, 28.96],
                    [108.3142, 28.9984]
                ]
            ]
        },
        "tags": {
            "name": "酉阳土家族苗族自治县",
            "group": "china"
        },
        "timestamp": 0
    }],
    "status": 200,
    "code": "success"
}

查询geo对象并转为geoJson

请求方式: POST
URL: http(s)://localhost:8844/api/v1/geo/object/_search/geo.json
http body 请求参数:

| 名称 | 类型 | 是否必选 | 示例值 | 描述 | | —- | —- | —- | —- | —- |

| shape | Object | 否 | | 图形,如重庆市行政区域边界(扩展属性objectId为该边界的标识) |

| filter | QueryParamEntity | 否 | | 可根据GeoObject.tags中的属性进行查询 |

返回参数:

| 名称 | 类型 | 描述 | | —- | —- | —- |

| result | GeoJson | 返回数据,请参考GeoJson标准 |

| status | int | 状态码 |

| code | String | 业务编码 |

请求示例:
RequestUrl: http://localhost:8844/api/v1/geo/object/_search
RequestMethod: POST
RequestHeader:
X-Sign: f9f297a****************acf288a
X-Timestamp: 1587542185752
X-Client-Id: kF**********HRZ
Content-Type: application/json
::: tip 说明:
X-Sign为签名,body+X-Timestamp+SecuryeKeyMD5加密
X-Timestamp为时间戳
X-Client-Id为平台openApi客户端id
:::
RequestBody:
查询参数请参考查询geo对象接口

{
              "shape":{
                  "objectId":"youyang" //查询objectId为youyang geo对象内的所有geo信息
              },
              "filter":{

              }
          }

HttpResponse:

{
    "result": {
        "type": "FeatureCollection",
        "features": [{
            "type": "Feature",
            "properties": {
                "name": "酉阳土家族苗族自治县",
                "id": "youyang",
                "objectId": "youyang",
                "group": "china",
                "objectType": "city"
            },
            "geometry": {
                "type": "Polygon",
                "coordinates": [
                    [
                        [108.3142, 28.9984],
                        [108.3252, 29.0039],
                        [108.3252, 28.96],
                        [108.3142, 28.9984]
                    ]
                ]
            }
        }]
    },
    "status": 200,
    "code": "success"
}