[关闭]
@soszrg 2019-05-09T03:32:54.000000Z 字数 5439 阅读 447

设备管理接口

anxin


服务器地址

  1. http://121.40.214.215:8001

token格式

  1. Authorization: token 1:d79be1d657d9a8b45f6f903620e84b06cbf225e0
  1. 登出接口(token)

设备列表(token)

接口地址

GET /api/v1/projects/devices/

请求示例

  1. GET /api/v1/projects/devices/?page=1&page_size=10&project_id=10&product_type=0
  2. {
  3. }

请求参数说明

参数 类型 必须 说明
page int N 页码
page_size int N 每页条目数
project_id int Y 项目id
product_type int Y 产品类别

返回参数

  1. {
  2. "meta":{
  3. "message":"info list",
  4. "code":0
  5. },
  6. "data":{
  7. "count":5,
  8. "page_size":10,
  9. "next":null,
  10. "previous":null,
  11. "results":[
  12. {
  13. "id":22,
  14. "device_id":"a88d813af3291...",
  15. "iot_secret":"",
  16. "product":{
  17. "product_id":"c374be3301...",
  18. "name":"test3"
  19. },
  20. "parent":{
  21. "device_id":"3e527594f328...",
  22. "dsn":"zrgtest18112805"
  23. },
  24. "house":null,
  25. "dsn":"zrgtest18112809",
  26. "house_id":null,
  27. "project_id":10,
  28. "alias":null,
  29. "wifi_ver":"",
  30. "mcu_ver":"",
  31. "online_times":0,
  32. "extra":{
  33. "a":1,
  34. "b":2
  35. },
  36. "status":true,
  37. "is_online":false,
  38. "is_active":false,
  39. "is_virtual":false,
  40. "created_at":"2018-11-29T00:21:28",
  41. "updated_at":"2018-11-29T00:21:28"
  42. },
  43. {
  44. "id":21,
  45. "device_id":"63613c98f...",
  46. "iot_secret":"",
  47. "product":{
  48. "product_id":"c374be33010cd...",
  49. "name":"test3"
  50. },
  51. "parent":{
  52. "device_id":"3e527594f3281...",
  53. "dsn":"zrgtest18112805"
  54. },
  55. "house":null,
  56. "dsn":"zrgtest18112808",
  57. "house_id":null,
  58. "project_id":10,
  59. "alias":null,
  60. "wifi_ver":"",
  61. "mcu_ver":"",
  62. "online_times":0,
  63. "extra":{
  64. "a":1,
  65. "b":2
  66. },
  67. "status":true,
  68. "is_online":false,
  69. "is_active":false,
  70. "is_virtual":false,
  71. "created_at":"2018-11-29T00:19:32",
  72. "updated_at":"2018-11-29T00:19:32"
  73. }
  74. ]
  75. }
  76. }

返回参数说明

参数 类型 说明
id int 设备db id
device_id string 设备id
product.product_id string 产品id
product.name string 产品名
parent.device_id string 父级设备id
parent.dsn string 父级设备mac/编号等
house json object 所属房间信息(待定)
dsn string 设备mac/编号(等)
project_id int 项目id
alias string 设备别名
wifi_ver string wifi固件版本
mcu_ver string wifi固件版本
online_times int 设备上线c
extra json object 拓展信息(冗余表信息存于此)
updated_at string 更新时间
created_at string 创建时间

错误码

code 说明
10000 参数错误:具体信息参加Response的message字段

添加设备(token)

接口地址

POST /api/v1/projects/devices/

请求示例

  1. POST /api/v1/projects/devices/
  2. {
  3. "project_id":42,
  4. "dsn":"00191108",
  5. "product_id":"7355a1cefdb8dd8f88c2520cb4b2d0",
  6. "parent_id": 2,
  7. "alias":"真实中继器1",
  8. "extra":
  9. {
  10. "chanel_nums":120
  11. }
  12. }

请求参数说明

参数 类型 必须 说明
product_id string Y 产品id
parent_id string N 父级设备id(使用db id)
house_id int N 所属房间id(预留)
dsn string N 中继器或采集器表号
project_id N int 项目id
alias string N 设备别名
extra json object N 拓展信息(冗余表信息存于此)

返回参数

  1. {
  2. "meta":{
  3. "code":0,
  4. "message":"create ok"
  5. },
  6. "data":{
  7. "id":23,
  8. "device_id":"81fef4baf37...",
  9. "product":{
  10. "product_id":"c374be33010...",
  11. "name":"test3"
  12. },
  13. "parent":null,
  14. "house":null,
  15. "dsn":"zrgtest18112910",
  16. "iot_secret":"",
  17. "project_id":10,
  18. "alias":"",
  19. "wifi_ver":"",
  20. "mcu_ver":"",
  21. "online_times":0,
  22. "extra":{
  23. "chanel_nums":1,
  24. "diam":"10",
  25. "init_flow":"10.00"
  26. },
  27. "is_online":false,
  28. "is_virtual":false,
  29. "created_at":"2018-11-29T10:28:50",
  30. "updated_at":"2018-11-29T10:28:50"
  31. }
  32. }

返回参数说明

参数 类型 说明
id int 设备db id
device_id string 设备id
product.product_id string 产品id
product.name string 产品名
parent.device_id string 父级设备id
parent.dsn string 父级设备mac/编号等
house json object 所属房间信息(待定)
dsn string 设备mac/编号(等)
project_id int 项目id
alias string 设备别名
extra json object 拓展信息(冗余表信息存于此)
updated_at string 更新时间
created_at string 创建时间

