配置

Neuron 将为 IIoT 平台提供一系列 API 服务,用于查询基本信息、控制网关行为或设置轮询配置。 IIoT 平台必须通过向 Neuron 发送请求消息来启动通信。 通过返回,Neuron 将返回所需的信息或执行相应的操作。 如果有错误,将返回一个错误代码来说明失败的原因。

Ping

POST /api/v2/ping

响应状态

  • 200 OK

登录

POST /api/v2/login

请求头部

Content-Type application/json

响应状态

  • 200 OK
  • 401
    • 1004, 缺少令牌
    • 1005, 解码令牌错误
  • 403
    • 1006, 令牌过期
    • 1007, 验证令牌错误
    • 1008, 无效令牌

请求体

json

  1. {
  2. "name": "admin",
  3. "pass": "0000"
  4. }

响应

json

  1. {
  2. "token": "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJleHAiOjE2MzcyODcxNjMsImlhdCI6MTYzNzIwMDc2MywiaXNzIjoiRU1RIFRlY2hub2xvZ2llcyBDby4sIEx0ZCBBbGwgcmlnaHRzIHJlc2VydmVkLiIsInBhc3MiOiIwMDAwIiwidXNlciI6ImFkbWluIn0.2EZzPC9djErrCeYNrK2av0smh-eKxDYeyu7cW4MyknI"
  3. }

更改密码

POST /api/v2/password

请求头部

Content-Type application/json

Authorization Bearer <token>

响应状态

  • 200 OK
  • 401
    • 1004, 缺少令牌
    • 1005, 解码令牌错误
    • 1012, 密码长度太短或太长
    • 1013, 密码重复
  • 403
    • 1006, 令牌过期
    • 1007, 验证令牌错误
    • 1008, 无效令牌

请求体

json

  1. {
  2. "name": "admin",
  3. "old_pass": "01234",
  4. "new_pass": "56789"
  5. }

响应

json

  1. {
  2. "error": 0
  3. }

添加 Node

POST /api/v2/node

请求头部

Content-Type application/json

Authorization Bearer <token>

响应状态

  • 200 OK
  • 400
    • 2001 node 类型无效
    • 2004 node 配置无效
  • 404
    • 2301 未找到插件库
  • 409
    • 2002 node 不存在

请求体

json

  1. {
  2. //node name
  3. "name": "modbus-tcp-node",
  4. //plugin name
  5. "plugin": "Modbus TCP"
  6. //setting (optional)
  7. "params": {
  8. "param1": 1,
  9. "param2": "1.1.1.1",
  10. "param3": true,
  11. "param4": 11.22
  12. }
  13. }

响应

json

  1. {
  2. "error": 0
  3. }

删除 Node

Delete /api/v2/node

请求头部

Content-Type application/json

Authorization Bearer <token>

响应状态

  • 200 OK
  • 404
    • 2003 node not exist

请求体

json

  1. {
  2. //node name
  3. "name": "modbus-tcp-node"
  4. }

响应

json

  1. {
  2. "error": 0
  3. }

更新 Node

PUT /api/v2/node

请求头部

Content-Type application/json

Authorization Bearer <token>

响应状态

  • 200 OK
  • 400
    • 2013 node 不允许更新
    • 2015 node 名称不允许为空
  • 404
    • 2003 node 不存在
  • 409
    • 2002 node 已存在
  • 500
    • 1001 内部错误
    • 1010 程序繁忙

请求体

json

  1. {
  2. "name": "modbus-node"
  3. "new_name": "modbus-tcp-node"
  4. }

响应

json

  1. {
  2. "error": 0
  3. }

获取 Node

GET /api/v2/node

请求参数

type 必需

plugin 可选

node 可选

请求头部

Authorization Bearer <token>

响应状态

  • 200 OK

响应

json

  1. {
  2. "nodes": [
  3. {
  4. //node name
  5. "name": "sample-driver-adapter",
  6. //plugin name
  7. "plugin": "Modbus TCP"
  8. },
  9. {
  10. "name": "modbus-tcp-adapter",
  11. "plugin": "Modbus TCP"
  12. }
  13. ]
  14. }

