13 Commits

Author SHA1 Message Date
ab699bbca3 Add HFP (Hands-Free Profile) support
Implement HFP client (Hands-Free Unit role) for the ESP32 test harness:

Firmware:
- bt_hfp.c/h: Full HFP client with call control, audio, volume, DTMF,
  voice recognition
- Enable HFP in sdkconfig.defaults with Wide Band Speech support
- Add HFP commands/events to protocol.h and cmd_dispatcher.c

Python MCP tools:
- 15 new tools: enable, connect, audio_connect, answer, reject, dial,
  send_dtmf, volume, voice_recognition_start/stop, query_calls, status
- Full protocol constants in protocol.py

Tested: HFP enable returns role='hands_free_unit', ready for AG pairing
2026-02-03 14:34:13 -07:00
9a8eae1d2f Add HID (Human Interface Device) profile support
Implements Classic Bluetooth HID Device profile for keyboard/mouse emulation:

Firmware:
- bt_hid.c/h: HID device driver with combo keyboard/mouse HID descriptor
- cmd_hid_{enable,disable,connect,disconnect}: HID lifecycle management
- cmd_hid_send_keyboard: Send keyboard reports (modifier + up to 6 keys)
- cmd_hid_send_mouse: Send mouse reports (buttons + relative X/Y)
- cmd_hid_status: Query HID state (enabled, registered, connected)

Python MCP tools:
- esp32_hid_enable/disable: Control HID device mode
- esp32_hid_connect/disconnect: Manage HID host connections
- esp32_hid_send_keyboard/send_mouse: Send HID reports
- esp32_hid_status: Get connection state

Config:
- Enable BT_HID_ENABLED + BT_HID_DEVICE_ENABLED in sdkconfig.defaults
- Add bt_hid.c to CMakeLists.txt

Tested E2E: Linux (hci1) connects to ESP32 HID device, keyboard and
mouse reports sent successfully.
2026-02-03 14:07:35 -07:00
61da375a0c Add SPP (Serial Port Profile) support for bidirectional data transfer
Firmware:
- Add spp_connect, spp_disconnect, spp_data events
- Add spp_send, spp_disconnect, spp_status commands
- Track remote address for connected SPP peer
- Report received data as hex + optional text decode

Python MCP:
- esp32_spp_send(data/data_hex) - send text or binary
- esp32_spp_disconnect() - close SPP connection
- esp32_spp_status() - query connection state

Tested: Linux rfcomm connect → ESP32, bidirectional data transfer works
2026-02-03 13:39:17 -07:00
5dcacc23ab Add comprehensive README with ESP32 capabilities and E2E testing guide
- Project overview and architecture diagram
- ESP32 hardware requirements and capabilities
- Full MCP tool reference (connection, classic BT, BLE/GATT, events)
- Quick start guide and Claude Code integration
- E2E testing instructions with latest results (v5: 76/76 PASS)
- Links to detailed documentation
2026-02-03 12:11:11 -07:00
88d006e9c4 Add automated E2E testing documentation and test prompts
- docs/automated-e2e-testing.md: Guide for running headless Claude CLI
  tests with both mcbluetooth and mcbluetooth-esp32 MCP servers
- tests/prompts/test-prompt-v4.md: 71-test suite covering Classic BT,
  BLE GATT, HCI capture, device management
- tests/prompts/test-prompt-v5.md: 76-test suite adding Battery Service
  (0x180F) and bt_ble_battery verification

Test results from v4: 71/71 PASS with 143 HCI packets captured
2026-02-03 11:18:37 -07:00
5a853c15fc Fix event system init and add SSP auto-accept for E2E testing
Two fixes for the E2E test failures:

1. event_reporter_init() was never called in app_main(), so the
   FreeRTOS queue and reporter task were never created. Every BT
   event (pair_request, gatt_read, gatt_write, gatt_subscribe)
   was silently dropped at the NULL-queue guard.

2. SSP Numeric Comparison requires both sides to confirm, but
   bt_pair blocks until completion — creating a deadlock since
   the LLM can't send classic_pair_respond while waiting. Added
   auto_accept flag to set_ssp_mode that auto-confirms numeric
   comparison requests in the GAP callback.
