跳到主要内容

设备接入

接口简述

通过 Janus HTTP API 设置设备接入

请求地址

/api/device/connection

请求方式

POST

请求参数

序号名称必填描述
1token令牌 (token)
2uuid操作的设备序列号
3conn_type设置设备的接入方式

其中,设备接入方式 conn_type 可选的方式有以下几种:

序号类别描述额外参数
1triton设备作为triton接入
2mqtt_client设备作为Mqtt客户端接入
3modbus_slave设备作为Modbus Slave接入(1) modbus (表示Modbus协议,支持tcp和rtu协议;e.g:modbus=tcp)
(2) slave (表示Slave ID;e.g:slave=1)
(3) port (表示端口号;只有在 modbus=tcp 时可选填;e.g:port=502)
(4) time (表示定时读取的时间间隔;e.g:time=1000)
(5) timeUnit (表示定时读取的时间单位,可选msms;e.g:timeUnit=s)
(6) ip (IP地址,只有在 modbus=tcp 时可选填)
(7) modbus=rtu 时需要额外增加的参数:
<1> commPortId (表示串口号;e.g:commPortId=COM1)
<2> baudRate (表示波特率,可选300, 600, 1200, 2400, 4800, 9600, 19200, 38400, 76800, 153600;e.g:baudRate=9600);
<3> parity (表示校验位:0: NONE;1: ODD;2: EVEN;e.g:parity=2);
<4> dataBits (表示数据位,可选6, 7, 8;e.g:dataBits=8);
<5> stopBits (表示停止位,可选1, 2;e.g:stopBits=1);
(8) (可选项) 可传入的参数 row,表示数据读取配置,
area,数据区域:
<1> Read Coils(1);
<2> Read Discrete Inputs(2);
<3> Read Holding Registers(3);
<4> Read Input Registers(4);
start,读取位置-开始
end,读取位置-结束
e.g:row=[{"area":"3","start":"0","end":"1"}]
4modbus_master设备作为Modbus Master接入modbus_slave
5tcp_client设备作为TCP Socket客户端接入可选项:(1) hex (表示数据为16进制格式,eg: hex=true);(2) client_ip (TCP 客户端地址,表示Janus通过此IP自动关联数据至该设备)
6tcp_server设备作为TCP Server接入(1) ip (表示TCP Server IP),
(2) port (表示TCP Server Port);
(3) (可选项) timer_switch (是否定时发送数据到TCP Server)
如果timer_switch=true, 则必须传入参数:
<1> time (表示定时读取的时间间隔;e.g:time=1000)
<2> timeUnit (表示定时读取的时间单位,可选msms;e.g:timeUnit=s)
<3> radix16 (表示是否16进制格式;e.g:radix16=true)
(4) (可选项) timer_data (表示要发送的数据,划分多组数据;e.g:timer_data=1\n2\n3)
7udp_client设备作为UDP Socket客户端接入可选项: (1) hex (表示数据为16进制格式,eg: hex=true);(2) client_ip (UDP客户端IP地址,表示Janus通过此IP自动关联数据至该设备)
8udp_server设备作为UDP Server接入(1) ip (表示UDP Server IP),
(2) port (表示UDP Server Port);
(3) (可选项) timer_switch (是否定时发送数据到UDP Server)
如果timer_switch=true, 则必须传入参数:
<1> time (表示定时读取的时间间隔;e.g:time=1000)
<2> timeUnit (表示定时读取的时间单位,可选msms;e.g:timeUnit=s)
<3> radix16 (表示是否16进制格式;e.g:radix16=true)
(4) (可选项) timer_data (表示要发送的数据,划分多组数据;e.g:timer_data=1\n2\n3)
9serial_port设备作为串口接入(1) commPortId (表示串口号;e.g:commPortId=COM1),
(2) baudRate (表示波特率,可选300, 600, 1200, 2400, 4800, 9600, 19200, 38400, 76800, 153600;e.g:baudRate=9600)
(3) parity (表示校验位:0: NONE;1: ODD;2: EVEN;e.g:parity=2)
(4) dataBits (表示数据位,可选6, 7, 8;e.g:dataBits=8)
(5) stopBits (表示停止位,可选1, 2;e.g:stopBits=1),
(6) time (表示定时读取的时间间隔;e.g:time=1000),
(7) timeUnit (表示定时读取的时间单位,可选msms;e.g:timeUnit=s),
(8) receive_type (表示接收数据格式,可选asciihex;e.g:receive_type=ascii)
(9) send_type (表示发送数据格式,可选 asciihex;e.g:send_type=ascii);
(10) (可选项) timer_data (表示要发送的数据,\n划分多组数据;e.g:timer_data=1\n2\n3)
10http_rest设备使用HTTP发送数据到Janus

请求示例

    // 使用jQuery AJax作为请求提交工具
$.ajax({
type: "post",
url: "http://127.0.0.1/api/device/connection",
dataType: "json",
data: {
token: "BE60-E612-A5DD-CBA9",
uuid: "850E-1861-CA70-8319",
conn_type: "triton"
}
});

返回值说明

返回值格式为JSON

序号名称描述
1code请求状态:
200 = 请求成功;
401 = Token授权失败;
1002 = 参数不正确;
1003 = 设备不存在;
1004 = 时间格式不正确;
2message请求状态描述

返回值示例

{
"code": 200,
"message": "成功"
}