配置 Node

POST /api/v2/node/setting

请求头部

Content-Type application/json

Authorization Bearer <token>

响应状态

  • 200 OK
  • 400
    • 2003 node 不存在
    • 2004 node 配置无效

请求体

json

  1. //The parameter fields in json fill in different fields according to different plugins
  2. {
  3. //node name
  4. "node": "modbus-node",
  5. "params": {
  6. "param1": 1,
  7. "param2": "1.1.1.1",
  8. "param3": true,
  9. "param4": 11.22
  10. }
  11. }

TIP

每个插件的配置参数具体可参考 插件设置

响应

json

  1. {
  2. "error": 0
  3. }

获取 Node 配置

GET /api/v2/node/setting

请求参数

node 必需

请求头部

Authorization Bearer <token>

响应状态

  • 200 OK
    • 2005 node 配置未发现
  • 404
    • 2003 node 不存在

响应

json

  1. //The parameter fields in json fill in different fields according to different plugins
  2. {
  3. "node": "modbus-node",
  4. "params": {
  5. "param1": "1.1.1.1",
  6. "param2": 502
  7. }
  8. }

控制 Node

POST /api/v2/node/ctl

请求头部

Content-Type application/json

Authorization Bearer <token>

请求状态

  • 200 OK
  • 409
    • 2006 node not ready
    • 2007 node is running
    • 2008 node not running
    • 2009 node is stopped

请求体

json

  1. {
  2. //node name
  3. "node": "modbus-node",
  4. //0 start, 1 stop
  5. "cmd": 0
  6. }

响应

json

  1. {
  2. "error": 0
  3. }

获取 Node 状态

GET /api/v2/node/state

请求参数

node optional

请求头部

Authorization Bearer <token>

响应状态

  • 200 OK

响应

json

  1. {
  2. "states": [
  3. {
  4. //node name
  5. "node": "modbus-node1",
  6. //running state
  7. "running": 2,
  8. //link state
  9. "link": 1,
  10. //average round trip time communicating with devices
  11. "rtt": 100,
  12. //log level
  13. "log_level": "notice"
  14. },
  15. {
  16. "node": "modbus-node2",
  17. "running": 1,
  18. "link": 0,
  19. "rtt": 9999,
  20. "log_level": "notice"
  21. }
  22. ],
  23. //log level of neuron.log
  24. "neuron_core": "notice"
  25. }

添加 Group

POST /api/v2/group

请求头部

Content-Type application/json

Authorization Bearer <token>

响应状态

  • 200 OK
  • 404
    • 2003 node not exist
  • 409
    • 2103 group not allow

请求体

json

  1. {
  2. //group name
  3. "group": "gconfig1",
  4. //node name
  5. "node": "modbus-node",
  6. //read/upload interval(ms)
  7. "interval": 10000
  8. }

响应

json

  1. {
  2. "error": 0
  3. }

删除 Group

DELETE /api/v2/group

请求头部

Content-Type application/json

Authorization Bearer <token>

响应状态

  • 200 OK
  • 412
    • 2101 group already subscribed
  • 404
    • 2003 node not exist
    • 2101 group not exist

请求体

json

  1. {
  2. //node name
  3. "node": "modbus-node",
  4. //group name
  5. "group": "gconfig1"
  6. }

响应

json

  1. {
  2. "error": 0
  3. }

更新 Group

PUT /api/v2/group

请求头部

Content-Type application/json

Authorization Bearer <token>

响应状态

  • 200 OK
  • 404
    • 2003 node not exist
    • 2106 group not exist
  • 409
    • 2104 group exist

请求体

json

  1. {
  2. //node name
  3. "node": "node1",
  4. //group name
  5. "group": "group",
  6. //read/upload interval(ms)
  7. "interval": 20000
  8. }

更新 group name:

json

  1. {
  2. //node name
  3. "node": "modbus-node",
  4. //group name
  5. "group": "gconfig1",
  6. //group new name
  7. "new_name": "group1"
  8. }

更新 group interval:

