API

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

数据类型

  • BYTE = 2
  • INT8 = 3
  • INT16 = 4
  • INT32 = 5
  • INT64 = 6
  • UINT8 = 7
  • UINT16 = 8
  • UINT32 = 9
  • UINT64 = 10
  • FLOAT = 11
  • DOUBLE = 12
  • BOOL = 13
  • BIT = 14
  • STRING = 15

点位属性

  • READ = 0x01

  • WRITE = 0x02

  • SUBSCRIBE = 0x04

Node 类型

  • DRIVER = 1
  • WEB = 2
  • MQTT = 3
  • DRIVERX = 4
  • APP = 5

插件类型

  • STATIC = 0
  • SYSTEM = 1
  • CUSTOM = 2

Node 控制

  • START = 0
  • STOP = 1

Node 状态

  • IDLE = 0
  • INIT = 1
  • READY = 2
  • RUNNING = 3
  • STOPPED = 4

Node 连接状态

  • DISCONNECTED = 0
  • CONNECTING = 1
  • CONNECTED = 2

Ping

POST /api/v2/ping

请求 Headers

Authorization Bearer \

响应状态

  • 200 OK

登录

POST /api/v2/login

请求 Headers

Content-Type application/json

响应状态

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

Body

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

响应

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

添加 Node

POST /api/v2/node

请求 Headers

Content-Type application/json

Authorization Bearer \

响应状态

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

Body

  1. {
  2. //node type
  3. "type": 1,
  4. //node name
  5. "name": "modbus-tcp-node",
  6. //plugin name
  7. "plugin_name": "modbus-plugin-tcp"
  8. }

响应

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

删除 Node

Delete /api/v2/node

请求 Headers

Content-Type application/json

Authorization Bearer \

响应状态

  • 200 OK
  • 404
    • 2003 node not exist

Body

  1. {
  2. //node id
  3. "id": 7
  4. }

响应

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

更新 Node(未实现)

PUT /api/v2/node

请求 Headers

Content-Type application/json

Authorization Bearer \

响应状态

  • 200 OK
  • 404
    • 2003 node exist

Body

  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

请求 Params

type 必需

请求 Headers

Authorization Bearer \

响应状态

  • 200 OK

响应

  1. {
  2. "nodes": [
  3. {
  4. //node name
  5. "name": "sample-driver-adapter",
  6. //node id
  7. "id": 1,
  8. "plugin_id": 1
  9. },
  10. {
  11. "name": "modbus-tcp-adapter",
  12. "id": 4,
  13. "plugin_id": 2
  14. },
  15. {
  16. "name": "opcua-adapter",
  17. "id": 6,
  18. "plugin_id": 3
  19. },
  20. {
  21. "name": "modbus-tcp-test",
  22. "id": 7,
  23. "plugin_id": 4
  24. }
  25. ]
  26. }

添加 Group Config

POST /api/v2/gconfig

请求 Headers

Content-Type application/json

Authorization Bearer \

响应状态

  • 200 OK
  • 404
    • 2003 node not exist
  • 409
    • 2103 group config conflict

Body

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

响应

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

删除 Group Config

DELETE /api/v2/gconfig

请求 Headers

Content-Type application/json

Authorization Bearer \

响应状态

  • 200 OK
  • 412
    • 2102 group config in use
  • 404
    • 2003 node not exist
    • 2101 group config not exist

Body

  1. {
  2. //node id
  3. "node_id": 4,
  4. //group config name
  5. "name": "gconfig1"
  6. }

响应

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

更新 Group Config(未实现)

PUT /api/v2/gconfig

请求 Headers

Content-Type application/json

Authorization Bearer \

响应状态

  • 200 OK
  • 404
    • 2101 group config not exist

Body

  1. {
  2. //group config name
  3. "name": "modbus-tcp-config1",
  4. //read/upload interval(ms)
  5. "interval": 20000,
  6. //node id
  7. "node_id": 4
  8. }

响应

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

获取 Group Config

GET /api/v2/gconfig

请求 Params

node_id 必需

请求 Headers

Authorization Bearer \

响应状态

  • 200 OK

响应

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

添加 Tag

POST /api/v2/tags

请求 Headers

Content-Type application/json

Authorization Bearer \

响应状态

  • 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

Body

  1. {
  2. //node id
  3. "node_id": 4,
  4. //group config name
  5. "group_config_name": "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": 1,
  14. //tag type
  15. "type": 4
  16. },
  17. {
  18. "name": "tag2",
  19. "address": "1!00001",
  20. "attribute": 3,
  21. "type": 14
  22. },
  23. {
  24. "name": "tag3",
  25. "address": "1!400009",
  26. "attribute": 3,
  27. "type": 11
  28. }
  29. ]
  30. }

