Skip to content

Commit

Permalink
Merge pull request #36 from iainbullock/dev
Browse files Browse the repository at this point in the history
Dev->Main
  • Loading branch information
iainbullock authored Apr 7, 2024
2 parents 66b3223 + 2aaf466 commit 0e58909
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 11 deletions.
19 changes: 13 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
# Tesla HTTP Proxy Docker

** Pleae use release version v1.0.3 until I can investigate a problem reported with v1.0.4 (https://github.com/iainbullock/tesla-http-proxy-docker/issues/19). Dockerhub 'latest' tag withdrawn until next release **

Now tested and working as expected with Home Assistant custom integration https://github.com/alandtse/tesla

Originally this was a fork of https://github.com/llamafilm/tesla-http-proxy-addon. All credit to llamafilm (https://github.com/llamafilm) for developing most of this.
Expand Down Expand Up @@ -29,13 +27,22 @@ Setting this up is fairly complex. Please read [DOCS.md](./tesla_http_proxy/DOC

- Start the container again. Further configuration will occur, and the Flask service will start to handle the creation of the vehicle keypair with Tesla and installing the key into your vehicle

- Enter the URL of your FQDN into a web browser. A page titled 'Tesla HTTP Proxy setup' will appear. Click the 'Generate OAuth token' button. This will open another web page inviting you to login into to Tesla. You will then be offered to allow the application to access your Tesla account. Click all the check boxes and press the Allow button
- Enter the URL of your FQDN into a web browser. A page titled 'Tesla HTTP Proxy setup' will appear. Click the '1. Generate OAuth token' button. This will open another web page inviting you to login into to Tesla. You will then be offered to allow the application to access your Tesla account. Click all the check boxes and press the Allow button

- The callback will then occur which if successful will display a page saying 'Authorization complete'. Click the 'You can now close this browser instance' button
- The callback will then occur which if successful will display a page saying 'Authorization complete'. The has generated a public/private key pair for Tesla Vehicle Commands, and the initial Access and Refresh tokens for the API access. Click the 'You can now close this browser instance' button

- Return to the 'Tesla HTTP Proxy setup' page. Click the 'Enroll public key in your vehicle' button. Another Tesla web page will appear inviting you to set up a third party virtual key. There is a QR code which you should scan with your phone (which already has the Tesla App installed and setup for your Tesla account). Approve the key in the Tesla app, which if successful will install it into your vehicle. You can close this webpage
- Return to the 'Tesla HTTP Proxy setup' page. Click the '2. Test public key endpoint' button. This will download the public key (com.tesla.3p.public-key.pem). You don't need to keep the downloaded key. You must keep this accessible to the internet or Tesla will reject your commands made through the proxy. You may have to manually copy the public key to a suitable location in the document root on your webserver. Make sure this test works before proceeding

- Return to the 'Tesla HTTP Proxy setup' page. Click the 'Test public key endpoint' button. This will download the public key (the private key was installed into you car). You don't need it, but you must keep this accessible to the internet or Tesla will reject your commands made through the proxy
- Return to the 'Tesla HTTP Proxy setup' page. Click the '3. Register Partner account' button. This generates the Partner Authentication token, and registers the account for API access. There isn't any feedback whether this works or not. Check the logs you will see something like this:

[16:14:02] main:INFO: *** Generating Partner Authentication Token ***
[16:14:03] main:INFO: {"access_token":"LongString","expires_in":28800,"token_type":"Bearer"}
[16:14:03] main:INFO: *** Registering Tesla account ***
[16:14:05] main:INFO: {"response":{"account_id":"XXXX-XXX-XXXX-XXX","domain":"tesla.example.com","name":"TeslaH","description":"Home automation for my Tesla. Application is for personal use only","csr":null,"client_id":"XX-XXXX-XX-XXXXXXXXXX","ca":null,"created_at":"2024-02-28T13:50:49.494Z","updated_at":"2024-04-07T16:14:05.827Z","enterprise_tier":"free","issuer":null,"csr_updated_at":null,"public_key":"FairlyLongString"}}
[16:14:05] werkzeug:INFO: 192.168.1.5 - - [07/Apr/2024 16:14:05] "GET /register-partner-account HTTP/1.0" 302 -
[16:14:05] werkzeug:INFO: 192.168.1.5 - - [07/Apr/2024 16:14:05] "GET /?success=1 HTTP/1.0" 200 -

- Return to the 'Tesla HTTP Proxy setup' page. Click the '4. Enrol private key into your vehicle' button. Another Tesla web page will appear inviting you to set up a third party virtual key. There is a QR code which you should scan with your phone (which already has the Tesla App installed and setup for your Tesla account). Approve the key in the Tesla app, which if successful will install it into your vehicle. You can close this webpage

- Return to the 'Tesla HTTP Proxy setup' page. Click 'Shutdown Flask Server'. This will do as it says. From now on the proxy server will continue to run in the docker contianer and listen for requests

Expand Down
1 change: 0 additions & 1 deletion tesla_http_proxy/app/curl/test.sh
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
#!/bin/bash
#export TESLA_AUTH_TOKEN=XXXXXXXX
#export VIN=xxxxxxxxxxxxxxxxx

curl --cacert ../cert.pem \
--header "Authorization: Bearer $TESLA_AUTH_TOKEN" \
Expand Down
2 changes: 1 addition & 1 deletion tesla_http_proxy/app/run.sh
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ elif [ ! -f /share/nginx/com.tesla.3p.public-key.pem ]; then
generate_tesla_keypair
fi

if [ -f /share/home-assistant/selfsigned.pem ]; then
if [ -f /share/home-assistant/selfsigned.pem ] && [ -f /data/key.pem ]; then
certPubKey="$(openssl x509 -noout -pubkey -in /share/home-assistant/selfsigned.pem)"
keyPubKey="$(openssl pkey -pubout -in /data/key.pem)"
if [ "${certPubKey}" == "${keyPubKey}" ]; then
Expand Down
6 changes: 3 additions & 3 deletions tesla_http_proxy/app/templates/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -35,11 +35,11 @@ <h2>Tesla HTTP Proxy setup</h2>
type="button">2. Test public key endpoint</button></a>
</div>
<div class="content">
<a href="generate-partner-account"><button type="button">3. Register Partner account<br />
(Make sure the above test works)</button></a>
<a href="register-partner-account"><button type="button">3. Register Partner account<br />
(Make sure test 2 works first)</button></a>
</div>
<div class="content">
<a href="https://tesla.com/_ak/{{domain}}" target="_blank"><button type="button">4. Enroll public key in your
<a href="https://tesla.com/_ak/{{domain}}" target="_blank"><button type="button">4. Enrol private key into your
vehicle</button></a>
</div>
<div class="content">
Expand Down

0 comments on commit 0e58909

Please sign in to comment.