API

    • 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. "token": "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJleHAiOjE2MzcyODcxNjMsImlhdCI6MTYzNzIwMDc2MywiaXNzIjoiRU1RIFRlY2hub2xvZ2llcyBDby4sIEx0ZCBBbGwgcmlnaHRzIHJlc2VydmVkLiIsInBhc3MiOiIwMDAwIiwidXNlciI6ImFkbWluIn0.2EZzPC9djErrCeYNrK2av0smh-eKxDYeyu7cW4MyknI"
    2. }

    添加 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. "error": 0
    2. }

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

    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

    响应状态

    • 200 OK

    响应

    添加 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. "type": 14,
    19. "address": "1!00001",
    20. "attribute": 3,
    21. "group_config_name": "config_modbus_tcp_sample_2",
    22. "id": 4
    23. },
    24. {
    25. "name": "tag3",
    26. "type": 11,
    27. "address": "1!400009",
    28. "attribute": 3,
    29. "group_config_name": "config_modbus_tcp_sample_2",
    30. "id": 5
    31. }
    32. ]
    33. }

    更新 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

    获取插件

    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

    Authorization Bearer \

    响应状态

    • 200 OK
    • 404
      • 2101 group config not exist

    Body

    响应

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

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

    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

    • 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"