RepositoryC++
yoziru

yoziru/tesla-ble

C++ library to communicate directly with Tesla vehicles over the BLE API

60stars
29forks
1issues
4views

Featured achievements

The project's latest awards

1
TINIX TRENDING·Topic: teslamotors

#1 Repository of the week

2
TINIX TRENDING·Topic: tesla-ble

#2 Repository of the week

3
TINIX TRENDING·Topic: tesla-api

#3 Repository of the week

TeslaBLE - A C++ library for communicating with Tesla vehicles over BLE

This library is designed to communicate with Tesla vehicles locally via the BLE API. It follows the same principles as the official Tesla vehicle-command library (Golang), and is intended for use in embedded systems.

It exists to:

  1. Provide a local and offline alternative to the official Tesla API.
  2. Avoid the rate limits of the official Tesla API.

The main purpose of this library is to locally manage charging of the vehicle to enable use cases such as charging during off-peak hours, or to manage charging based on solar production. It is not intended to replace the official Tesla API for all use cases.

Usage

This project is intended to be used as a library in your own project. It is not a standalone application.

yoziru/esphome-tesla-ble is an ESPHome project that uses this library to control your Tesla vehicle charging.

Several examples are included for your convenience.

cd examples/simple/
cmake .
make

Building and Testing

Quick Start

# Clone the repository
git clone https://github.com/yoziru/tesla-ble.git
cd tesla-ble

# Setup development environment (optional but recommended)
./scripts/setup_dev_environment.sh

# Build the project
cmake -B build
cmake --build build

# Run tests
./scripts/run_tests.sh

Manual Build

# Configure with CMake
cmake -B build -DCMAKE_BUILD_TYPE=Release

# Build the library and tests
cmake --build build --config Release

# Run tests with CTest
cd build
ctest --build-config Release --output-on-failure

Running Tests

Using the Test Runner Script

The repository includes a comprehensive test runner script with various options:

# Run tests in Debug mode (default)
./scripts/run_tests.sh

# Run tests in Release mode
./scripts/run_tests.sh --release

# Run tests with coverage analysis
./scripts/run_tests.sh --coverage

# Run tests with Valgrind (Linux only)
./scripts/run_tests.sh --valgrind

# Clean build and run tests
./scripts/run_tests.sh --clean

# Get help on available options
./scripts/run_tests.sh --help

Manual Test Execution

# Build and run all Tesla BLE tests (excludes dependency tests)
cd build
ctest --output-on-failure --verbose

# Run specific test suites
./tests/test_client
./tests/test_key_generation
./tests/test_message_building
./tests/test_message_parsing
./tests/test_session_management
./tests/test_protocol_compliance
./tests/test_utils

# Run the complete test suite
./tests/tesla_ble_tests

Test Coverage

To generate a coverage report:

# Install coverage tools (Ubuntu/Debian)
sudo apt-get install lcov

# Run tests with coverage
./scripts/run_tests.sh --coverage

# Coverage report will be generated in build/coverage_html/

Static Analysis

The project includes static analysis via cppcheck:

# Install cppcheck
sudo apt-get install cppcheck  # Ubuntu/Debian
brew install cppcheck          # macOS

# Run static analysis
cppcheck --enable=all --inconclusive \
    --suppress=missingIncludeSystem \
    --suppress=unusedFunction \
    src/ include/ examples/

Code Formatting and Linting

The project uses clang-format for code formatting and clang-tidy for static analysis:

# Install clang tools
sudo apt-get install clang-format clang-tidy  # Ubuntu/Debian
brew install clang-format clang-tidy          # macOS

# Run formatting and linting checks (will configure CMake if needed)
./scripts/lint.sh

# Or run individually:
# Format code
find src include tests examples -name "*.cpp" -o -name "*.h" | xargs clang-format -i

# Check formatting
find src include tests examples -name "*.cpp" -o -name "*.h" | xargs clang-format --dry-run --Werror --style=file

# Run clang-tidy on source files (requires compile_commands.json)
find src -name "*.cpp" | xargs clang-tidy

Development Environment Setup

Use the provided script to set up your development environment:

./scripts/setup_dev_environment.sh

This script will:

  • Detect your operating system
  • Install required dependencies (cmake, compiler, etc.)
  • Install optional development tools (lcov, cppcheck, valgrind)
  • Set up git hooks for automatic testing