响应

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

获取 Tag

GET /api/v2/tags

请求 Params

node_id requred

group_config_name optional

请求 Headers

Authorization Bearer \

响应状态

  • 200 OK
  • 404
    • 2003 node not exist

响应

  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": 1,
  12. //tag group config name
  13. "group_config_name": "config_modbus_tcp_sample_2",
  14. //tag id
  15. "id": 1
  16. },
  17. {
  18. "name": "tag2",
  19. "type": 14,
  20. "address": "1!00001",
  21. "attribute": 3,
  22. "group_config_name": "config_modbus_tcp_sample_2",
  23. "id": 4
  24. },
  25. {
  26. "name": "tag3",
  27. "type": 11,
  28. "address": "1!400009",
  29. "attribute": 3,
  30. "group_config_name": "config_modbus_tcp_sample_2",
  31. "id": 5
  32. }
  33. ]
  34. }

更新 Tag

PUT /api/v2/tags

请求 Headers

Content-Type application/json

Authorization Bearer \

响应状态

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

Body

  1. {
  2. //node id
  3. "node_id": 4,
  4. "tags": [
  5. {
  6. //tag id
  7. "id": 4,
  8. //tag name
  9. "name": "tag1",
  10. //tag type
  11. "type": 6,
  12. //tag attribute
  13. "attribute": 0,
  14. //tag address
  15. "address": "1!400001"
  16. },
  17. {
  18. "id": 5,
  19. "name": "tag2",
  20. "type": 6,
  21. "attribute": 0,
  22. "address": "1!400002"
  23. }
  24. ]
  25. }

响应

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

删除 Tag

DELETE /api/v2/tags

请求 Headers

Content-Type application/json

Authorization Bearer \

响应状态

  • 200 OK
  • 404
    • 2003 node not exist

Body

  1. {
  2. //group config name
  3. "group_config_name": "config_modbus_tcp_sample_2",
  4. //node id
  5. "node_id": 4,
  6. //tag ids
  7. "ids": [
  8. 4,
  9. 5
  10. ]
  11. }

响应

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

添加插件

POST /api/v2/plugin

请求 Headers

Content-Type application/json

Authorization Bearer \

响应状态

  • 200 OK

  • 400

    • 2302 library info invalid
  • 404

    • 2201 library not found
  • 409

    • 2203 library name conflict

Body

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

响应

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

删除插件

DELETE /api/v2/plugin

请求 Headers

Content-Type application/json

Authorization Bearer \

响应状态

  • 200 OK

Body

  1. {
  2. //plugin id
  3. "id": 1
  4. }

响应

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

获取插件

GET /api/v2/plugin

请求 Params

plugin_id optional

请求 Headers

Authorization Bearer \

响应状态

  • 200 OK

响应

  1. {
  2. "plugin_libs": [
  3. {
  4. //plugin id
  5. "id": 1,
  6. //plugin kind
  7. "kind": 1,
  8. //node type
  9. "node_type": 1,
  10. //plugin name
  11. "name": "plugin_name",
  12. //plugin library name
  13. "lib_name": "plugin_lib_name"
  14. }
  15. ]
  16. }

订阅

POST /api/v2/subscribe

请求 Headers

Content-Type application/json

Authorization Bearer \

响应状态

  • 200 OK
  • 404
    • 2101 group config not exist

Body

  1. {
  2. //src node id
  3. "src_node_id": 4,
  4. //dst node id
  5. "dst_node_id": 5,
  6. //src node group config name
  7. "name": "gconfig1"
  8. }

响应

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

取消订阅

DELETE /api/v2/subscribe

请求 Headers

Content-Type application/json

Authorization Bearer \

响应状态

  • 200 OK
  • 404
    • 2101 group config not exist

Body

  1. {
  2. //src node id
  3. "src_node_id": 4,
  4. //dst node id
  5. "dst_node_id": 5,
  6. //src node group config name
  7. "name": "gconfig1"
  8. }

响应

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

读点位

POST /api/v2/read

请求 Headers

Content—Type application/json

响应状态

  • 200

Body

  1. {
  2. //node name
  3. "node_name": "modbus-tcp-1",
  4. //group config name
  5. "group_name": "config_modbus_tcp_sample_2"
  6. }

