jonasman / TeslaSwift

Swift library to access the Tesla API
MIT License
247 stars 71 forks source link

Support the new Tesla command protocol #160

Open gshaviv opened 11 months ago

gshaviv commented 11 months ago

As the old command REST API is being deprecated, the new way of sending commands is via the new Tesla Command Protocol using the signed_command endpoint.

jonasman commented 11 months ago

The library has been changed to use the new API already. Or do you mean we need to make even more changes?

gshaviv commented 11 months ago

Indeed. According to the fleet API docs, the old REST api for sending commands will be deprecated end of the month and cease to work and starting Jan 24 sending commands will be done using the new command protocol and the new signed_command endpoint

gshaviv commented 11 months ago

Here is the link to the notification the old command API is phased out. https://developer.tesla.com/docs/fleet-api#announcements-amp-api-changelog

jonasman commented 11 months ago

the current library version already uses the new API.

jonasman commented 11 months ago

unless the current command API is going away too, but i dont see any alternative in the docs?

jonasman commented 11 months ago

ok i think i found the new endpoint: signed_command

gshaviv commented 11 months ago

Yep, the new endpoint is signed_command but I don't see any docs how to create the routable_message it needs. Only way I see is to try reverse engineer their go implementation available on GitHub. https://github.com/teslamotors/vehicle-command

NicolasJott commented 11 months ago

is this related to the response i've been getting when trying to send vehicle commands?

RESPONSE BODY: {"response":{"result":false,"reason":"unsigned_cmds_hardlocked"}}

gshaviv commented 11 months ago

Yep. The new way to send commands is to sign them with your private key so the car can verify them with your public key.

All vehicles will require this starting Jan and vehicles that didn't use the owner api commands last 30 days already require this. Also vehicles manufactured after October require this.

jonasman commented 10 months ago

I wonder if we shall use the proxy? this new API is a bit confusing to understand what is needed. I will try to see if we can use signed_command

jonasman commented 10 months ago

tried to have a look at signed_command, but im not sure how to build the message to send the command, probably need to base64 encode the protbuf msg somehow.

gshaviv commented 10 months ago

I saw in the proxy repository someone from Tesla wrote they are working on publishing docs for this. Hopefully will be available soon

gshaviv commented 9 months ago

Tesla added a doc explaining how messages are encoded to the proxy repo, maybe now we can implement this in the package:

https://github.com/teslamotors/vehicle-command/commit/d7a3e30f4f631b36760c61bc980157ea6de6d2bd

craigrigdon commented 9 months ago

any insight on encoding the protbuf msg to be sent via signed_command yet?

Urkman commented 9 months ago

@gshaviv did you make any progress with signing the command?

gshaviv commented 9 months ago

@Urkman Sorry, haven't had time to try it. Kinda busy and overwhelmed with other stuff at the moment.

jonasman commented 8 months ago

we need the pairing to work as well, not just sending messages. I recently installed Charge HQ and they have the new pairing working.

  1. First the user logs in with Tesla credentials
  2. Then the user needs to open a link that will in turn open the Tesla app
  3. The Tesla app asks to install some virtual key (for me it said it was not needed because my model S is old)
  4. After this virtual key is installed, i think the permissions are done

i think in the vehicle config this is what says if we need pairing or not: supports_qr_pairing or ble_autopair_enrolled

jonasman commented 8 months ago

i found how to do #2 will be pushing the code soon Tesla has updated the docs with more info

jonasman commented 8 months ago

tag 9.2.0 includes a helper to send the public key to the vehicle

jonasman commented 8 months ago

@gshaviv is the API now working fine for you? should we close this issue?

gshaviv commented 8 months ago

Vehicle commands are still not supported. Has any change been attempted to support the signed command?

jonasman commented 8 months ago

@gshaviv unfortunately i dont have a model 3/y/2021 S/X, so im not able to test. Do you mean that after we send the pub key we need to send all commands via the new signed_command API?

gshaviv commented 8 months ago

@jonasman exactly. The old way of sending commands no longer works. Only signed commands work.

jonasman commented 7 months ago

@gshaviv any idea on the api of that request?

Urkman commented 4 months ago

Anyone managed to sign a command using swift and send it to the API? https://developer.tesla.com/docs/fleet-api#signed_command

jonasman commented 3 months ago

@Urkman as far as i know, nobody is able to do it without using HTTP proxys yet.