错误码

code 说明
10000 参数错误:具体信息参加Response的message字段
10300 产品不存在
10301 设备不存在
10050 创建iot设备异常

获取单个设备信息(token)

接口地址

GET /api/v1/projects/devices/[device_id]/info/

请求示例

  1. GET /api/v1/projects/devices/81fef4baf37e.../info/?project_id=10
  2. {
  3. }

请求参数说明

参数 类型 必须 说明
device_id string Y 设备id
project_id int Y 项目id

返回参数

  1. {
  2. "meta":{
  3. "code":0,
  4. "message":"create ok"
  5. },
  6. "data":{
  7. "id":23,
  8. "device_id":"81fef4baf37...",
  9. "product":{
  10. "product_id":"c374be33010...",
  11. "name":"test3"
  12. },
  13. "parent":null,
  14. "house":null,
  15. "dsn":"zrgtest18112910",
  16. "iot_secret":"",
  17. "project_id":10,
  18. "alias":"",
  19. "wifi_ver":"",
  20. "mcu_ver":"",
  21. "online_times":0,
  22. "extra":{
  23. "chanel_nums":1,
  24. "diam":"10",
  25. "init_flow":"10.00"
  26. },
  27. "is_online":false,
  28. "is_virtual":false,
  29. "created_at":"2018-11-29T10:28:50",
  30. "updated_at":"2018-11-29T10:28:50"
  31. }
  32. }

返回参数说明


更新设备信息(token)

接口地址

PUT /api/v1/projects/devices/[device_id]/info/

请求示例

  1. PUT /api/v1/projects/devices/81fef4baf37e11e8.../info/
  2. {
  3. "project_id": 4,
  4. "house_id": 101,
  5. "parent_id": 22,
  6. "is_master": true,
  7. "extra":{
  8. "chanel_nums":1, # 信道总数
  9. "diam": "10", # 口径尺寸
  10. "init_flow": "10.00", # 初始流量/电量
  11. },
  12. }

请求参数说明

参数 类型 必须 说明 位置
device_id string Y 设备id path
project_id int Y 项目id body
is_master bool N 是否为主表 body
house_id int N 房间id body
parent_id int N 父级设备id body
dsn string N 表号 body
extra json对象 N 附加信息 body

返回参数


删除设备(token)

接口地址

DELETE /api/v1/projects/devices/[device_id]/info/

请求示例

  1. DELETE /api/v1/projects/devices/81fef4baf37e11e8.../info/
  2. {
  3. }

请求参数说明

返回参数

  1. {
  2. "meta":{
  3. "code":0,
  4. "message":"delete device[81fef4baf37e11e...:zrgtest18112910] ok"
  5. },
  6. "data":{
  7. }
  8. }

返回参数说明


关联子设备(token)

接口地址

POST /api/v1/projects/devices/subs/

请求示例

  1. POST /api/v1/projects/devices/subs/
  2. {
  3. "parent": "ahhxfaa...",
  4. "houses": [12, 15, 16]
  5. }

请求参数说明

参数 类型 必须 说明
parent string Y 父设备id
houses int array Y 要关联设备的房间id

返回参数

  1. {
  2. "meta":{
  3. "code":0,
  4. "message":"add sub devices ok"
  5. },
  6. "data":{
  7. }
  8. }

返回参数说明

错误码

code 说明
10000 参数错误:具体信息参加Response的message字段
10251 房间不存在
10303 父设备不存在

查询未关联到该采集器的房间(token)

接口地址

GET /api/v1/projects/devices/subs/

请求示例

  1. GET /api/v1/projects/devices/subs/?page_size=10&page=1&device_id=aaxx...&query_type=0&house_parent=
  2. {
  3. }

请求参数说明

参数 类型 必须 说明
device_id string Y 采集器的设备id
query_type int Y 查询类型

查询类型说明:

说明
0 查询未关联到该采集器的房间
其他 根据设备类型id(如水表品类id,电表品类id等)查询设备

返回参数

  1. {
  2. "meta": {
  3. "message": "info list",
  4. "code": 0
  5. },
  6. "data": {
  7. "count": 2,
  8. "page_size": 10,
  9. "next": null,
  10. "previous": null,
  11. "results": [
  12. {
  13. "id": 31,
  14. "address": [
  15. "发发发",
  16. "1",
  17. "1",
  18. "2",
  19. "201"
  20. ]
  21. },
  22. {
  23. "id": 28,
  24. "address": [
  25. "发发发",
  26. "1",
  27. "1",
  28. "1",
  29. "tag"
  30. ]
  31. }
  32. ]
  33. }
  34. }

返回参数说明

错误码


获取采集器路由表(token)

接口地址

GET /api/v1/projects/devices/route/

请求示例

  1. GET /api/v1/projects/devices/route/?collector_id=aaxx...
  2. {
  3. }

请求参数说明

参数 类型 必须 说明
collector_id string Y 采集器的设备id

返回参数

  1. {
  2. "meta": {
  3. "code": 0,
  4. "message": "route info"
  5. },
  6. "data": [
  7. "zrgtest1812104/00000000"
  8. ]
  9. }

返回参数说明

错误码


添加新批注
在作者公开此批注前,只有你和作者可见。
回复批注