配置

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

Ping

POST /api/v2/ping

请求头部

Authorization Bearer <token>

响应状态

  • 200 OK

登录

POST /api/v2/login

请求头部

Content-Type application/json

响应状态

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

请求体

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

响应

  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, 无效令牌

请求体

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

响应

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

添加 Node

POST /api/v2/node

请求头部

Content-Type application/json

Authorization Bearer <token>

响应状态

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

请求体

  1. {
  2. //node name
  3. "name": "modbus-tcp-node",
  4. //plugin name
  5. "plugin": "Modbus TCP"
  6. }

响应

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

删除 Node

Delete /api/v2/node

请求头部

Content-Type application/json

Authorization Bearer <token>

响应状态

  • 200 OK
  • 404
    • 2003 node not exist

请求体

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

响应

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

更新 Node(未实现)

PUT /api/v2/node

请求头部

Content-Type application/json

Authorization Bearer <token>

响应状态

  • 200 OK
  • 404
    • 2003 node exist

请求体

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

响应

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

获取 Node

GET /api/v2/node

请求参数

type 必需

plugin 可选

node 可选

请求头部

Authorization Bearer <token>

响应状态

  • 200 OK

响应

  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 配置无效

请求体

  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. }

提示

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

响应

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

获取 Node 配置

GET /api/v2/node/setting

请求参数

node 必需

请求头部

Authorization Bearer <token>

响应状态

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

响应

  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

请求体

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

响应

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

获取 Node 状态

GET /api/v2/node/state

请求参数

node optional

请求头部

Authorization Bearer <token>

响应状态

  • 200 OK

响应

  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. },
  13. {
  14. "node": "modbus-node2",
  15. "running": 1,
  16. "link": 0,
  17. "rtt": 9999
  18. }
  19. ]
  20. }

添加 Group

POST /api/v2/group

请求头部

Content-Type application/json

Authorization Bearer <token>

响应状态

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

请求体

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

响应

  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

请求体

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

响应

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

更新 Group

PUT /api/v2/group

请求头部

Content-Type application/json

Authorization Bearer <token>

响应状态

  • 200 OK
  • 404
    • 2106 group not exist

请求体

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

响应

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

获取 Group

GET /api/v2/group

请求参数

node 可选

请求头部

Authorization Bearer <token>

响应状态

  • 200 OK

响应

  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

请求体

  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. }

响应

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

获取 Tag

GET /api/v2/tags

请求参数

node 必需

group 必需

name 可选

请求头部

Authorization Bearer <token>

响应状态

  • 200 OK
  • 404
    • 2003 node 不存在

响应

  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 不存在

请求体

  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. }

响应

  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 不存在

请求体

  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. }

响应

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

添加插件

POST /api/v2/plugin

请求头部

Content-Type application/json

Authorization Bearer <token>

响应状态

  • 200 OK

  • 400

    • 2302 库信息无效

请求体

  1. {
  2. //plugin library name
  3. "library": "plugin_name.so"
  4. }

响应

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

删除插件

DELETE /api/v2/plugin

请求头部

Content-Type application/json

Authorization Bearer <token>

响应状态

  • 200 OK

请求体

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

响应

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

获取插件

GET /api/v2/plugin

请求参数

plugin optional

请求头部

Authorization Bearer <token>

响应状态

  • 200 OK

响应

  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

响应

  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 不存在

请求体

  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. }

响应

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

取消订阅

DELETE /api/v2/subscribe

请求头部

Content-Type application/json

Authorization Bearer <token>

响应状态

  • 200 OK
  • 404
    • 2106 group 不存在

请求体

  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. }

响应

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

获取订阅的 Group

GET /api/v2/subscribe

请求参数

app 必需

请求头部

Authorization Bearer <token>

响应状态

  • 200
  • 400

响应

  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 服务器内部错误

响应

  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 服务器内部错误

请求体

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

响应

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

获取 License 信息

GET /api/v2/license

请求头部

Authorization Bearer <token>

响应状态

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

响应

  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. }

下载日志文件

GET /api/v2/logs

请求头部

Authorization Bearer <token>

响应状态

  • 200 OK
  • 404
    • 1011 文件不存在
    • 1014 执行指令失败
  • 500
    • 1001 内部错误

响应

如果有错误返回时响应:

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

修改节点日志等级

PUT /api/v2/log/level

请求头部

Authorization Bearer <token>

响应状态

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

请求体

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

响应

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

提示

调用接口修改节点的日志等级为 debug,十分钟左右自动切回默认等级。

下载文件

GET /api/v2/file

请求头部

Authorization Bearer <token>

请求参数

file_path 必需,文件的绝对路径

响应状态

  • 404
    • 1011 文件不存在
    • 4101 文件打开失败
    • 4102 文件读失败

响应

当正常响应时,返回文件内容并下载文件。

当错误响应时,返回对应的错误码。

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

获取文件列表

GET /api/v2/file/info

请求头部

Authorization Bearer <token>

请求参数

dir_path 必需,目录的绝对路径

响应状态

  • 404
    • 1011 文件不存在
    • 4101 文件打开失败

响应

当正确响应时,响应文件名称、文件大小、文件创建时间和文件更新时间。

  1. {
  2. "files": [
  3. {
  4. "name": "neuron",
  5. "size": 4096,
  6. "ctime": "Wed Jan 4 02:38:12 2023",
  7. "mtime": "Mon Dec 26 09:48:42 2022"
  8. },
  9. {
  10. "name": "test.txt",
  11. "size": 13,
  12. "ctime": "Wed Jan 4 02:38:12 2023",
  13. "mtime": "Mon Dec 26 09:48:42 2022"
  14. }
  15. ]
  16. }

当错误响应时,响应对应的错误码。

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