跳转至

03. 设备与配置

1. 设备动态码绑定(公开 + JWT)

POST /api/device/pre-check(公开)

请求:

{
  "mac": "AA:BB:CC:DD:EE:FF",
  "username": "alice",
  "device_password": "Ab12Cd34"
}

返回(已认证):

{ "code": 200, "data": { "status": "authenticated", "call_sign": "BG7XXX" } }

返回(需绑定):

{ "code": 200, "data": { "status": "need_bind", "message": "请使用动态码绑定设备" } }

POST /api/device/request-code(公开)

请求:

{ "mac": "AA:BB:CC:DD:EE:FF" }

返回:

{ "code": 200, "data": { "dynamic_code": "735921", "expires_in": 60 } }

POST /api/device/confirm-bind(公开)

请求:

{ "mac": "AA:BB:CC:DD:EE:FF" }

返回(等待中):

{ "code": 200, "data": { "status": "waiting", "message": "等待用户完成绑定" } }

返回(已就绪):

{
  "code": 200,
  "data": {
    "status": "ready",
    "username": "alice",
    "device_password": "Ab12Cd34",
    "ssid": 11,
    "dmr_id": 4601234
  }
}

POST /api/device/bind(JWT)

请求:

{ "dynamic_code": "735921" }

返回:

{ "code": 200, "data": { "device_mac": "AA:BB:CC:DD:EE:FF", "call_sign": "BG7XXX", "message": "绑定成功,请配置设备参数" } }

POST /api/device/submit-config(JWT)

请求:

{ "device_mac": "AA:BB:CC:DD:EE:FF", "ssid": 11 }

返回:

{
  "code": 200,
  "data": {
    "message": "配置已保存",
    "udp_auth_info": {
      "username": "alice",
      "device_password": "Ab12Cd34"
    },
    "dmr_id": 4601234
  }
}

2. 用户设备密码(JWT)

GET /api/user/device-password

PUT /api/user/device-password

请求:

{ "new_password": "Ab12Cd34" }

POST /api/user/device-password/regenerate

返回示例:

{ "code": 200, "message": "设备密码已重新生成", "data": { "device_password": "Xy98Lm12" } }

3. 设备管理(JWT + Approved)

说明:设备收发控制仅设备级生效,统一通过 PUT /api/devices/:iddisable_send / disable_recv 字段更新。

GET /api/devices

参数:pagelimitcallsigngroup_id

返回项补充: - last_online_ip:设备最近一次上线客户端 IP - last_online_ip_location:根据 IP 计算的归属地(实时计算)

GET /api/devices/list(兼容旧路径)

GET /api/device/get?id=123

GET /api/device/qth?id=123(兼容)

GET /api/device/qths

返回:设备位置列表。

PUT /api/devices/:id

请求示例:

{
  "name": "My ESP32",
  "group_id": 1001,
  "status": 1,
  "priority": 100,
  "note": "备用机",
  "disable_send": false,
  "disable_recv": false
}

DELETE /api/devices/:id

POST /api/device/changegroup

PUT /api/devices/:id/group

请求体(以 body device_id 为准):

{
  "device_id": 123,
  "group_id": 1002,
  "password": "private_group_pwd"
}

说明:私有群组且用户未验证时,需要 password

4. 设备配置同步(UDP 普通设备)

GET /api/devices/:id/config

PUT /api/devices/:id/config

请求示例:

{
  "rx_freq": "439500000",
  "tx_freq": "431500000",
  "rx_ctcss": "88.5",
  "tx_ctcss": "88.5",
  "sql_level": "4",
  "power_level": "2",
  "tx_bandwidth": "1"
}

POST /api/devices/:id/config/sync

返回示例:

{ "code": 200, "message": "配置已发送到设备" }

离线时:

{ "code": 200, "message": "设备离线,配置将在设备上线时自动同步" }

5. 管理员设备配置(Admin)

  • GET /api/admin/devices/:id/config
  • PUT /api/admin/devices/:id/config
  • POST /api/admin/devices/:id/config/sync

与前台配置接口字段一致,但无设备归属限制。

6. 设备 AT/参数接口(JWT + Approved,历史业务码)

  • POST /api/device/at
  • POST /api/device/query
  • POST /api/device/change
  • POST /api/device/change1w
  • POST /api/device/change2w

示例(/api/device/at):

{
  "callsign": "BG7XXX",
  "ssid": 11,
  "type": 1,
  "atcommand": "AT+VERSION?"
}

返回示例:

{
  "code": 20000,
  "data": {
    "message": "AT命令执行成功",
    "items": { "callsign": "BG7XXX", "ssid": 11, "version": "DraARL AT V1.0" }
  }
}