對應教材第 13 章。三家助理的喚醒與辨識在生態系側完成,STM32 只多一個 Gateway 任務,所有指令仍進同一條 g_cmd_q。

STM32 側

加入編譯:../common/src/*.c、../lab08_asr_module/asr_map.c、 gw_proto.c、app_main.c。CubeMX 需開 USART6(GW_UART,115200)。 若同時使用路徑 A 語音模組,把閘道改接 USART2 並調整 pin_map.h。

門的遠端控制由 APP_GW_ALLOW_DOOR 管制(預設 1,產品請改 0)。

協定單元測試(PC):

cd host_test
gcc -I../../common/include -I.. test_gw.c ../gw_proto.c -o test_gw && ./test_gw

ESP32 側(擇一燒錄)

草稿 生態系 程式庫
esp32/homespan_siri/ Siri/家庭 App HomeSpan
esp32/fauxmo_alexa/ Alexa(區網模擬) fauxmoESP
esp32/mqtt_uart_bridge/ Home Assistant(三家皆可) PubSubClient

接線:ESP32 GPIO16(RX2) ← STM32 USART6 TX、GPIO17(TX2) → STM32 USART6 RX、 共地。兩側皆 3.3V 邏輯,直連即可。

  • HomeSpan:首次啟動在序列埠按 W 設 Wi-Fi;家庭 App 掃碼或輸入 配對碼 111-22-333(請改掉)。
  • fauxmo:改 SSID 後對 Echo 說 "Alexa, discover devices"。裝置名用英文。
  • MQTT 橋 + homeassistant/configuration.yaml:HA 經 HomeKit Bridge 暴露 給 Siri;Alexa/Google 用 Nabu Casa 或自建 skill/action。

OK Google 的直連建議走 Matter,見 esp32/matter_bridge.md。

驗收

  1. 「嘿 Siri,打開客廳燈」→ 燈亮,VCP 印 src=gateway。
  2. VCP 打 xiao-ke、guan-deng → 燈滅,家庭 App 同步變關。
  3. "Alexa, set living room fan to fifty percent" → 風扇 50%。
  4. 拔 ESP32 → 本地口令照常;插回 5 秒內狀態恢復同步。
  5. -DAPP_GW_ALLOW_DOOR=0 → Siri 開門被拒,log 顯示 gw: door blocked。