Git Product home page Git Product logo

tesla-ble's Introduction

CPPTeslaBLE

This CPP library facilitates direct communication with Tesla vehicles via the BLE API. It offers fundamental features such as unlocking/locking, opening the trunk, and more. The library's capabilities are contingent on the range of actions implemented by Tesla, which is the only limitation at present.

Rationale behind the Library

In my current residence, the Tesla vehicle lacks access to the mobile network but is connected to Wi-Fi. I posited that the car would establish a Wi-Fi connection when it's active. While the conventional wake-up method relies on the mobile network, this option isn't viable in this scenario. Thus, I explored the possibility of using Bluetooth for this purpose, and it proved successful.

Usage

Several examples are included for your convenience.

cd examples/simple/ 
mkdir -p build/
cd build/
cmake ..
make

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.

tesla-ble's People

Contributors

pmdroid avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar

Watchers

 avatar

tesla-ble's Issues

Support for mbedtls v2.x

I'm trying to use your library in ESPHome, unfortunately, the mbedtls version included in the Espressif Arduino framework (/data/cache/platformio/packages/framework-arduinoespressif32/tools/sdk/esp32/include/mbedtls/mbedtls) seems to be 2.x, which is not compatible:

src/esphome/components/tesla_ble/client.cpp: In member function 'int TeslaBLE::Client::LoadPrivateKey(const uint8_t*, size_t)':
src/esphome/components/tesla_ble/client.cpp:92:65: error: too many arguments to function 'int mbedtls_pk_parse_key(mbedtls_pk_context*, const unsigned char*, size_t, const unsigned char*, size_t)'
       password, 0, mbedtls_ctr_drbg_random, &this->drbg_context_);
                                                                 ^
In file included from src/esphome/components/tesla_ble/client.h:10,
                 from src/esphome/components/tesla_ble/client.cpp:1:
/data/cache/platformio/packages/framework-arduinoespressif32/tools/sdk/esp32/include/mbedtls/mbedtls/include/mbedtls/pk.h:712:5: note: declared here
 int mbedtls_pk_parse_key( mbedtls_pk_context *ctx,
     ^~~~~~~~~~~~~~~~~~~~
src/esphome/components/tesla_ble/client.cpp: In member function 'int TeslaBLE::Client::GeneratePublicKey()':
src/esphome/components/tesla_ble/client.cpp:131:51: error: 'mbedtls_ecp_keypair' {aka 'struct mbedtls_ecp_keypair'} has no member named 'private_grp'
       &mbedtls_pk_ec(this->private_key_context_)->private_grp,
                                                   ^~~~~~~~~~~
src/esphome/components/tesla_ble/client.cpp:132:51: error: 'mbedtls_ecp_keypair' {aka 'struct mbedtls_ecp_keypair'} has no member named 'private_Q'
       &mbedtls_pk_ec(this->private_key_context_)->private_Q,
                                                   ^~~~~~~~~
src/esphome/components/tesla_ble/client.cpp: In member function 'int TeslaBLE::Client::GenerateKeyId()':
src/esphome/components/tesla_ble/client.cpp:153:54: error: void value not ignored as it ought to be
   int return_code = mbedtls_sha1_starts(&sha1_context);
                                                      ^
src/esphome/components/tesla_ble/client.cpp:160:59: error: void value not ignored as it ought to be
                                     this->public_key_size_);
                                                           ^
src/esphome/components/tesla_ble/client.cpp:167:58: error: void value not ignored as it ought to be
   return_code = mbedtls_sha1_finish(&sha1_context, buffer);
                                                          ^
