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
响应
"token": "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJleHAiOjE2MzcyODcxNjMsImlhdCI6MTYzNzIwMDc2MywiaXNzIjoiRU1RIFRlY2hub2xvZ2llcyBDby4sIEx0ZCBBbGwgcmlnaHRzIHJlc2VydmVkLiIsInBhc3MiOiIwMDAwIiwidXNlciI6ImFkbWluIn0.2EZzPC9djErrCeYNrK2av0smh-eKxDYeyu7cW4MyknI"
}
添加 Node
POST /api/v2/node
请求 Headers
Content-Type application/json
Authorization Bearer \
响应状态
- 200 OK
- 400
- 2001 node 类型无效
- 404
- 2301 未找到插件库
- 409
- 2002 node 不存在
Body
{
//node type
"type": 1,
//node name
"name": "modbus-tcp-node",
//plugin name
"plugin_name": "modbus-plugin-tcp"
}
响应
{
"error": 0
}
删除 Node
Delete /api/v2/node
请求 Headers
Content-Type application/json
Authorization Bearer \
响应状态
- 200 OK
- 404
- 2003 node not exist
Body
{
//node id
"id": 7
}
响应
{
"error": 0
}
更新 Node(未实现)
PUT /api/v2/node
请求 Headers
Content-Type application/json
Authorization Bearer \
响应状态
- 200 OK
- 404
- 2003 node exist
Body
{
//node id
"id": 1,
//node name
"name": "modbus-tcp-node"
}
响应
"error": 0
}
获取 Node
GET /api/v2/node
请求 Params
type 必需
请求 Headers
Authorization Bearer \
响应状态
- 200 OK
响应
{
"nodes": [
{
//node name
"name": "sample-driver-adapter",
//node id
"id": 1,
"plugin_id": 1
},
{
"name": "modbus-tcp-adapter",
"id": 4,
"plugin_id": 2
},
{
"name": "opcua-adapter",
"id": 6,
"plugin_id": 3
},
{
"name": "modbus-tcp-test",
"id": 7,
"plugin_id": 4
}
]
}
添加 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
{
//group config name
"name": "gconfig1",
//node id
"node_id": 4,
//read/upload interval(ms)
"interval": 10000
}
响应
{
"error": 0
}
删除 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
{
//node id
"node_id": 4,
//group config name
"name": "gconfig1"
}
响应
{
"error": 0
}
PUT /api/v2/gconfig
请求 Headers
Content-Type application/json
Authorization Bearer \
- 200 OK
- 404
- 2101 group config not exist
Body
{
//group config name
"name": "modbus-tcp-config1",
//read/upload interval(ms)
"interval": 20000,
//node id
"node_id": 4
}
响应
{
"error": 0
}
获取 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
{
//node id
"node_id": 4,
//group config name
"group_config_name": "config_modbus_tcp_sample_2",
"tags": [
{
//tag name
"name": "tag1",
//tag address
"address": "1!400001",
//tag attribute
"attribute": 1,
//tag type
"type": 4
},
{
"name": "tag2",
"address": "1!00001",
"attribute": 3,
"type": 14
},
{
"name": "tag3",
"address": "1!400009",
"attribute": 3,
"type": 11
}
]
}
响应
{
"error": 0
}
获取 Tag
GET /api/v2/tags
请求 Params
node_id requred
group_config_name optional
请求 Headers
Authorization Bearer \
响应状态
- 200 OK
- 404
- 2003 node not exist
响应
{
"tags": [
{
//tag name
"name": "tag1",
//tag type
"type": 4,
//tag address
"address": "1!400001",
//tag attribute
"attribute": 1,
//tag group config name
"group_config_name": "config_modbus_tcp_sample_2",
//tag id
"id": 1
},
{
"type": 14,
"address": "1!00001",
"attribute": 3,
"group_config_name": "config_modbus_tcp_sample_2",
"id": 4
},
{
"name": "tag3",
"type": 11,
"address": "1!400009",
"attribute": 3,
"group_config_name": "config_modbus_tcp_sample_2",
"id": 5
}
]
}
更新 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
{
//node id
"node_id": 4,
"tags": [
{
//tag id
"id": 4,
//tag name
"name": "tag1",
//tag type
"type": 6,
//tag attribute
"attribute": 0,
//tag address
"address": "1!400001"
},
{
"id": 5,
"name": "tag2",
"type": 6,
"attribute": 0,
"address": "1!400002"
}
]
}
响应
{
"error": 0
}
删除 Tag
DELETE /api/v2/tags
请求 Headers
Content-Type application/json
Authorization Bearer \
响应状态
- 200 OK
- 404
- 2003 node not exist
Body
{
//group config name
"group_config_name": "config_modbus_tcp_sample_2",
//node id
"node_id": 4,
//tag ids
"ids": [
4,
5
]
}
响应
{
"error": 0
}
添加插件
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
{
//plugin library name
"lib_name": "plugin_name.so"
}
响应
{
"error": 0
}
删除插件
DELETE /api/v2/plugin
请求 Headers
Content-Type application/json
Authorization Bearer \
响应状态
- 200 OK
Body
{
//plugin id
"id": 1
}
响应
{
"error": 0
获取插件
GET /api/v2/plugin
请求 Params
plugin_id optional
请求 Headers
Authorization Bearer \
响应状态
- 200 OK
响应
{
"plugin_libs": [
{
//plugin id
"id": 1,
//plugin kind
"kind": 1,
//node type
"node_type": 1,
//plugin name
"name": "plugin_name",
//plugin library name
"lib_name": "plugin_lib_name"
}
]
}
POST /api/v2/subscribe
请求 Headers
Content-Type application/json
Authorization Bearer \
响应状态
- 200 OK
- 404
- 2101 group config not exist
Body
{
//src node id
"src_node_id": 4,
//dst node id
"dst_node_id": 5,
//src node group config name
"name": "gconfig1"
}
{
"error": 0
}
取消订阅
DELETE /api/v2/subscribe
请求 Headers
Authorization Bearer \
响应状态
- 200 OK
- 404
- 2101 group config not exist
Body
响应
{
"error": 0
}
读点位
POST /api/v2/read
请求 Headers
Content—Type application/json
响应状态
- 200
Body
{
//node name
"node_name": "modbus-tcp-1",
//group config name
"group_name": "config_modbus_tcp_sample_2"
}
响应
{
"tags": [
{
//tag nmae
"name": "data1",
//tag value
"value": 1,
},
{
"name": "data2",
"error": 2014
},
{
"name": "data3",
"value": true,
}
]
}
注意 当某个点位读数值出错时,将显示 error 字段,不再显示 value 字段。
写点位
POST /api/v2/write
请求 Headers
Content-Type application/json
Authorization Bearer \
响应状态
- 200 OK
Body
{
"node_name": "modbus-tcp-1",
"group_name": "config_modbus_tcp_sample_2",
"tag_name": "tag1",
"value": 1234
}
响应
{
"error": 0
}
获取插件 Schema
GET /api/v2/schema
请求 Params
plugin_name required
响应状态
- 200 OK
响应
{
4,
5,
6,
7,
8,
9,
10,
11,
14
],
"params": [
"host",
"port",
"mode",
"baud_rate",
"real_param"
],
"host": {
"name": "host",
"description": "host",
"type": "string",
"default": "127.0.0.1",
"valid": {
"length": 30
}
},
"port": {
"name": "port",
"description": "port",
"type": "int",
"default": 502,
"valid": {
"min": 1024,
"max": 65535
}
},
"mode": {
"name": "mode",
"description": "mode",
"type": "bool",
"default": false,
"valid": {}
},
"baud_rate": {
"name": "baud rate",
"description": "port",
"type": "int",
"default": 9600,
"valid": {
"value": [
9600,
112800
]
}
},
"real_param": {
"name": "real param",
"description": "real",
"type": "real",
"default": 11.22,
"valid": {
"min": 1.1,
"max": 20.2
}
},
"ca": {
"name": "ca",
"description": "",
"attribute": "optional",
"type": "file",
"condition": {
"field": "mode",
"value": true
},
"valid": {
"length": 1024
}
}
}
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
//The parameter fields in json fill in different fields according to different plugins
{
//node id
"node_id": 123,
"params": {
"param1": 1,
"param2": "1.1.1.1",
"param3": true,
"param4": 11.22
}
}
响应
{
"error": 0
}
获取 Node 配置
GET /api/v2/node/setting
请求 Params
node_id 必需
请求 Headers
Authorization Bearer \
响应状态
- 200 OK
- 2005 node setting not found
- 404
- 2003 node not exist
响应
//The parameter fields in json fill in different fields according to different plugins
{
"node_id": 4,
"params": {
"param1": "1.1.1.1",
"param2": 502
}
}
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
{
//node id
"id": 4,
//0 start, 1 stop
"cmd": 0
}
响应
{
"error": 0
}
获取 Node 状态
GET /api/v2/node/state
请求 Params
node_id required
请求 Headers
Authorization Bearer \
响应状态
- 200 OK
响应
{
//running state
"running": 2,
//link state
"link": 1
}
GET /api/v2/subscribe
请求 Params
node_id required
请求 Headers
Authorization Bearer \
响应状态
- 200
- 400
响应
{
"groups": [
{
//node id
"node_id": 1,
//group config name
"group_config_name": "g1name"
},
{
"node_id": 2,
"group_config_name": "g2name"
}
]
}
获取日志
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 错误参数
响应
{
"error": 0,
"rows": [
"2022-02-11 15:30:57 WARN [neuron] src/main.c:90: recv sig: 2"