json

  1. {
  2. //node name
  3. "node": "modbus-node",
  4. //group name
  5. "group": "gconfig1",
  6. //read/upload interval(ms)
  7. "interval": 10000
  8. }

同时更新 group name 和 interval:

json

  1. {
  2. //node name
  3. "node": "modbus-node",
  4. //group name
  5. "group": "gconfig1",
  6. //group new name
  7. "new_name": "group1",
  8. //read/upload interval(ms)
  9. "interval": 10000
  10. }

响应

json

  1. {
  2. "error": 0
  3. }

获取 Group

GET /api/v2/group

请求参数

node 可选

请求头部

Authorization Bearer <token>

响应状态

  • 200 OK

响应

json

  1. {
  2. "groups": [
  3. {
  4. //group name
  5. "name": "config_modbus_tcp_sample_2",
  6. //read/upload interval(ms)
  7. "interval": 2000,
  8. //tag count
  9. "tag_count": 0
  10. },
  11. {
  12. "name": "gconfig1",
  13. "interval": 10000,
  14. "tag_count": 0
  15. }
  16. ]
  17. }

添加 Tag

POST /api/v2/tags

请求头部

Content-Type application/json

Authorization Bearer <token>

响应状态

  • 200 OK
  • 206
    • 2202 tag name conflict
    • 2203 tag attribute not support
    • 2204 tag type not support
    • 2205 tag address format invalid
  • 404
    • 2003 node not exist

请求体

json

  1. {
  2. //node name
  3. "node": "modbus-node",
  4. //group name
  5. "group": "config_modbus_tcp_sample_2",
  6. "tags": [
  7. {
  8. //tag name
  9. "name": "tag1",
  10. //tag address
  11. "address": "1!400001",
  12. //tag attribute
  13. "attribute": 8,
  14. //tag type
  15. "type": 4,
  16. //optional, float/double precision, optional(0-17)
  17. "precision": 0,
  18. //optional, decimal
  19. "decimal": 0,
  20. //optional, description
  21. "description": "",
  22. //optional, when the attribute is static,the value field needs to be added.
  23. "value": 12
  24. },
  25. {
  26. "name": "tag2",
  27. "address": "1!00001",
  28. "attribute": 3,
  29. "type": 3,
  30. "decimal": 0.01
  31. },
  32. {
  33. "name": "tag3",
  34. "address": "1!400009",
  35. "attribute": 3,
  36. "type": 9,
  37. "precision": 3
  38. },
  39. {
  40. "name": "static_tag",
  41. "address": "",
  42. "attribute": 10,
  43. "type": 1,
  44. "description": "It is a static tag",
  45. "value": 42
  46. }
  47. ]
  48. }

响应

json

  1. {
  2. "index": 1,
  3. "error": 0
  4. }

添加多组 Tag

POST /api/v2/gtags

请求头部

Content-Type application/json

Authorization Bearer <token>

响应状态

  • 200 OK
  • 206
    • 2202 tag name conflict
    • 2203 tag attribute not support
    • 2204 tag type not support
    • 2205 tag address format invalid
  • 404
    • 2003 node not exist
    • 2106 group not exist

请求体

json

  1. {
  2. //node name
  3. "node": "modbus-node",
  4. "groups": [
  5. {
  6. //group name
  7. "group": "group_1",
  8. //group interval
  9. "interval": 3000,
  10. "tags": [
  11. {
  12. //tag name
  13. "name": "tag1",
  14. //tag address
  15. "address": "1!400001",
  16. //tag attribute
  17. "attribute": 3,
  18. //tag type
  19. "type": 3,
  20. //optional, float/double precision, optional(0-17)
  21. "precision": 0,
  22. //optional, decimal
  23. "decimal": 0,
  24. //optional, description
  25. "description": "",
  26. //optional, when the attribute is static,the value field needs to be added.
  27. "value": 12
  28. },
  29. {
  30. "name": "tag2",
  31. "address": "1!400002",
  32. "attribute": 3,
  33. "type": 9,
  34. "precision": 3
  35. }
  36. ]
  37. },
  38. {
  39. "group": "group_2",
  40. "interval": 3000,
  41. "tags": [
  42. {
  43. "name": "tag1",
  44. "address": "1!400003",
  45. "attribute": 3,
  46. "type": 9,
  47. "precision": 3
  48. },
  49. {
  50. "name": "tag2",
  51. "address": "1!400004",
  52. "attribute": 3,
  53. "type": 9,
  54. "precision": 3
  55. }
  56. ]
  57. }
  58. ]
  59. }

