This file provides guidance to Claude Code (claude.ai/code) when working with code in this repository.
Python library for interfacing with Mendi fNIRS devices via Bluetooth Low Energy. Successfully reverse-engineered the proprietary BLE protocol to enable direct device communication.
Repository: https://github.com/BioMycoBit/mendi-ble-python
Author: Brandon Taylor
- Service UUID:
fc3eabb0-c6c4-49e6-922a-6e551c455af5 - Data Characteristic:
fc3eabb5-c6c4-49e6-922a-6e551c455af5 - Streaming Method: Request-response via descriptor writes (not standard BLE streaming)
- Packet Format: 9 bytes, protobuf-like encoding
- Optimal Timing: 2-second intervals between descriptor writes
Position: 0 1 2 3 4 5 6 7 8
Value: 0a 03 08 XX 1d 10 01 18 01
^^
Sensor value (varies with brain activity)
- Use type hints for all functions
- Follow PEP 8 conventions
- Max line length: 88 (black default)
- Use dataclasses for data models
- NO COMMENTS unless specifically requested
- Run tests before committing:
pytest tests/ -v - Format code:
black src/ tests/ examples/ - Type check:
mypy src/
- Windows: Full BLE functionality, all testing happens here
- WSL: Development only (no Bluetooth access)
- macOS/Linux: Should work but primary testing is Windows
mendi-ble-python/
├── src/mendi_ble/ # Library source code
│ ├── __init__.py # Public API exports
│ ├── client.py # Low-level BLE client
│ ├── stream.py # High-level streaming API
│ ├── scanner.py # Device discovery
│ ├── parser.py # Packet parsing
│ ├── models.py # Data models
│ ├── scoring.py # Activity scoring engine
│ └── visualization_plotly.py # Browser-based visualization
├── examples/ # Usage examples
│ └── visualization_example.py
├── tests/ # Test suite
├── docs/ # Documentation
│ ├── REVERSE_ENGINEERING_OVERVIEW.md
│ ├── DEVICE_PROFILE.md
│ ├── BLE_DEVICE_CRASH_RECOVERY.md
│ └── API_USAGE.md
└── requirements.txt # Dependencies
✅ Completed:
- BLE protocol reverse engineering
- Device discovery and connection
- Real-time data streaming
- Packet parsing (protobuf-like format)
- Browser-based visualization (Plotly)
- Reconnection handling
- Scoring engine with presets
- Create feature branch
- Implement in appropriate module
- Add tests
- Update documentation
- Test with real device (Windows only)
- Device must be on (blue LED)
- Windows Bluetooth must be enabled
- May need to pair device first via Windows settings
- Check Device Manager for adapter status
# Windows PowerShell
cd C:\repos\mendi-ble-python
.\venv\Scripts\activate
python examples\visualization_example.py
# With simulated data (no device needed)
python examples\visualization_example.py --simulate- No Button Required: Device starts streaming automatically after BLE initialization
- Descriptor Writes: Data packets triggered by writing
b'\x01\x00'to CCCD handle 29 - Reconnection: Device may maintain phantom connection, requiring special handling
- Cross-Platform: Primary development/testing on Windows due to BLE requirements
- Ensure device is on (blue LED)
- Check Windows Bluetooth settings
- Try closer proximity to adapter
- Device MAC:
C3:DF:6C:5E:82:9E(primary device)
- Verify descriptor write implementation
- Check 2-second timing between writes
- Ensure notifications enabled on fc3eabb5
- Install in development mode:
pip install -e . - Check virtual environment is activated
- Verify all dependencies installed
- Test with Real Device: All changes must be tested with actual Mendi hardware
- Document Protocol Findings: Any new protocol discoveries should be documented
- Maintain Compatibility: Don't break existing API without version bump
- Cross-Platform: Consider Windows/Mac/Linux compatibility
MIT License - Copyright (c) 2025 Brandon Taylor
Unofficial library developed through reverse engineering. Not affiliated with Mendi.io.