设备接入
建立连接与握手
WebSocket 鉴权与 hello 握手报文。
文档中的域名示例请替换为实际环境;本地开发可在控制台文档页根据当前访问域名自动推断。
WebSocket 鉴权
# 推荐:URL 参数
wss://open.ailancun.com/ws?token=<jwt>
# 方式 2:握手 Header
Authorization: Bearer <jwt>
# 旧设备兼容:仅在网关显式启用无 JWT 模式时可用
wss://open.ailancun.com/ws?device_id=AA:BB:CC:DD:EE:FF&tenant_id=1客户端发送 hello
WebSocket 建连后,Gateway 主动发送服务端 hello。设备也可发送客户端 hello 上报自身信息。MQTT 客户端使用 OTA 下发的 endpoint、client_id、username、password 连接,按 publish_topic 和 subscribe_topic 收发控制消息。先订阅,再发送客户端 hello,等待服务端 hello 后建立 UDP 音频通道。
下面是 WebSocket 客户端示例。MQTT 客户端将 transport 填为 udp。扩展字段按实际设备能力填写。
{
"type": "hello",
"version": 1,
"transport": "websocket",
"uuid": "持久化唯一ID",
"device_model": "ESP32-S3-DevKitC-1",
"client_type": "esp32",
"firmware_version": "1.3.0",
"audio_params": { "format": "opus", "sample_rate": 16000, "channels": 1, "frame_duration": 60 },
"network": { "type": "wifi", "ssid": "MyWifi", "signal": -65 }
}服务端 hello
WebSocket 使用 transport: "websocket",音频直接走二进制帧。
{
"type": "hello",
"version": 1,
"session_id": "<session-id>",
"transport": "websocket",
"features": { "device_settings": true },
"audio_params": { "sample_rate": 24000, "frame_duration": 60 }
}MQTT 使用 transport: "udp",通过 udp 字段下发音频连接参数。
{
"type": "hello",
"version": 1,
"session_id": "<session-id>",
"features": { "device_settings": true },
"transport": "udp",
"audio_params": { "sample_rate": 24000, "frame_duration": 60 },
"udp": { "server": "1.2.3.4", "port": 5678, "key": "<aes128-hex>", "nonce": "<hex>" }
}遇到问题时,把 session_id 提供给技术支持可快速定位日志。也可在控制台「设备管理 → 实时联调」选中该设备,实时查看握手、音频上下行、识别、合成、动作下发的完整链路。