teslausb icon indicating copy to clipboard operation
teslausb copied to clipboard

Tesla_apy.pi failing to install from fresh installation

Open TarkUK opened this issue 1 year ago • 45 comments

Describe the problem

Fresh install of Tesla USB

in the teslausb_setup_variable.conf i have the below entered

export TESLA_EMAIL= export TESLA_PASSWORD= export TESLA_REFRESH_TOKEN= export TESLA_WAKE_MODE=stream

i copy the conf file over to the sd card and insert in to the PI and power up. looking at the logs tesla_apy.pi fails to install or run

Device

Raspberry Pi 4

OS Image

Prebuilt TeslaUSB image

Car Model

Model X

USB connection

Center console

Logs

Thu 26 Oct 14:03:26 BST 2023 : configure: Installing tesla_api.py Thu 26 Oct 14:03:26 BST 2023 : Downloaded /root/bin/tesla_api.py ... Thu 26 Oct 14:03:39 BST 2023 : configure: Failed to mount /mutable Thu 26 Oct 14:05:31 BST 2023 : configure: tesla_api.py setup failed

if i ssh into the PI the mount is there

Additional information

No response

TarkUK avatar Oct 26 '23 13:10 TarkUK

export TESLA_EMAIL= export TESLA_PASSWORD=

These are no longer used.

export TESLA_REFRESH_TOKEN=

Did you actually put a refresh token there? Because the above isn't going to work. Please follow the documentation in the config file.

export TESLA_WAKE_MODE=stream

You don't need to specify this as it's the default.

marcone avatar Oct 26 '23 16:10 marcone

Hello

i did put the refresh token there in addition to the other fields.

the reason i have tried the above is the Tesla Mod X is not staying awake

i have tried export TESLA_WAKE_MODE=stream, and have tried the same but with sentry

looking at the diagnostic logs its adds a line Not Keep Tesla Awake so i am a bit stuck hence reading the other post here that suggests adding Tesla Email / Passoword.

At the moment my car does not stay away hence not mounting the drive to record

TarkUK avatar Oct 26 '23 18:10 TarkUK

event with only the token added with nothing else, tesla_apy.py still fails if that makes a difference

TarkUK avatar Oct 26 '23 18:10 TarkUK

Something seems wrong with the refresh token then. Make sure to put it in quotes, and don't break it up into multiple lines. It should all be on one (long) line. After TeslaUSB installs tesla_api.py it tries to list the vehicles on the account using the provided refresh token. If that fails, you will get the "configure: tesla_api.py setup failed" message.

You could try the following:

sudo -i
source bin/envsetup.sh
echo $TESLA_REFRESH_TOKEN

Verify that what it prints matches the refresh token you generated.

Then run bin/tesla_api.py list_vehicles and see if/how that fails.

marcone avatar Oct 26 '23 18:10 marcone

will give that a shot now with the quote are you specifing this " at the start and the end

TarkUK avatar Oct 26 '23 18:10 TarkUK

just done a fresh install still get the error during setup however after all is done i have run the command you specified and it does output the details of my car

TarkUK avatar Oct 26 '23 18:10 TarkUK

should i do another fresh install but the the quoation marks " start and end "

TarkUK avatar Oct 26 '23 18:10 TarkUK

Single quotes are usually better e.g.

export TESLA_REFRESH_TOKEN='eyJhbGciOiJ........2F1dGgyL3YzL3Rva2'

(the real token will be much longer, probably over a thousand characters)

marcone avatar Oct 26 '23 18:10 marcone

oh, and you shouldn't need to do a fresh install every time. You can just reboot and it should resume/retry installation.

marcone avatar Oct 26 '23 18:10 marcone

so if i do

sudo -i source bin/envsetup.sh echo $TESLA_REFRESH_TOKEN Then run bin/tesla_api.py list_vehicles

and the output i get is my car, am i correct in assuming that its working ?

TarkUK avatar Oct 26 '23 18:10 TarkUK

Yes

marcone avatar Oct 26 '23 18:10 marcone

ok will looks like its working will go and plug in to car and see how it goes

thank you for all your help, will let you know what happens

TarkUK avatar Oct 26 '23 18:10 TarkUK

Plugged the Pi in to the car and waited for it to boot and the recording icon to appear on the screen which it did.

Went away for dinner, came back to the car with out the keys say 15min later and the Pi was powered off, got the keys walked to the car and it woke up went in to the car and the PI was booting up, Car reported 1 sentry event however when i go in to the app there is no event recorded

TarkUK avatar Oct 26 '23 19:10 TarkUK

It's not clear to me whether you took the car to go to dinner or left the car at home while you went away.

In any case, TeslaUSB only uses the Tesla API to keep the car awake during archiving. When Sentry mode is enabled, the car itself should keep the USB ports powered, and therefore the Pi should be on as long as Sentry mode is on.

marcone avatar Oct 26 '23 20:10 marcone

Hi Sorry

i should have said the car was parked at home with Sentry active

