注意:本工具只能运行于 mac 或者 linux, win下不支持。
1. 克隆项目到本地
https://github.com/teslamotors/vehicle-command.git
2. 项目根目录下执行命令
go get ./...
go build ./...
go install ./...
cd cmd
cd tesla-control
go build
3. 生成密钥
生成私钥
openssl ecparam -genkey -name prime256v1 -noout > private.pem
生成公钥
openssl ec -in private.pem -pubout > public.pem
3. 添加汽车公钥
./tesla-control -vin {youvin} -ble add-key-request public.pem owner cloud_key
发出命令后,成功的请求将返回以下响应。
向 {youvin} 发送添加密钥请求。通过在中央控制台上轻触 NFC 卡进行确认。
当 NFC 卡在特斯拉汽车的中央控制台上触碰时,汽车显示控制台上会出现一条消息。
特斯拉触摸屏显示一个确认按钮,用于将公钥添加到汽车。
添加钥匙后,它将出现在钥匙列表中,如果您的手机上安装了特斯拉应用程序,也会收到通知。
列出汽车配对的所有钥匙
./tesla-control -vin {youvin} -ble -debug list-keys
4. 解锁/上锁
./tesla-control -ble -vin {youvin} -key-name private.pem -key-file private.pem unlock
./tesla-control -ble -vin {youvin} -key-name private.pem -key-file private.pem lock
6. 后备箱:开,关,开关切换
./tesla-control -ble -vin {youvin} -key-name private.pem -key-file private.pem trunk-open
./tesla-control -ble -vin {youvin} -key-name private.pem -key-file private.pem trunk-close
./tesla-control -ble -vin {youvin} -key-name private.pem -key-file private.pem trunk-move
7. 前备箱开
./tesla-control -ble -vin {youvin} -key-name private.pem -key-file private.pem frunk-open
8. 闪灯
./tesla-control -ble -vin {youvin} -key-name private.pem -key-file private.pem flash-lights
9. 命令帮助
./tesla-control -h
Usage: ./tesla-control [OPTION...] COMMAND [ARG...]Run ./tesla-control help COMMAND for more information. Valid COMMANDs are listed below.* Commands sent to a vehicle over the internet require a VIN and a token.* Commands sent to a vehicle over BLE require a VIN.* Account-management commands require a token.Available OPTIONs:-bleForce BLE connection even if OAuth environment variables are defined-command-timeout durationSet timeout for commands sent to the vehicle. (default 5s)-connect-timeout durationSet timeout for establishing initial connection. (default 20s)-debugEnable verbose debugging messages-domain valueDomains to connect to (can be repeated; omit for all)-key-file fileA file containing private key. Defaults to $TESLA_KEY_FILE.-key-name nameSystem keyring name for private key. Defaults to $TESLA_KEY_NAME.-keyring-debugEnable keyring debug logging-keyring-file-dir directorykeyring directory for file-backed keyring types (default "~/.tesla_keys")-keyring-type typeKeyring type (file|keychain|pass). Defaults to $TESLA_KEYRING_TYPE.-session-cache fileLoad session info cache from file. Defaults to $TESLA_CACHE_FILE.-token-file FileFile containing OAuth token. Defaults to $TESLA_TOKEN_FILE.-token-name nameSystem keyring name for OAuth token. Defaults to $TESLA_TOKEN_NAME.-vin stringVehicle Identification Number. Defaults to $TESLA_VIN.Available COMMANDs:add-key Add PUBLIC_KEY to vehicle whitelist with ROLE and FORM_FACTORadd-key-request Request NFC-card approval for a enrolling PUBLIC_KEY with ROLE and FORM_FACTORauto-seat-and-climate Turn on automatic seat heating and HVACautosecure-modelx Close falcon-wing doors and lock vehicle. Model X only.body-controller-state Fetch limited vehicle state information. Works over BLE when infotainment is asleep.charge-port-close Close charge portcharge-port-open Open charge portcharging-schedule Schedule charging to MINS minutes after midnight and enable daily schedulingcharging-schedule-cancel Cancel scheduled charge startcharging-set-amps Set charge current to AMPScharging-set-limit Set charge limit to PERCENTcharging-start Start chargingcharging-stop Stop chargingclimate-off Turn off climate controlclimate-on Turn on climate controlclimate-set-temp Set temperature (Celsius)drive Remote start vehicleerase-guest-data Erase Guest Mode user dataflash-lights Flash lightsfrunk-open Open vehicle frunk. Note that there's no frunk-close command!get GET an owner API http ENDPOINT. Hostname will be taken from -config.honk Honk hornlist-keys List public keys enrolled on vehiclelock Lock vehiclemedia-set-volume Set volumemedia-toggle-playback Toggle between play/pauseping Ping vehiclepost POST to ENDPOINT the contents of FILE. Hostname will be taken from -config.product-info Print JSON product inforemove-key Remove PUBLIC_KEY from vehicle whitelistrename-key Change the human-readable metadata of PUBLIC_KEY to NAME, MODEL, KINDseat-heater Set seat heater at POSITION to LEVELsentry-mode Set sentry mode to STATE ('on' or 'off')session-info Retrieve session info for PUBLIC_KEY from DOMAINsoftware-update-cancel Cancel a pending software updatesoftware-update-start Start software update after DELAYsteering-wheel-heater Set steering wheel mode to STATE ('on' or 'off')tonneau-close Close Cybertruck tonneau.tonneau-open Open Cybertruck tonneau.tonneau-stop Stop moving Cybertruck tonneau.trunk-close Closes vehicle trunk. Only available on certain vehicle types.trunk-move Toggle trunk open/closed. Closing is only available on certain vehicle types.trunk-open Open vehicle trunk. Note that trunk-close only works on certain vehicle types.unlock Unlock vehiclewake Wake up vehiclewindows-close Close all windowswindows-vent Vent all windows
参考资料
https://shankarkumarasamy.blog/2024/01/28/tesla-developer-api-guide-ble-key-pair-auth-and-vehicle-commands-part-3/
https://github.com/teslamotors/vehicle-command/blob/main/README.md