Rdzleo f5a2777abf feat(rtc+ble): A+B+C 三件套 RTC 偶发连接失败修复 + BLE 配网 reboot 修复 (移植自 Baji)
============ 问题与修复 ============

### 问题 1: 配网模式按 BOOT 进入配网 → 设备 reboot
  日志:
    E BT_OSI: future_new unable to allocate memory for the semaphore.
    assert failed: future_ready future.c:64 (future != NULL)

  根因:
    BLE Bluedroid 协议栈初始化时, future_new 分配 semaphore 失败 → 后续 future_ready
    拿到 NULL → assert. 跟 Baji 的 vQueueDelete(NULL) 同性质 — DRAM 不足.
    Kapi 用 LVGL (~50-80 KB DRAM) + RTC SDK 静态 .bss (~30-50 KB),
    BLE Bluedroid stack 抢不到所需内存.

  修复 (sdkconfig):
    CONFIG_BT_ALLOCATION_FROM_SPIRAM_FIRST=y
    让 BLE Bluedroid 全局变量动态分配优先走 PSRAM, 释放 ~30 KB DRAM
    给 controller / GATT / WiFi 使用. 修复后 BLE 配网正常.

### A+B+C 三件套 (移植自 Baji commit 70f0cdd, 解决 RTC 偶发连接失败)

  [A] sdkconfig: CONFIG_LWIP_MAX_SOCKETS=10 → 20
    根治火山 RTC SDK 启动时 lwIP socket fd 不足触发 SocketConnection-Lite.c:191
    bind local ip failed → ICE 协商失败 → wait connect bits=0x0 超时.

  [B] application.h/cc + volc_rtc_protocol.h/cc: 失败 3 次后销毁 + 重建 engine
    新增 VolcRtcProtocol::ForceRebuildEngine() public 方法.
    application.cc 加 audio_channel_retry_count_ 重试计数,
    OpenAudioChannel 连续失败 3 次时调用 ForceRebuildEngine 清理 SDK 状态.
    应对 A 修复后仍可能出现的 SDK 内部状态污染 (ICE Agent 异常等).

  [C] volc_rtc_protocol.cc: DIAG_RTC_BIND_ENABLE 一键开关诊断埋点
    在 join_room 前/后 + ForceRebuildEngine 前/后打印 lwIP socket fd / heap /
    psram / WiFi rssi / errno, 偶发失败时直接定位根因.
    验证完成后改 0 关闭, 编译器消除 #if 块, 零运行时开销.

============ 文件改动 ============

  sdkconfig:
    +CONFIG_BT_ALLOCATION_FROM_SPIRAM_FIRST=y    (BLE 配网修复)
    +CONFIG_LWIP_MAX_SOCKETS=10 → 20             (方案 A)

  main/application.h:
    +int audio_channel_retry_count_ = 0;         (RTC 重试计数)

  main/application.cc:
    OpenAudioChannel 失败处加重试计数 + 连续失败 3 次调 ForceRebuildEngine,
    static_cast<VolcRtcProtocol*>(protocol_.get()) (ESP-IDF 默认 -fno-rtti).

  main/protocols/volc_rtc_protocol.h:
    +void ForceRebuildEngine() 声明.

  main/protocols/volc_rtc_protocol.cc:
    +DIAG_RTC_BIND_ENABLE 开关 + diag_count_used_sockets() 工具函数,
    +OpenAudioChannel Pre-Join / Post-Fail DIAG 埋点,
    +ForceRebuildEngine() 实现 (volc_rtc_stop + volc_rtc_destroy + 等 2 秒 + 触发重建).