响应

json

  1. {
  2. //tags count
  3. "index": 4,
  4. "error": 0
  5. }

获取 Tag

GET /api/v2/tags

请求参数

node 必需

group 必需

name 可选

请求头部

Authorization Bearer <token>

响应状态

  • 200 OK
  • 404
    • 2003 node 不存在

响应

json

  1. {
  2. "tags": [
  3. {
  4. //tag name
  5. "name": "tag1",
  6. //tag type
  7. "type": 4,
  8. //tag address
  9. "address": "1!400001",
  10. //tag attribute
  11. "attribute": 8,
  12. //description
  13. "description": "",
  14. //float/double precision
  15. "precison": 0,
  16. //decimal
  17. "decimal": 0,
  18. //optional, when the attribute is static
  19. "value": 12
  20. },
  21. {
  22. "name": "tag2",
  23. "type": 14,
  24. "address": "1!00001",
  25. "attribute": 3,
  26. "description": "",
  27. "precison": 0,
  28. "decimal": 0,
  29. },
  30. {
  31. "name": "tag3",
  32. "type": 11,
  33. "address": "1!400009",
  34. "attribute": 3,
  35. "description": "",
  36. "precison": 0,
  37. "decimal": 0,
  38. }
  39. ]
  40. }

更新 Tag

PUT /api/v2/tags

请求头部

Content-Type application/json

Authorization Bearer <token>

响应状态

  • 200 OK
  • 206
    • 2201 tag 不存在
    • 2202 tag 名字冲突
    • 2203 tag 属性不支持
    • 2204 tag 类型不支持
    • 2205 tag 地址格式无效
  • 404
    • 2003 node 不存在
    • 2106 group 不存在

请求体

json

  1. {
  2. //node name
  3. "node": "modbus-tcp-test",
  4. //group name
  5. "group": "group1",
  6. "tags": [
  7. {
  8. //tag name
  9. "name": "tag1",
  10. //tag type
  11. "type": 8,
  12. //tag attribute
  13. "attribute": 0,
  14. //tag address
  15. "address": "1!400001",
  16. //description
  17. "description":"",
  18. //float/double precision
  19. "precison": 0,
  20. //decimal
  21. "decimal": 0,
  22. //when the attribute is static,the value field needs to be added.
  23. "value": 12
  24. },
  25. {
  26. "name": "tag2",
  27. "type": 6,
  28. "attribute": 0,
  29. "address": "1!400002",
  30. "description":"",
  31. "precison": 0,
  32. "decimal": 0,
  33. },
  34. {
  35. "name": "static_tag",
  36. "address": "",
  37. "attribute": 10,
  38. "type": 1,
  39. "description":"",
  40. "precison": 0,
  41. "decimal": 0,
  42. "value": 42
  43. }
  44. ]
  45. }

响应

json

  1. {
  2. "error": 0,
  3. "index": 1
  4. }

删除 Tag

DELETE /api/v2/tags

请求头部

Content-Type application/json

Authorization Bearer <token>

响应状态

  • 200 OK
  • 404
    • 2003 node 不存在

请求体

json

  1. {
  2. //group name
  3. "group": "config_modbus_tcp_sample_2",
  4. //node name
  5. "node": "modbus-node",
  6. //tag names
  7. "tags": [
  8. "tag1",
  9. "tag2"
  10. ]
  11. }

响应

json

  1. {
  2. "error": 0
  3. }

添加插件

POST /api/v2/plugin

请求头部

Content-Type application/json

Authorization Bearer <token>

响应状态

  • 200 OK

  • 400

    • 2302 库信息无效
    • 2303 库名称冲突
    • 2304 库文件打开失败
    • 2305 库文件插件无效
    • 2307 库文件插件实例化失败
    • 2308 库文件架构不支持
    • 2310 库文件添加失败
    • 2311 库文件插件已存在
    • 2313 库文件插件类型不支持