2026-02-02 21:05:28 -07:00
397b164eee Add ready probe to esp32_connect for reliable startup
The boot event fires early in app_main before the UART command
handler task is fully initialised. This means the first command
after connect can get lost, causing transient ping timeouts.

Now esp32_connect retries a ping (up to 5 attempts, 1s timeout
each) after the boot-event wait, so it only returns "connected"
when the firmware is actually responsive.
2026-02-02 19:45:01 -07:00
82cd0e5c9d Fix Response.data normalisation in parse_message() too
The previous commit only fixed Response.from_json(), but the serial
client's read loop uses parse_message() which constructs Response
directly. Apply the same string-to-dict normalisation there.
2026-02-02 15:58:20 -07:00
ea22f2f9db Fix async/await bugs found by headless E2E test
- Make get_client() sync (was async but did no async work). Callers
  that omitted await silently got a coroutine object instead of the
  SerialClient, causing "'coroutine' object has no attribute 'connect'"
  errors on every tool call.

- Fix esp32_connect: use get_client_or_none() for init check and
  client.event_queue.wait_for() for boot event (wait_event() didn't
  exist on SerialClient).

- Normalise Response.data to dict at parse time — firmware returns
  bare strings on some error paths, which broke .get() calls in tool
  error handlers.

- Remove stale await from ble.py (9 calls) and classic.py (4 calls).

Tested with dual-MCP headless claude session: 26/27 PASS.
2026-02-02 15:54:36 -07:00
0e7b8c2ef5 Fix docs to match UART0 firmware implementation
The firmware uses UART0 (via USB bridge) with ESP-IDF console disabled,
not UART1 on GPIO4/GPIO5 as originally documented. Updated both docs to
reflect the actual hardware-verified configuration:

- protocol-spec.md: UART peripheral description
- hardware-setup.md: wiring section, monitor section, sdkconfig table,
  troubleshooting steps
2026-02-02 15:38:20 -07:00
dc6078b296 Fix firmware for ESP-IDF v5.3 and hardware-verified operation
- Switch UART0 for protocol I/O (USB bridge), disable ESP-IDF console
- Wire all 21 command handlers into dispatch table (was only 4)
- Add configure command handler (name, io_cap, device_class)
- Add bt_classic_is_enabled()/bt_ble_is_enabled() for live status
- Fix cJSON_False misuse in get_status (type constant, not boolean)
- Fix esp_bt_gap_set_cod() to use esp_bt_cod_t bitfield struct
- Fix auth_cmpl.auth_mode → lk_type for ESP-IDF v5.3
- Replace deprecated esp_bt_dev_set_device_name with stack-specific API
- Remove unused bytes_to_hex, obsolete kconfig symbols
- Use large partition table (1.5MB) for dual-mode BT stack

Verified on ESP32-D0WD-V3 rev 3.1, /dev/ttyUSB4, all commands tested.
2026-02-02 15:30:54 -07:00
73d3d438a2 Expand test scenarios with step-by-step procedures
Rewrite test-scenarios.md with detailed per-step instructions
including exact tool calls, expected responses, negative test
cases, teardown procedures, and an environment variable reference.
2026-02-02 15:13:36 -07:00
6398a5223a ESP32 Bluetooth test harness MCP server
UART-controlled ESP32 peripheral for automated E2E Bluetooth testing.
Dual-mode (Classic BT + BLE) via Bluedroid on original ESP32.

Firmware (ESP-IDF v5.x, 2511 lines C):
- NDJSON protocol over UART1 (115200 baud)
- System commands: ping, reset, get_info, get_status
- Classic BT: GAP, SPP, all 4 SSP pairing modes
- BLE: GATTS, advertising, GATT service/characteristic management
- 6 device personas: headset, speaker, keyboard, sensor, phone, bare
- Event reporter: thread-safe async event queue to host

Python MCP server (FastMCP, 1626 lines):
- Async serial client with command/response correlation
- Event queue with wait_for pattern matching
- Tools: connection, configure, classic, ble, persona, events
- MCP resources: esp32://status, esp32://events, esp32://personas

Tests: 74 unit tests passing, 5 integration test stubs (skip without hardware)
2026-02-02 15:12:28 -07:00