============ 关联资源 ============
  Baji commit 70f0cdd: feat(rtc): 偶发连接失败完整修复 (A+B+C 三件套)
  Baji commit bffd316: feat(provisioning): BLE 配网完整修复
  全局 CLAUDE.md "BLE 配网 DRAM 紧张完整排查流程" 章节
  项目记忆 project_ble_provisioning_issues.md

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
2026-05-21 15:15:34 +08:00
2026-01-20 16:55:17 +08:00
2026-01-20 16:55:17 +08:00
2026-01-20 16:55:17 +08:00
2026-01-20 16:55:17 +08:00
2026-01-20 16:55:17 +08:00
2026-01-20 16:55:17 +08:00
2026-01-20 16:55:17 +08:00
2026-01-20 16:55:17 +08:00
2026-01-20 16:55:17 +08:00
2026-01-20 16:55:17 +08:00
2026-01-20 16:55:17 +08:00
2026-01-20 16:55:17 +08:00
2026-01-20 16:55:17 +08:00
2026-01-20 16:55:17 +08:00
2026-01-20 16:55:17 +08:00
2026-01-20 16:55:17 +08:00
2026-01-20 16:55:17 +08:00
2026-01-20 16:55:17 +08:00
2026-01-20 16:55:17 +08:00
2026-01-20 16:55:17 +08:00
2026-01-20 16:55:17 +08:00

XiaoZhi AI Chatbot

(中文 | English | 日本語)

Introduction

👉 Build your AI chat companion with ESP32+SenseVoice+Qwen72B!【bilibili】

👉 Equipping XiaoZhi with DeepSeek's smart brain【bilibili】

👉 Build your own AI companion, a beginner's guide【bilibili】

Project Purpose

This is an open-source project released under the MIT license, allowing anyone to use it freely, including for commercial purposes.

Through this project, we aim to help more people get started with AI hardware development and understand how to implement rapidly evolving large language models in actual hardware devices. Whether you're a student interested in AI or a developer exploring new technologies, this project offers valuable learning experiences.

Everyone is welcome to participate in the project's development and improvement. If you have any ideas or suggestions, please feel free to raise an Issue or join the chat group.

Learning & Discussion QQ Group: 376893254

Implemented Features

  • Wi-Fi / ML307 Cat.1 4G
  • BOOT button wake-up and interruption, supporting both click and long-press triggers
  • Offline voice wake-up ESP-SR
  • Streaming voice dialogue (WebSocket or UDP protocol)
  • Support for 5 languages: Mandarin, Cantonese, English, Japanese, Korean SenseVoice
  • Voice print recognition to identify who's calling AI's name 3D Speaker
  • Large model TTS (Volcano Engine or CosyVoice)
  • Large Language Models (Qwen, DeepSeek, Doubao)
  • Configurable prompts and voice tones (custom characters)
  • Short-term memory, self-summarizing after each conversation round
  • OLED / LCD display showing signal strength or conversation content
  • Support for LCD image expressions
  • Multi-language support (Chinese, English)

Hardware Section

Breadboard DIY Practice

See the Feishu document tutorial:

👉 XiaoZhi AI Chatbot Encyclopedia

Breadboard demonstration:

Breadboard Demo

Supported Open Source Hardware

Firmware Section

Flashing Without Development Environment

For beginners, it's recommended to first use the firmware that can be flashed without setting up a development environment.

The firmware connects to the official xiaozhi.me server by default. Currently, personal users can register an account to use the Qwen real-time model for free.

👉 Flash Firmware Guide (No IDF Environment)

Development Environment

  • Cursor or VSCode
  • Install ESP-IDF plugin, select SDK version 5.3 or above
  • Linux is preferred over Windows for faster compilation and fewer driver issues
  • Use Google C++ code style, ensure compliance when submitting code

Developer Documentation

AI Agent Configuration

If you already have a XiaoZhi AI chatbot device, you can configure it through the xiaozhi.me console.

👉 Backend Operation Tutorial (Old Interface)

Technical Principles and Private Deployment

👉 Detailed WebSocket Communication Protocol Documentation

For server deployment on personal computers, refer to another MIT-licensed project xiaozhi-esp32-server

Star History

Star History Chart
Description
Kapi_Rtc_toy 卡皮吧啦项目_火山RTC版本
Readme MIT 24 MiB
Languages
C++ 66.2%
C 27.3%
Python 5.9%
CMake 0.6%