请求体

json

  1. {
  2. //plugin library name
  3. "library": "plugin_name.so",
  4. // base64 content of schema json file
  5. "schema_file":"...",
  6. // base64 content of library file
  7. "so_file":"..."
  8. }

响应

json

  1. {
  2. "error": 0
  3. }

更新插件

PUT /api/v2/plugin

请求头部

Content-Type application/json

Authorization Bearer <token>

响应状态

  • 200 OK

  • 400

    • 2302 库文件不存在
    • 2302 库信息无效
    • 2304 库文件打开失败
    • 2305 库文件插件无效
    • 2307 库文件插件实例化失败
    • 2308 库文件架构不支持
    • 2310 库文件添加失败
    • 2312 库文件插件不存在
    • 2313 库文件插件类型不支持

请求体

json

  1. {
  2. //plugin library name
  3. "library": "plugin_name.so",
  4. // base64 content of schema json file
  5. "schema_file":"...",
  6. // base64 content of library file
  7. "so_file":"..."
  8. }

响应

json

  1. {
  2. "error": 0
  3. }

删除插件

DELETE /api/v2/plugin

请求头部

Content-Type application/json

Authorization Bearer <token>

响应状态

  • 200 OK

  • 400

    • 2306 系统插件不允许删除
    • 2309 插件使用中

请求体

json

  1. {
  2. //plugin name
  3. "plugin": "modbus-tcp"
  4. }

响应

json

  1. {
  2. "error": 0
  3. }

获取插件

GET /api/v2/plugin

请求参数

plugin optional

请求头部

Authorization Bearer <token>

响应状态

  • 200 OK

响应

json

  1. {
  2. "plugins": [
  3. {
  4. //plugin kind
  5. "kind": 1,
  6. //node type
  7. "node_type": 1,
  8. //plugin name
  9. "name": "Modbus TCP",
  10. //plugin library name
  11. "library": "libplugin-modbus-tcp.so",
  12. "description": "description",
  13. "description_zh": "描述",
  14. "schema": "modbus-tcp"
  15. },
  16. {
  17. "kind": 1,
  18. "node_type": 2,
  19. "name": "MQTT",
  20. "library": "libplugin-mqtt.so",
  21. "description": "Neuron northbound MQTT plugin bases on NanoSDK.",
  22. "description_zh": "基于 NanoSDK 的 Neuron 北向应用 MQTT 插件",
  23. "schema": "mqtt"
  24. }
  25. ]
  26. }

获取插件 Schema

GET /api/v2/schema

请求参数

schema_name 必需

请求头部

Authorization Bearer <token>

响应状态

  • 200 OK

响应

