# mystackchan **Repository Path**: nanze/mystackchan ## Basic Information - **Project Name**: mystackchan - **Description**: No description available - **Primary Language**: Unknown - **License**: Not specified - **Default Branch**: main - **Homepage**: None - **GVP Project**: No ## Statistics - **Stars**: 0 - **Forks**: 0 - **Created**: 2026-11-13 - **Last Updated**: 2026-11-13 ## Categories & Tags **Categories**: Uncategorized **Tags**: None ## README # StackChan Voice Assistant ESP-IDF 5.4 C++ firmware for M5Stack CoreS3 / CoreS3 SE. Say **“你好小智”** to wake the local ESP-SR WakeNet9 model. The 12-LED WS2812C ring in the StackChan body and the LCD network badge are yellow while connecting, blue when connected and red after a connection timeout. The LEDs are driven through the body PY32L020 I2C expander (address `0x6F`), not directly from an ESP32 GPIO (see the [StackChan hardware documentation](https://docs.m5stack.com/en/StackChan) and [official BSP](https://github.com/m5stack/StackChan-BSP)). After the wake word, the ring blinks blue while listening; it turns green while the touchscreen recording button is held. The firmware sends each recorded WAV clip through the existing OpenClaw Gateway WSS connection; the Gateway handles speech recognition and chat, and the firmware uses MiniMax T2A to play the reply through the onboard speaker. If no speech is detected within 6 seconds after wake, listening is cancelled. A 1.2-second pause ends a spoken question. Use the bottom touchscreen controls to hold **按住说话** while recording, hold **配网 3秒** for three seconds to start the captive portal, or hold **清除 5秒** for five seconds to erase saved Wi-Fi profiles. Physical BtnA/BtnB GPIOs are not used on CoreS3. ## Configure 1. Wi-Fi credentials are managed as up to eight profiles by `esp_wifi_service`. On startup the selector scans and chooses a suitable saved 2.4 GHz network, reconnects after disconnects, and switches to another saved profile when needed. 2. Hold **配网 3秒** on the touchscreen. Scan the QR code to join the temporary `StackChan-XXXXXX` SoftAP, then open `http://192.168.4.1` if the captive portal does not open automatically. Enter the Wi-Fi SSID and password. Credentials are committed only after the Wi-Fi connection succeeds; the SoftAP is stopped after success or after 120 seconds. 3. The MiniMax API key is hard-coded as the `kMiniMaxApiKey` constant in [main/config_store.hpp](./main/config_store.hpp). Update and rebuild before flashing. Wi-Fi profiles use the default NVS partition with ESP-IDF NVS encryption enabled. This configuration selects the HMAC key protection scheme and eFuse key ID 5. On first NVS initialization, ESP-IDF generates and irreversibly writes an HMAC key to that eFuse block unless a suitable key is already present. Confirm that key block 5 is available and reserved for NVS before booting a device with this configuration. The `nvs_keys` partition is not used by the selected HMAC scheme. For physical protection of other flash contents, enable ESP-IDF flash encryption separately; that can also irreversibly change eFuses, so follow Espressif's production provisioning procedure before enabling it on a device. 4. Check the MiniMax account region and API permissions. The API host is `https://api.minimax.cn`; the API key must belong to the matching region. 5. The project pins M5Unified 0.2.25, M5GFX 0.2.32, cJSON 1.7.19~2 and `espressif/esp_wifi_service` ^0.5.3 in `main/idf_component.yml`. Local component source directories, when present, are used by ESP-IDF instead of downloading the M5Stack packages. 6. The project defaults enable 16 MB flash, quad PSRAM and the full TLS certificate bundle for CoreS3. If `sdkconfig` already exists, review and apply the corresponding entries from `sdkconfig.defaults` in `idf.py menuconfig`; defaults do not replace existing sdkconfig selections. The custom [`partitions.csv`](./partitions.csv) includes encrypted NVS key storage, reserves 6 MB for ESP-SR models and provides a 0x300000-byte app partition. ## Build, flash and test Run these commands from the project directory in an ESP-IDF terminal: ```sh idf.py set-target esp32s3 idf.py menuconfig idf.py reconfigure idf.py build idf.py -p /dev/ttyACM0 -b 1500000 flash idf.py -p /dev/ttyACM0 -b 1500000 monitor ``` In `menuconfig`, verify: - `Serial flasher config` → `Flash size` is **16 MB**. - `Partition Table` → **Custom partition table CSV** with `partitions.csv`. - `Component config` → `ESP PSRAM` → support is enabled, mode is **Quad**, and allocation through `malloc()` is enabled. - `Component config` → `mbedTLS` → certificate bundle and the full default certificate bundle are enabled. - `Component config` → `ESP System Settings` → main task stack is **16384 bytes**. - `Component config` → `NVS` → NVS encryption is enabled and HMAC key ID is 5. - `ESP-Service` → MCP support and the Wi-Fi service MCP tools are enabled. This project exposes the Wi-Fi MCP tools over UART1 (GPIO6 TX, GPIO5 RX, 115200 baud). The earlier GPIO17/GPIO18 pins are not used because the M5Stack CoreS3 already wires those pads to Serial2 for the StackChan base/expansion bus; reusing them would collide with M5Unified's Serial2 traffic. The MCP `prov_start` tool is registered alongside `prov_stop`, `request_connect`, and `request_reeval`, so any host that dials in can reopen the SoftAP. Disable `WIFI_SERVICE_MCP_ENABLE` in menuconfig if you do not want that surface. MCP is not exposed over the unauthenticated provisioning SoftAP. - `Wi-Fi Service` → HTTP provisioning is enabled and the built-in web UI is disabled because the firmware supplies its own Wi-Fi/API-key form. Optional flash encryption is configured separately under `Security features` in menuconfig. It is not auto-enabled by the project because device flash encryption changes eFuse state; use Espressif's deployment procedure before turning it on for hardware. At runtime, confirm that the RGB ring and LCD network badge change from yellow to blue. Hold the bottom-center **按住说话** button while speaking and release it (the ring turns green), or say “你好小智” and speak while the ring blinks blue. Hold **配网 3秒** to verify the QR/captive-portal flow and hold **清除 5秒** to clear saved Wi-Fi profiles. Check the recognized question, generated answer and speaker playback. Use the full `idf.py flash` command (not `app-flash`) to program the firmware, ESP-SR model partition, and the local Chinese TTS voice-data partition. The firmware limits a recording to 12 seconds with PSRAM enabled (4 seconds otherwise). Network and MiniMax errors are logged and shown on the display. Any `...` sections in MiniMax replies are removed before display and speech synthesis. Speaker master and channel volumes are set to maximum. Wake-word acknowledgements (“我在!”) are synthesized locally with the ESP-SR Chinese TTS model and do not require network access. The xiaole voice data is stored in the dedicated `tts_voice` flash partition and is included when using the full flash target. The head touch sensor (LTR-507 / Si12T at I2C address `0x68`) shares the CoreS3 internal I2C bus (GPIO11 = SCL, GPIO12 = SDA) with the body expander, so it is driven through `M5.In_I2C` rather than a separate I2C controller. Double-tap the head within 450 ms to make the robot shake its head. The driver only reports a double tap when the *same* electrode fires twice, so a swipe across the three electrodes is not mistaken for a double tap. ## Voice request flow - Speech input: mono 16 kHz PCM is wrapped in a WAV header, Base64-encoded in bounded chunks, and sent as a `chat.send` audio attachment over WSS. The firmware subscribes to its per-device session before sending; it re-subscribes after a Gateway reconnect. - Speech recognition and chat: handled by the configured OpenClaw Gateway media-understanding pipeline. - Speech output: `POST /v1/t2a_v2`, model `speech-2.8-turbo`, mono PCM at 32 kHz, played through the existing onboard PCM path. See the [MiniMax Text-to-Speech](https://platform.minimax.io/docs/api-reference/speech-t2a-http.md) documentation for account access and supported voice IDs.