src/esphome/components/tesla_ble/client.cpp: In member function 'int TeslaBLE::Client::LoadTeslaKey(const uint8_t*, size_t)':
src/esphome/components/tesla_ble/client.cpp:193:62: error: 'mbedtls_ecp_keypair' {aka 'struct mbedtls_ecp_keypair'} has no member named 'private_grp'
   int return_code = mbedtls_ecp_group_load(&this->tesla_key_.private_grp,
                                                              ^~~~~~~~~~~
src/esphome/components/tesla_ble/client.cpp:201:25: error: 'mbedtls_ecp_keypair' {aka 'struct mbedtls_ecp_keypair'} has no member named 'private_grp'
       &this->tesla_key_.private_grp, &this->tesla_key_.private_Q,
                         ^~~~~~~~~~~
src/esphome/components/tesla_ble/client.cpp:201:56: error: 'mbedtls_ecp_keypair' {aka 'struct mbedtls_ecp_keypair'} has no member named 'private_Q'
       &this->tesla_key_.private_grp, &this->tesla_key_.private_Q,
                                                        ^~~~~~~~~
src/esphome/components/tesla_ble/client.cpp:241:50: error: void value not ignored as it ought to be
   return_code = mbedtls_sha1_starts(&sha1_context);
                                                  ^
src/esphome/components/tesla_ble/client.cpp:248:62: error: void value not ignored as it ought to be
                                     temp_shared_secret_length);
                                                              ^
src/esphome/components/tesla_ble/client.cpp:254:72: error: void value not ignored as it ought to be
   return_code = mbedtls_sha1_finish(&sha1_context, this->shared_secret_);
                                                                        ^
src/esphome/components/tesla_ble/client.cpp: In member function 'int TeslaBLE::Client::Encrypt(unsigned char*, size_t, unsigned char*, size_t, size_t*, unsigned char*)':
src/esphome/components/tesla_ble/client.cpp:297:49: error: too few arguments to function 'int mbedtls_gcm_starts(mbedtls_gcm_context*, int, const unsigned char*, size_t, const unsigned char*, size_t)'
                                    sizeof(nonce));
                                                 ^
In file included from src/esphome/components/tesla_ble/client.cpp:7:
/data/cache/platformio/packages/framework-arduinoespressif32/tools/sdk/esp32/include/mbedtls/mbedtls/include/mbedtls/gcm.h:244:5: note: declared here
 int mbedtls_gcm_starts( mbedtls_gcm_context *ctx,
     ^~~~~~~~~~~~~~~~~~
src/esphome/components/tesla_ble/client.cpp:304:40: error: invalid conversion from 'unsigned char*' to 'size_t' {aka 'unsigned int'} [-fpermissive]
       mbedtls_gcm_update(&aes_context, input_buffer, input_buffer_length,
                                        ^~~~~~~~~~~~
src/esphome/components/tesla_ble/client.cpp:304:54: error: invalid conversion from 'size_t' {aka 'unsigned int'} to 'const unsigned char*' [-fpermissive]
       mbedtls_gcm_update(&aes_context, input_buffer, input_buffer_length,
                                                      ^~~~~~~~~~~~~~~~~~~
src/esphome/components/tesla_ble/client.cpp:305:76: error: too many arguments to function 'int mbedtls_gcm_update(mbedtls_gcm_context*, size_t, const unsigned char*, unsigned char*)'
                          output_buffer, output_buffer_length, output_length);
                                                                            ^
In file included from src/esphome/components/tesla_ble/client.cpp:7:
/data/cache/platformio/packages/framework-arduinoespressif32/tools/sdk/esp32/include/mbedtls/mbedtls/include/mbedtls/gcm.h:276:5: note: declared here
 int mbedtls_gcm_update( mbedtls_gcm_context *ctx,
     ^~~~~~~~~~~~~~~~~~
src/esphome/components/tesla_ble/client.cpp:317:69: error: too many arguments to function 'int mbedtls_gcm_finish(mbedtls_gcm_context*, unsigned char*, size_t)'
                          &finish_buffer_length, signature_buffer, 16);
                                                                     ^
In file included from src/esphome/components/tesla_ble/client.cpp:7:
/data/cache/platformio/packages/framework-arduinoespressif32/tools/sdk/esp32/include/mbedtls/mbedtls/include/mbedtls/gcm.h:297:5: note: declared here
 int mbedtls_gcm_finish( mbedtls_gcm_context *ctx,
     ^~~~~~~~~~~~~~~~~~
*** [.pioenvs/watchy-01/src/esphome/components/tesla_ble/client.cpp.o] Error 1

I quickly had a look at it, but some changes do not seem that trivial to me. Any chance you could make the library compatible with both versions (2.x and 3.x)? I doubt adding 3.x on top of 2.x in my work tree would do any good.

Thanks!

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.