json

  1. {
  2. "tag_regex": [
  3. {
  4. "type": 3,
  5. "regex": "^[0-9]+![3-4][0-9]+(#B|#L|)$"
  6. },
  7. {
  8. "type": 4,
  9. "regex": "^[0-9]+![3-4][0-9]+(#B|#L|)$"
  10. },
  11. {
  12. "type": 5,
  13. "regex": "^[0-9]+![3-4][0-9]+(#BB|#BL|#LL|#LB|)$"
  14. },
  15. {
  16. "type": 6,
  17. "regex": "^[0-9]+![3-4][0-9]+(#BB|#BL|#LL|#LB|)$"
  18. },
  19. {
  20. "type": 7,
  21. "regex": "^[0-9]+![3-4][0-9]+(#B|#L|)$"
  22. },
  23. {
  24. "type": 8,
  25. "regex": "^[0-9]+![3-4][0-9]+(#B|#L|)$"
  26. },
  27. {
  28. "type": 9,
  29. "regex": "^[0-9]+![3-4][0-9]+(#BB|#BL|#LL|#LB|)$"
  30. },
  31. {
  32. "type": 10,
  33. "regex": "^[0-9]+![3-4][0-9]+(#B|#L|)$"
  34. },
  35. {
  36. "type": 11,
  37. "regex": "^[0-9]+!([0-1][0-9]+|[3-4][0-9]+\\.([0-9]|[0-1][0-5]))$"
  38. },
  39. {
  40. "type": 13,
  41. "regex": "^[0-9]+![3-4][0-9]+\\.[0-9]+(H|L|)$"
  42. }
  43. ],
  44. "group_interval": 1000,
  45. "connection_mode": {
  46. "name": "Connection Mode",
  47. "name_zh": "连接模式",
  48. "description": "Neuron as the client, or as the server",
  49. "description_zh": "Neuron 作为客户端或服务端",
  50. "attribute": "required",
  51. "type": "map",
  52. "default": 0,
  53. "valid": {
  54. "map": [
  55. {
  56. "key": "Client",
  57. "value": 0
  58. },
  59. {
  60. "key": "Server",
  61. "value": 1
  62. }
  63. ]
  64. }
  65. },
  66. "interval": {
  67. "name": "Send Interval",
  68. "name_zh": "指令发送间隔",
  69. "description": "Send reading instruction interval(ms)",
  70. "description_zh": "发送读指令时间间隔,单位为毫秒",
  71. "attribute": "required",
  72. "type": "int",
  73. "default": 20,
  74. "valid": {
  75. "min": 0,
  76. "max": 3000
  77. }
  78. },
  79. "host": {
  80. "name": "IP Address",
  81. "name_zh": "IP地址",
  82. "description": "Local IP in server mode, remote device IP in client mode",
  83. "description_zh": "服务端模式中填写本地 IP,客户端模式中填写目标设备 IP",
  84. "attribute": "required",
  85. "type": "string",
  86. "valid": {
  87. "regex": "/^((2[0-4]\\d|25[0-5]|[01]?\\d\\d?)\\.){3}(2[0-4]\\d|25[0-5]|[01]?\\d\\d?)$/",
  88. "length": 30
  89. }
  90. },
  91. "port": {
  92. "name": "Port",
  93. "name_zh": "端口号",
  94. "description": "Local port in server mode, remote device port in client mode",
  95. "description_zh": "服务端模式中填写本地端口号,客户端模式中填写远程设备端口号",
  96. "attribute": "required",
  97. "type": "int",
  98. "default": 502,
  99. "valid": {
  100. "min": 1,
  101. "max": 65535
  102. }
  103. },
  104. "timeout": {
  105. "name": "Connection Timeout",
  106. "name_zh": "连接超时时间",
  107. "description": "Connection timeout(ms)",
  108. "description_zh": "连接超时时间,单位为毫秒",
  109. "attribute": "required",
  110. "type": "int",
  111. "default": 3000,
  112. "valid": {
  113. "min": 1000,
  114. "max": 65535
  115. }
  116. }
  117. }

订阅

POST /api/v2/subscribe

请求头部

Content-Type application/json

Authorization Bearer <token>

响应状态

  • 200 OK
  • 404
    • 2106 group 不存在

请求体

json

  1. {
  2. //app name
  3. "app": "mqtt",
  4. //driver name
  5. "driver": "modbus-tcp",
  6. //driver node group name
  7. "group": "group-1",
  8. //when using the MQTT plugin, the topic field needs to be added
  9. "params": {
  10. "topic": "/neuron/mqtt/group-1"
  11. }
  12. }

响应

json

  1. {
  2. "error": 0
  3. }

订阅多个组

POST /api/v2/subscribes

请求头部

Content-Type application/json

Authorization Bearer <token>

响应状态

  • 200 OK
  • 404
    • 2106 group 不存在

请求体

json

  1. {
  2. //app name
  3. "app": "mqtt",
  4. "groups": [
  5. {
  6. //driver name
  7. "driver": "modbus1",
  8. //group name
  9. "group": "group1",
  10. //optional, depends on plugins
  11. "params": {
  12. //when using the MQTT plugin, the topic key is the upload topoic
  13. "topic": "/neuron/mqtt/modbus1/group1"
  14. }
  15. },
  16. {
  17. "driver": "modbus2",
  18. "group": "group2",
  19. "params": {
  20. "topic": "/neuron/mqtt/modbus2/group2"
  21. }
  22. }
  23. ]
  24. }

