C.1 HTTP API

  • BASEURL: /api

C.1.1 登录

C.1.1.1 请求

  • Method: POST
  • URL: /user/login
  • Headers: Content-Type:application/json
  • Body:
{
    "username" : "admin",
    "password" : "password"
}

C.1.1.2 返回

  • 200
{
    "token": "uuid"
}
  • 400 请求参数错误
  • 410 密码错误

C.1.2 登出

C.1.2.1 请求

  • Method: DELETE
  • URL: /user/login
  • Headers: Content-Type:application/json JWT:{token}

C.1.2.2 返回

  • 204 OK
  • 401 未登录

C.1.3 获取用户信息

C.1.3.1 请求

  • Method: GET
  • URL: /user/info
  • Headers: Content-Type:application/json JWT:{token}

C.1.3.2 返回

  • 200
{
    "avatar":"",
    "name":"admin"
}
  • 401 未登录

C.1.4 修改密码

C.1.4.1 请求

  • Method: POST
  • URL: /user/change_password
  • Headers: Content-Type:application/json JWT:{token}
  • Body:
{
    "password" : "password",
    "password2" : "password2"
}

C.1.4.2 返回

  • 204 OK
  • 400 请求参数错误
  • 401 未登录
  • 410 密码错误

C.1.5 设备列表

C.1.5.1 请求

  • Method: GET
  • URL: /device
  • Headers: Content-Type:application/json

C.1.5.2 返回

  • 200
[
    {
        "baud": 9600,
        "data_bits": 8,
        "did": "FanucTest112",
        "enable": true,
        "id": 1,
        "interval": 1.0,
        "ip": "192.168.1.1",
        "items": [
            {
            "address": "",
            "address_type": "",
            "function_code": 3,
            "id": 1,
            "interval": 1,
            "item_name": "cnc_type",
            "size": 0,
            "sub_address": 0,
            "value_type": 1
            }
        ],
        "model": "all",
        "parity": "N",
        "port": 8193,
        "protocol": "fanuc",
        "serial": "/dev/ttyO2",
        "slave_id": 1,
        "stop_bits": 1,
        "type": "fanuc"
    }
]

C.1.6 添加设备

C.1.6.1 请求

  • Method: POST
  • URL: /device
  • Headers: Content-Type:application/json
  • Body:
{
    "baud": 9600,
    "data_bits": 8,
    "did": "FanucTest112",
    "enable": true,
    "interval": 1.0,
    "ip": "192.168.1.1",
    "items": [
        {
        "address": "",
        "address_type": "",
        "function_code": 3,
        "id": 1,
        "interval": 1,
        "item_name": "cnc_type",
        "size": 0,
        "sub_address": 0,
        "value_type": 1
        }
    ],
    "model": "all",
    "parity": "N",
    "port": 8193,
    "protocol": "fanuc",
    "serial": "/dev/ttyO2",
    "slave_id": 1,
    "stop_bits": 1,
    "type": "fanuc"
}

C.1.6.2 返回

  • 201 填加OK
  • 400 请求参数错误
  • 409 授权数量不匹配

C.1.7 获取单个设备

C.1.7.1 请求

  • Method: GET
  • URL: /device/{device_id}
  • Headers: Content-Type:application/json

C.1.7.2 返回

  • 200
{
    "baud": 9600,
    "data_bits": 8,
    "did": "FanucTest112",
    "enable": true,
    "id": 1,
    "interval": 1.0,
    "ip": "192.168.1.1",
    "items": [
        {
        "address": "",
        "address_type": "",
        "function_code": 3,
        "id": 1,
        "interval": 1,
        "item_name": "cnc_type",
        "size": 0,
        "sub_address": 0,
        "value_type": 1
        }
    ],
    "model": "all",
    "parity": "N",
    "port": 8193,
    "protocol": "fanuc",
    "serial": "/dev/ttyO2",
    "slave_id": 1,
    "stop_bits": 1,
    "type": "fanuc"
}
  • 404 未找到资源

C.1.8 修改设备

C.1.8.1 请求

  • Method: PUT
  • URL: /device/{device_id}
  • Headers: Content-Type:application/json
  • Body:
{
    "baud": 9600,
    "data_bits": 8,
    "did": "FanucTest112",
    "enable": true,
    "interval": 1.0,
    "ip": "192.168.1.1",
    "items": [
        {
        "address": "",
        "address_type": "",
        "function_code": 3,
        "id": 1,
        "interval": 1,
        "item_name": "cnc_type",
        "size": 0,
        "sub_address": 0,
        "value_type": 1
        }
    ],
    "model": "all",
    "parity": "N",
    "port": 8193,
    "protocol": "fanuc",
    "serial": "/dev/ttyO2",
    "slave_id": 1,
    "stop_bits": 1,
    "type": "fanuc"
}

C.1.8.2 返回

  • 204 OK
  • 400 请求参数错误
  • 409 授权数量不匹配
  • 404 未找到资源

C.1.9 删除设备

C.1.9.1 请求

  • Method: DELETE
  • URL: /device/{device_id}
  • Headers: Content-Type:application/json

C.1.9.2 返回

  • 204 OK
  • 404 未找到资源

C.1.10 获取设备采集数据

C.1.10.1 请求

  • Method: GET
  • URL: /device/{device_id}/info
  • Headers: Content-Type:application/json

C.1.10.2 返回

  • 200
{
    "cnc_respos": {
        "ts": 1566384648053,
        "value": [
            {
                "axis": "X",
                "value": 0.0
            },
            {
                "axis": "Y",
                "value": 0.0
            },
            {
                "axis": "Z",
                "value": 0.0
            }
        ]
    },
    "cnc_type": {
        "ts": 1566384649570,
        "value": "FANUC 0i MF"
    }
}
  • 404 未找到资源

C.1.11 通过设备名控制变量

C.1.11.1 请求

  • Method: PUT
  • URL: /device/{device_name}/control_by_name
  • Headers: Content-Type:application/json
  • Body:
{
    "key": "M100",
    "value": 1,
    "value_type": 1
}

C.1.11.2 返回

  • 204 OK
  • 400 请求参数错误
  • 409 失败
  • 404 未找到资源

C.1.12 通过设备ID控制变量

C.1.12.1 请求

  • Method: PUT
  • URL: /device/{device_id}/control_by_id
  • Headers: Content-Type:application/json
  • Body:
{
    "key": "M100",
    "value": 1,
    "value_type": 1
}

C.1.12.2 返回

  • 204 OK
  • 400 请求参数错误
  • 409 失败
  • 404 未找到资源

C.1.13 操作设备临时变量

C.1.13.1 请求

  • Method: PUT
  • URL: /device/{device_id}/temp_value
  • Headers: Content-Type:application/json
  • Body:
[
    {
        "key": "M100",
        "action": "get",
        "value": 111,
        "per": 1
    }
]
  • key是变量名称
  • action是操作方式,get,set,delete
  • value要写入的值,get,delete方法忽略
  • per指定要写入的区域,0 redis,1 sqlite redis变量重启失效,sqlite位持久保存

C.1.13.2 返回

  • 204 OK
  • 400 请求参数错误
  • 409 失败
  • 404 未找到资源