Continuous Integration

The project uses GitHub Actions for CI/CD with the following features:

  • Cross-platform testing: Ubuntu, Windows, macOS
  • Multiple build types: Debug and Release
  • Code coverage: Automatic coverage reporting to Codecov
  • Static analysis: cppcheck integration
  • Memory testing: Valgrind and AddressSanitizer
  • Performance testing: Various sanitizers (address, undefined, thread)

Test Structure

The test suite is organized into several categories:

  • test_client.cpp: Core client functionality and initialization
  • test_key_generation.cpp: Private key generation and loading
  • test_message_building.cpp: Message construction for various commands
  • test_message_parsing.cpp: Parsing of received messages
  • test_session_management.cpp: Session handling and peer management
  • test_utils.cpp: Utility functions and helper methods
  • test_vehicle.cpp: Vehicle state management and command processing
  • test_exponential_backoff.cpp: Exponential backoff retry logic

Each test file contains comprehensive unit tests covering both success and failure scenarios, edge cases, and parameter validation.

State Architecture

The library uses a unified state pattern for command processing with the following states:

  • IDLE: Initial state for new commands
  • AUTHENTICATING: Unified authentication initiation (replaces legacy domain-specific states)
  • AUTH_RESPONSE_WAITING: Unified authentication response waiting
  • READY: Command ready to be sent
  • WAITING_FOR_RESPONSE: Waiting for command response
  • COMPLETED: Command completed successfully
  • FAILED: Command failed

This architecture provides a clean, maintainable approach to command lifecycle management with exponential backoff for retries.

Dependencies

  • nanopb
  • mbedtls 3.x
    • NOTE: ESP-IDF <=4.4 includes mbedtls 2.x, and is not compatible with this library. You will need to use at least ESP-IDF 5.0.

Features

  • Implements Tesla's BLE protocol
  • AES-GCM key generation
  • Metadata serialization
  • Supports UniversalMessage.RoutableMessage encoding and decoding
    • Supports Vehicle Security (VSSEC) payload
    • Supports Infotainment payload

Credits

This fork builds on the original version by pmdroid.

IMPORTANT

Please take note that this library does not have official backing from Tesla, and its operational capabilities may be discontinued without prior notice. It's essential to recognize that this library retains private keys and other sensitive data on your device without encryption. I would like to stress that I assume no liability for any possible (although highly unlikely) harm that may befall your vehicle.

Similar Projects

Discover other similar projects and AI models.

RepositoryC++
yoziru/esphome-tesla-ble

Interact with Tesla vehicles over BLE using ESPHome and Home Assistant

373
Dec 1, 2026
RepositoryElixir
teslamate-org/teslamate

A self-hosted data logger for your Tesla 🚘 [main maintainer=@JakobLichterfeld]

9.3k
Dec 1, 2026
RepositoryC#
bassmaster187/TeslaLogger

TeslaLogger is a self hosted data logger for your Tesla Model S/3/X/Y. Actually it supports RaspberryPi 3B, 3B+, 4B, Docker and Synology NAS.

649
Nov 30, 2026
RepositoryJavaScript
jasonacox/pypowerwall

Python API for Tesla Powerwall and Solar Power Data

238
Nov 28, 2026
RepositoryQML
Omardigio/VoltaOS

Volta OS: in-car infotainment interface for Linux (Qt 6 / QML, Wayland compositor). Beta.

235
Nov 12, 2026
RepositoryJavaScript
geraldoramos/nikola

⚡Unofficial cross-platform desktop app to monitor and control Tesla vehicles, powered by Electron & React

156
Apr 29, 2024
RepositoryPython
cobanov/teslamate-mcp

A Model Context Protocol (MCP) server that provides access to your TeslaMate database, allowing AI assistants to query Tesla vehicle data and analytics.

142
Nov 14, 2026
RepositoryJava
pccr10001/TeslaWearKey

Tesla Key Card for NFC-enabled Android Wear watches

125
Jul 22, 2025
RepositoryJavaScript
milesburton/teslacam

Tesla Dash Cam Footage Management System | Automate video backup, cloud storage, and remote access for Tesla's built-in dash cam using a Raspberry Pi Zero W.

105
Nov 27, 2026