响应

json

  1. {
  2. "error": 0
  3. }

更新订阅参数

PUT /api/v2/subscribe

请求头部

Content-Type application/json

Authorization Bearer <token>

响应状态

  • 200 OK
  • 404
    • 2106 group 不存在

请求体

json

  1. {
  2. //app name
  3. "app": "mqtt",
  4. //driver name
  5. "driver": "modbus-tcp",
  6. //driver node group name
  7. "group": "group-1",
  8. "params": {
  9. //when using the MQTT plugin, the topic key is the upload topic
  10. "topic": "/neuron/mqtt/group-1"
  11. }
  12. }

响应

json

  1. {
  2. "error": 0
  3. }

取消订阅

DELETE /api/v2/subscribe

请求头部

Content-Type application/json

Authorization Bearer <token>

响应状态

  • 200 OK
  • 404
    • 2106 group 不存在

请求体

json

  1. {
  2. //app name
  3. "app": "mqtt",
  4. //driver name
  5. "driver": "modbus-tcp",
  6. //driver node group name
  7. "group": "group-1",
  8. //optional, when using the MQTT plugin, the topic field needs to be added
  9. "params": {
  10. "topic": "/neuron/mqtt/group-1"
  11. }
  12. }

响应

json

  1. {
  2. "error": 0
  3. }

获取订阅的 Group

GET /api/v2/subscribe

请求参数

app 必需

driver 可选,对南向节点名字进行子字符串匹配过滤。

group 可选,对组名字进行子字符串匹配过滤。

请求头部

Authorization Bearer <token>

响应状态

  • 200
  • 400

响应

json

  1. {
  2. "groups": [
  3. {
  4. //driver name
  5. "driver": "modbus-tcp",
  6. //group name
  7. "group": "group-1",
  8. //optional, when using the MQTT plugin, the topic field needs to be added
  9. "params": {
  10. "topic": "/neuron/mqtt/group-1"
  11. }
  12. },
  13. {
  14. //driver name
  15. "driver": "modbus-tcp",
  16. //group name
  17. "group": "group-2",
  18. //when using the MQTT plugin, the topic field needs to be added
  19. "params": {
  20. "topic": "/neuron/mqtt/group-2"
  21. }
  22. }
  23. ]
  24. }

获取版本信息

GET /api/v2/version

请求头部

Authorization Bearer <token>

响应状态

  • 200
  • 500
    • 1001 服务器内部错误

响应

json

  1. {
  2. "build_date": "2022-06-01",
  3. "revision": "99e2184+dirty", // dirty 表示有未提交的更改
  4. "version": "2.4.0"
  5. }

上传 License

POST /api/v2/license

请求头部

Authorization Bearer <token>

响应状态

  • 200
    • 0 OK
    • 2402 license 过期
  • 400
    • 2401 license 无效
  • 500
    • 1001 服务器内部错误

请求体

json

  1. {
  2. "license": "-----BEGIN CERTIFICATE-----\nMIID2TCCAsGgAwIBAgIEATSJqjA....."
  3. }

响应

json

  1. {
  2. "error": 2401
  3. }

获取 License 信息

GET /api/v2/license

请求头部

Authorization Bearer <token>

响应状态

  • 200 OK
  • 404
    • 2400 license 未找到
  • 500
    • 1001 服务器内部错误

响应

json

  1. {
  2. "valid_until": "2023-03-15 08:11:19",
  3. "valid_since": "2022-03-15 08:11:19",
  4. "valid": false,
  5. "max_nodes": 1,
  6. "max_node_tags": 1,
  7. "used_nodes": 12,
  8. "used_tags": 846,
  9. "license_type": "retail",
  10. "error": 0,
  11. "enabled_plugins": [
  12. "MODBUS TCP Advance",
  13. "OPC UA"
  14. ],
  15. "hardware_token": "I+kZidSifiyVSbz0/EgcM6AcefnlfR4IU19ZZUnTS18=",
  16. "object": "emq",
  17. "email_address": "emq@emqx.io"
  18. }