响应

  1. {
  2. "tags": [
  3. {
  4. //tag nmae
  5. "name": "data1",
  6. //tag value
  7. "value": 1,
  8. },
  9. {
  10. "name": "data2",
  11. "error": 2014
  12. },
  13. {
  14. "name": "data3",
  15. "value": true,
  16. }
  17. ]
  18. }

注意 当某个点位读数值出错时,将显示 error 字段,不再显示 value 字段。

写点位

POST /api/v2/write

请求 Headers

Content-Type application/json

Authorization Bearer \

响应状态

  • 200 OK

Body

  1. {
  2. "node_name": "modbus-tcp-1",
  3. "group_name": "config_modbus_tcp_sample_2",
  4. "tag_name": "tag1",
  5. "value": 1234
  6. }

响应

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

获取插件 Schema

GET /api/v2/schema

请求 Params

plugin_name required

响应状态

  • 200 OK

响应

  1. {
  2. "tag_type": [
  3. 4,
  4. 5,
  5. 6,
  6. 7,
  7. 8,
  8. 9,
  9. 10,
  10. 11,
  11. 14
  12. ],
  13. "params": [
  14. "host",
  15. "port",
  16. "mode",
  17. "baud_rate",
  18. "real_param"
  19. ],
  20. "host": {
  21. "name": "host",
  22. "description": "host",
  23. "type": "string",
  24. "default": "127.0.0.1",
  25. "valid": {
  26. "length": 30
  27. }
  28. },
  29. "port": {
  30. "name": "port",
  31. "description": "port",
  32. "type": "int",
  33. "default": 502,
  34. "valid": {
  35. "min": 1024,
  36. "max": 65535
  37. }
  38. },
  39. "mode": {
  40. "name": "mode",
  41. "description": "mode",
  42. "type": "bool",
  43. "default": false,
  44. "valid": {}
  45. },
  46. "baud_rate": {
  47. "name": "baud rate",
  48. "description": "port",
  49. "type": "int",
  50. "default": 9600,
  51. "valid": {
  52. "value": [
  53. 9600,
  54. 112800
  55. ]
  56. }
  57. },
  58. "real_param": {
  59. "name": "real param",
  60. "description": "real",
  61. "type": "real",
  62. "default": 11.22,
  63. "valid": {
  64. "min": 1.1,
  65. "max": 20.2
  66. }
  67. },
  68. "ca": {
  69. "name": "ca",
  70. "description": "",
  71. "attribute": "optional",
  72. "type": "file",
  73. "condition": {
  74. "field": "mode",
  75. "value": true
  76. },
  77. "valid": {
  78. "length": 1024
  79. }
  80. }
  81. }

Node 配置

POST /api/v2/node/setting

请求 Headers

Content-Type application/json

Authorization Bearer \

响应状态

  • 200 OK
  • 400
    • 2003 node not exist
    • 2004 node setting invalid

Body

  1. //The parameter fields in json fill in different fields according to different plugins
  2. {
  3. //node id
  4. "node_id": 123,
  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

请求 Params

node_id 必需

请求 Headers

Authorization Bearer \

响应状态

  • 200 OK
    • 2005 node setting not found
  • 404
    • 2003 node not exist

响应

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

Node 控制

POST /api/v2/node/ctl

请求 Headers

Content-Type application/json

Authorization Bearer \

请求状态

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

Body

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

响应

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

获取 Node 状态

GET /api/v2/node/state

请求 Params

node_id required

请求 Headers

Authorization Bearer \

响应状态

  • 200 OK

响应

  1. {
  2. //running state
  3. "running": 2,
  4. //link state
  5. "link": 1
  6. }

获取订阅的 Group Config

GET /api/v2/subscribe

请求 Params

node_id required

请求 Headers

Authorization Bearer \

响应状态

  • 200
  • 400

响应

  1. {
  2. "groups": [
  3. {
  4. //node id
  5. "node_id": 1,
  6. //group config name
  7. "group_config_name": "g1name"
  8. },
  9. {
  10. "node_id": 2,
  11. "group_config_name": "g2name"
  12. }
  13. ]
  14. }

获取日志

GET /api/v2/log

请求 Params

since 必需, UTC 时间戳

until 必需, UTC timestamp, with since forms the interval [since, until)

level 选填, log level, should be one of trace, debug, info, warn, error, fatal

page 必需

page_size 必需,范围应在 200 ~ 10000

请求 Headers

Authorization Bearer \

响应状态

  • 200
  • 400
    • 1003 错误参数

响应

  1. {
  2. "error": 0,
  3. "rows": [
  4. "2022-02-11 15:30:57 WARN [neuron] src/main.c:90: recv sig: 2"
  5. ]
  6. }