had dinner came back to car and the PI was powered off

TarkUK avatar Oct 26 '23 20:10 TarkUK

What model year is your Model X?

marcone avatar Oct 26 '23 20:10 marcone

2020

TarkUK avatar Oct 26 '23 20:10 TarkUK

Hmm, I don't understand what's going on then. The car should keep the USB port powered while Sentry is on (because without power even a regular USB drive wouldn't work), and yours apparently doesn't. That is unrelated to using tesla_api.py to keep the car awake during archiving.

marcone avatar Oct 26 '23 21:10 marcone

Defintly a very strange one unless something has been introduced in the latest tesla update to the car

TarkUK avatar Oct 26 '23 21:10 TarkUK

so if i do

sudo -i source bin/envsetup.sh echo $TESLA_REFRESH_TOKEN Then run bin/tesla_api.py list_vehicles

and the output i get is my car, am i correct in assuming that its working ?

this is what I get :-( when I do the commands from top

root@teslausb:~# bin/tesla_api.py list_vehicles Traceback (most recent call last): File "/root/bin/tesla_api.py", line 596, in main() File "/root/bin/tesla_api.py", line 572, in main _get_id() File "/root/bin/tesla_api.py", line 185, in _get_id result = list_vehicles() File "/root/bin/tesla_api.py", line 269, in list_vehicles return _execute_request(base_url, None, None, False) File "/root/bin/tesla_api.py", line 78, in _execute_request json_response = _rest_request(url, method, data) File "/root/bin/tesla_api.py", line 105, in _rest_request 'Authorization': 'Bearer {}'.format(_get_api_token()), File "/root/bin/tesla_api.py", line 163, in _get_api_token tesla.refresh_token() File "/usr/local/lib/python3.9/dist-packages/teslapy/init.py", line 249, in refresh_token super(Tesla, self).refresh_token(token_url, **kwargs) File "/usr/local/lib/python3.9/dist-packages/requests_oauthlib/oauth2_session.py", line 452, in refresh_token self.token = self._client.parse_request_body_response(r.text, scope=self.scope) File "/usr/local/lib/python3.9/dist-packages/oauthlib/oauth2/rfc6749/clients/base.py", line 427, in parse_request_body_response self.token = parse_token_response(body, scope=scope) File "/usr/local/lib/python3.9/dist-packages/oauthlib/oauth2/rfc6749/parameters.py", line 441, in parse_token_response validate_token_parameters(params) File "/usr/local/lib/python3.9/dist-packages/oauthlib/oauth2/rfc6749/parameters.py", line 448, in validate_token_parameters raise_from_error(params.get('error'), params) File "/usr/local/lib/python3.9/dist-packages/oauthlib/oauth2/rfc6749/errors.py", line 399, in raise_from_error raise cls(**kwargs) oauthlib.oauth2.rfc6749.errors.LoginRequired: (login_required) Login required

merlinfive avatar Oct 27 '23 09:10 merlinfive

did you add the token refresh in to the setup file

TarkUK avatar Oct 27 '23 11:10 TarkUK

yes ,

export TESLA_REFRESH_TOKEN='eyJhbGciOiJSUzI1NiIsInR5cCI6Ikp....snip.....emrhH-hyGw'

I use MFA on my account will this be a problem ?

and afterwards I started the bin/setup-teslausb , reboot to bring it into running config

merlinfive avatar Oct 27 '23 11:10 merlinfive

on my line i used these quotation marks "

then did a fresh install

TarkUK avatar Oct 27 '23 11:10 TarkUK

I saw a comment to use singe quotes but will give it a try

merlinfive avatar Oct 27 '23 11:10 merlinfive

yes true but i used " before i saw that comment but it worked

TarkUK avatar Oct 27 '23 11:10 TarkUK

same result :-(

merlinfive avatar Oct 27 '23 11:10 merlinfive

im see this line in the diagnostics

Fri 27 Oct 13:18:47 BST 2023: Failed to contact car using Tesla API, retrying in 5s...

no other line after that as i suspect the PI looses power

TarkUK avatar Oct 27 '23 12:10 TarkUK

Another update, so i have remove the Tesla_api comments in the setup file and moved to Tesla FI API,

ran the install and i can see the wake call within Tesla FI web portal so its working, however after about 5 min the Pi Powers off even with Sentry being turned on.

not sure if this normal behaviour or not

TarkUK avatar Oct 27 '23 13:10 TarkUK

ran the install and i can see the wake call within Tesla FI web portal so its working, however after about 5 min the Pi Powers off even with Sentry being turned on.

not sure if this normal behaviour or not

No, when Sentry mode is on the car is supposed to keep the USB ports powered. As I mentioned before, that's independent of using tesla_api.py to keep the car awake during archiving.

marcone avatar Oct 27 '23 20:10 marcone

Really don't know what the problem is, has to be a software issue with the tesla not sure if anyone else with a X is having the same

TarkUK avatar Oct 27 '23 21:10 TarkUK