修改节点日志等级

PUT /api/v2/log/level

请求头部

Authorization Bearer <token>

响应状态

  • 200 OK
  • 404
    • 2003 node 不存在
  • 500
    • 1001 内部错误
    • 1010 程序繁忙

请求体

json

  1. {
  2. // node name
  3. "node": "modbus-tcp",
  4. // log level: debug, info, notice, warn, error, fatal
  5. "level": "debug",
  6. // whether to switch the core log level
  7. "core": true
  8. }

TIP

core 字段选填,默认为 true。

node 字段选填,不填此字段时 core 不可以为 false,此时仅切换核心日志等级。

响应

json

  1. {
  2. "error": 0
  3. }

批量添加 Drivers

PUT /api/v2/global/drivers

请求头部

Content-Type application/json

Authorization Bearer <token>

响应状态

  • 200 OK
  • 206
    • 2203 tag 属性不支持
    • 2204 tag 类型不支持
    • 2205 tag 地址格式无效
    • 2206 tag 名字太长
    • 2207 tag 地址太长
    • 2208 tag 描述太长
    • 2209 tag 精度无效
  • 400
    • 1002 请求 body 无效
    • 2010 node 名称太长
    • 2011 node 不允许删除
    • 2105 group 参数无效
    • 2107 group 名称太长
    • 2304 库打开失败
    • 3013 插件名字太长
    • 3019 插件不支持请求的操作
  • 404
    • 2301 库未找到
    • 3014 插件不存在
  • 409
    • 2104 group 已存在
    • 2202 tag 名称冲突
    • 2307 插件不允许实例化
  • 500
    • 1001 内部错误
    • 1010 程序繁忙

请求体

json

  1. {
  2. "nodes": [
  3. {
  4. "name": "rtu template",
  5. "plugin": "Modbus RTU",
  6. "params": {
  7. "param1": 1,
  8. "param2": "1.1.1.1",
  9. "param3": true,
  10. "param4": 11.22
  11. },
  12. "groups": [
  13. {
  14. "name": "group1",
  15. "interval": 2000,
  16. "tags": [
  17. {
  18. "name": "tag1",
  19. "type": 4,
  20. "address": "1!400001",
  21. "attribute": 1,
  22. "precison": 1,
  23. "decimal": 0
  24. },
  25. {
  26. "name": "tag2",
  27. "type": 11,
  28. "address": "1!400009",
  29. "attribute": 3
  30. }
  31. ]
  32. }
  33. ]
  34. }
  35. ]
  36. }

响应

json

  1. {
  2. "error": 0
  3. }

获取 Drivers

GET /api/v2/global/drivers

请求头部

Content-Type application/json

Authorization Bearer <token>

请求参数

name Optional, list of names to filter out driver nodes (separated by ‘,’) name 可选,指定要过滤的南下节点名字列表(以 ‘,’ 分隔)。 未指定 name 参数时,则返回所有模板的列表。

响应状态

  • 200 OK
    • 2005 node 设置未找到
  • 400
    • 1003 请求 param 无效
  • 404
    • 2003 node 不存在
  • 500
    • 1001 内部错误
    • 1010 程序繁忙

响应

如果成功,返回所有南向节点。

json

  1. {
  2. "nodes": [
  3. {
  4. "name": "rtu template",
  5. "plugin": "Modbus RTU",
  6. "params": {
  7. "param1": 1,
  8. "param2": "1.1.1.1",
  9. "param3": true,
  10. "param4": 11.22
  11. },
  12. "groups": [
  13. {
  14. "name": "group1",
  15. "interval": 2000,
  16. "tags": [
  17. {
  18. "name": "tag1",
  19. "type": 4,
  20. "address": "1!400001",
  21. "attribute": 1,
  22. "precison": 1,
  23. "decimal": 0
  24. },
  25. {
  26. "name": "tag2",
  27. "type": 11,
  28. "address": "1!400009",
  29. "attribute": 3
  30. }
  31. ]
  32. }
  33. ]
  34. }
  35. ]
  36. }

否则返回错误玛。

json

  1. {
  2. "error": 0
  3. }