API

Neuron provide a series of API services for IIoT platform, to query the basic information, to control gateway behaviors or to setup the polling configuration. IIoT platform can initiate the communication by sending request message to Neuron. By return, Neuron would send back the required information or execute the deserved action. If there is error, a error code would be returned to tell the reason of failure.

Value

Data Type

  • 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

Data Attribute

  • READ = 0x01

  • WRITE = 0x02

  • SUBSCRIBE = 0x04

Node Type

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

Plugin Kind

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

Node CTL

  • START = 0
  • STOP = 1

Node State

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

Ping

POST /api/v2/ping

Request Headers

Authorization Bearer \

Response Status

  • 200 OK

Login

POST /api/v2/login

Request Headers

Content-Type application/json

Response Status

  • 200 OK
Error code Type of error
401 1004, Missing token
401 1005, Decoding token error
401 1009, User or password error
403 1006, Expired token
403 1007, Validate token error
403 1008, Invalid token

Body

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

Response

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

Add Node

POST /api/v2/node

Request Headers

Content-Type application/json

Authorization Bearer \

Response Status

  • 200 OK
  • 400
    • 2001 node type invalid
  • 404
    • 2301 plugin library not found
  • 409
    • 2002 node exist

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

Response

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

Del Node

Delete /api/v2/node

Request Headers

Content-Type application/json

Authorization Bearer \

Response Status

  • 200 OK
  • 404
    • 2003 node not exist

Body

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

Response

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

Update Node(Not Implemented)

PUT /api/v2/node

Request Headers

Content-Type application/json

Authorization Bearer \

Response Status

  • 200 OK
  • 404
    • 2003 node exist

Body

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

Response

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

Get Node

GET /api/v2/node

Request Params

type required

Request Headers

Authorization Bearer \

Response Status

  • 200 OK

Response

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

Add Group Config

POST /api/v2/gconfig

Request Headers

Content-Type application/json

Authorization Bearer \

Response Status

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

Response

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

Del Group Config

DELETE /api/v2/gconfig

Request Headers

Content-Type application/json

Authorization Bearer \

Response Status

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

Response

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

Update Group Config(Not Implemented)

PUT /api/v2/gconfig

Request Headers

Content-Type application/json

Authorization Bearer \

Response Status

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

Response

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

Get Group Config

GET /api/v2/gconfig

Request Params

node_id required

Request Headers

Authorization Bearer \

Response Status

  • 200 OK

Response

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

Add Tag

POST /api/v2/tags

Request Headers

Content-Type application/json

Authorization Bearer \

Response Status

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

Response

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

Get Tag

GET /api/v2/tags

Request Params

node_id requred

group_config_name optional

Request Headers

Authorization Bearer \

Response Status

  • 200 OK
  • 404
    • 2003 node not exist

Response

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

Update Tag

PUT /api/v2/tags

Request Headers

Content-Type application/json

Authorization Bearer \

Response status

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

Response

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

Del Tag

DELETE /api/v2/tags

Request Headers

Content-Type application/json

Authorization Bearer \

Response Status

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

Response

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

Add Plugin

POST /api/v2/plugin

Request Headers

Content-Type application/json

Authorization Bearer \

Response Status

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

Response

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

Del Plugin

DELETE /api/v2/plugin

Request Headers

Content-Type application/json

Authorization Bearer \

Response Status

  • 200 OK

Body

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

Response

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

Get Plugin

GET /api/v2/plugin

Request Params

plugin_id optional

Request Headers

Authorization Bearer \

Response Status

  • 200 OK

Response

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

Subscribe

POST /api/v2/subscribe

Request Headers

Content-Type application/json

Authorization Bearer \

Response Status

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

Response

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

UnSubscribe

DELETE /api/v2/subscribe

Request Headers

Content-Type application/json

Authorization Bearer \

Response Status

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

Response

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

Read Tag

POST /api/v2/read

Request Headers

Content—Type application/json

Response Status

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

Response

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

Note The value is displayed only when the value is read correctly, when the value is read incorrectly, the error code is displayed, not the value.

Write Tag

POST /api/v2/write

Request Headers

Content-Type application/json

Authorization Bearer \

Response Status

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

Response

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

Get Plugin Schema

GET /api/v2/schema

Request Params

plugin_name required

Response Status

  • 200 OK

Response

  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 Setting

POST /api/v2/node/setting

Request Headers

Content-Type application/json

Authorization Bearer \

Response Status

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

Response

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

Get Node Setting

GET /api/v2/node/setting

Request Params

node_id required

Request Headers

Authorization Bearer \

Response Status

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

Response

  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 CTL

POST /api/v2/node/ctl

Request Headers

Content-Type application/json

Authorization Bearer \

Request Status

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

Response

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

Get Node State

GET /api/v2/node/state

Request Params

node_id required

Request Headers

Authorization Bearer \

Response Status

  • 200 OK

Response

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

Get Subscribe Group Config

GET /api/v2/subscribe

Request Params

node_id required

Request Headers

Authorization Bearer \

Response Status

  • 200
  • 400

Response

  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 Log

GET /api/v2/log

Request Params

since required, UTC timestamp

until required, UTC timestamp, with since forms the interval [since, until)

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

page required

page_size required, should be in range [200, 10000]

Request Headers

Authorization Bearer \

Response Status

  • 200
  • 400
    • 1003 param is wrong

Response

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