Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Tesla] Binding going offline #14435

Open
hlemmens opened this issue Feb 18, 2023 · 43 comments
Open

[Tesla] Binding going offline #14435

hlemmens opened this issue Feb 18, 2023 · 43 comments
Labels
bug An unexpected problem or unintended behavior of an add-on

Comments

@hlemmens
Copy link

Since about a month, my Tesla binding is going offline every 8 hours. It seems to be a problem of getting a new access token once the old one has expired. After manually disabling and enabling the binding, everything works fine for another 8 hours.

Anyone experiencing the same issue? Any solution?

@hlemmens hlemmens added the bug An unexpected problem or unintended behavior of an add-on label Feb 18, 2023
@wborn
Copy link
Member

wborn commented Feb 18, 2023

I think it was fixed with #14300?

@hlemmens
Copy link
Author

hlemmens commented Feb 19, 2023 via email

@wborn
Copy link
Member

wborn commented Feb 19, 2023

It depends on your installation method.

openHABian has a tool for it:

https://www.openhab.org/docs/installation/openhabian.html#openhabian-configuration-tool

@hlemmens
Copy link
Author

hlemmens commented Feb 19, 2023 via email

@lolodomo lolodomo changed the title Tesla binding going offline [Tesla] Binding going offline Feb 21, 2023
@wborn
Copy link
Member

wborn commented Feb 21, 2023

Does it fix your issue @hlemmens?

@wborn wborn added the awaiting feedback Awaiting feedback from the pull request author label Feb 21, 2023
@hlemmens
Copy link
Author

Unfortunately not. But I'm not sure the #14300 fix was implemented in v3.4.2. . How to figure out?

@wborn
Copy link
Member

wborn commented Feb 21, 2023

It should be part of it according to the release notes:

/~https://github.com/openhab/openhab-distro/releases/tag/3.4.2

@hlemmens
Copy link
Author

hlemmens commented Feb 21, 2023 via email

@hlemmens
Copy link
Author

The version 3.4.2 doesn't solve this #14435 issue. Any other hints?

@wborn
Copy link
Member

wborn commented Feb 21, 2023

I don't use it myself, maybe @kaikreuzer or @kgoderis can help.

@kaikreuzer
Copy link
Member

I can't. For me it is absolutely stable.
What might help could be some debug logs from the moment when it goes offline.

@hlemmens
Copy link
Author

hlemmens commented Feb 22, 2023 via email

@lsiepel
Copy link
Contributor

lsiepel commented Feb 23, 2023

You need to enable DEBUG logging. Documentation is here:
https://www.openhab.org/docs/administration/logging.html

TL;DR from the console: log:set DEBUG org.openhab.binding.tesla

@hlemmens
Copy link
Author

hlemmens commented Feb 23, 2023 via email

@hlemmens
Copy link
Author

hlemmens commented Feb 23, 2023

This is what I could read in the log file:
2023-02-23 20:00:09.271 [DEBUG] [internal.handler.TeslaAccountHandler] - The access token has expired, trying to get a new one.
2023-02-23 20:00:09.273 [DEBUG] [internal.handler.TeslaAccountHandler] - Current authentication time 2023-02-23 20:00:09
2023-02-23 20:00:09.275 [DEBUG] [internal.handler.TeslaAccountHandler] - Found a request token from 2023-02-23 11:59:18
2023-02-23 20:00:09.277 [DEBUG] [internal.handler.TeslaAccountHandler] - Access token expiration time 2023-02-23 19:59:18
2023-02-23 20:00:09.278 [DEBUG] [internal.handler.TeslaAccountHandler] - The access token has expired
2023-02-23 20:00:09.280 [DEBUG] [sla.internal.handler.TeslaSSOHandler] - Exchanging SSO refresh token for API access token
2023-02-23 20:00:09.281 [DEBUG] [internal.handler.TeslaAccountHandler] - The access token has expired, trying to get a new one.
2023-02-23 20:00:09.284 [DEBUG] [internal.handler.TeslaAccountHandler] - Current authentication time 2023-02-23 20:00:09
2023-02-23 20:00:09.287 [DEBUG] [internal.handler.TeslaAccountHandler] - Found a request token from 2023-02-23 11:59:18
2023-02-23 20:00:09.290 [DEBUG] [internal.handler.TeslaAccountHandler] - Access token expiration time 2023-02-23 19:59:18
2023-02-23 20:00:09.292 [DEBUG] [internal.handler.TeslaAccountHandler] - The access token has expired
2023-02-23 20:00:09.294 [DEBUG] [sla.internal.handler.TeslaSSOHandler] - Exchanging SSO refresh token for API access token
2023-02-23 20:00:09.314 [DEBUG] [sla.internal.handler.TeslaSSOHandler] - An exception occurred while invoking a HTTP request: 'java.io.EOFException: HttpConnectionOverHTTP@1057eb::DecryptedEndPoint@1dda816{l=/192.168.0.181:57782,r=auth.tesla.com/23.55.96.81:443,OPEN,fill=-,flush=-,to=28850510/0}'
2023-02-23 20:00:09.316 [DEBUG] [sla.internal.handler.TeslaSSOHandler] - An error occurred during refresh of SSO token: no response
2023-02-23 20:00:09.319 [DEBUG] [internal.handler.TeslaAccountHandler] - An error occurred while communicating with the vehicle during request charge_state: 401: Unauthorized
2023-02-23 20:00:09.915 [DEBUG] [sla.internal.handler.TeslaSSOHandler] - Access token expires in 28800 seconds at 2023-02-24 04:00:09
2023-02-23 20:00:09.918 [DEBUG] [internal.handler.TeslaAccountHandler] - An error occurred while communicating with the vehicle during request set_charging_amps: 401: Unauthorized
2023-02-23 20:00:12.168 [DEBUG] [internal.handler.TeslaVehicleHandler] - Car has not moved in 5 min, and can sleep
2023-02-23 20:00:12.170 [DEBUG] [internal.handler.TeslaVehicleHandler] - fastpoll: Throttled to allow sleep, occupied/idle, or in a console mode
2023-02-23 20:00:14.654 [DEBUG] [internal.handler.TeslaVehicleHandler] - Querying the vehicle, response : 200, OK
2023-02-23 20:00:14.655 [DEBUG] [internal.handler.TeslaVehicleHandler] - Querying the vehicle: *VIN MASKED

It seems the bridge had some trouble to get a fresh access token. After a few attempts, it succeeded. But often it fails and I have to disable the bridge and then enable it.

@lsiepel
Copy link
Contributor

lsiepel commented Feb 23, 2023

The interesting part:
'java.io.EOFException: HttpConnectionOverHTTP@1057eb::DecryptedEndPoint@1dda816{l=/192.168.0.181:57782,r=auth.tesla.com/23.55.96.81:443,OPEN,fill=-,flush=-,to=28850510/0}'

Without the request and response it is hard to say why this end of file exception occurs. The binding does not have a trace logs set to capture those details, so without an updated binding version it is hard to tell what is causing this. It might also be something on the Tesla side, hard to tell.

@oOMagicOo
Copy link

I have the same problem since a few month. Already surfaced the problem in the OH forum here. Eventually I wrote a script which restarts the binding every 8hrs which is not nice but works for me.

@lsiepel
Copy link
Contributor

lsiepel commented Feb 25, 2023

I have the same problem since a few month. Already surfaced the problem in the OH forum here. Eventually I wrote a script which restarts the binding every 8hrs which is not nice but works for me.

I could write some workaround this weekend. That if a eof exception occurs it performs one or two retries. But that is just a workaround the real cause is not yet known. I might also improve the logging.

@hlemmens
Copy link
Author

Looking into the debug logs, I noticed some commands are no longer accepted (start charging, set charging amps), although the access key has not yet expired. At the same moment, the querying the vehicle seems to work.

Here goes a subset of logs:
2023-02-25 12:52:09.255 [DEBUG] [internal.handler.TeslaAccountHandler] - An error occurred while communicating with the vehicle during request charge_state: 408: Request Timeout
2023-02-25 12:52:09.260 [DEBUG] [internal.handler.TeslaAccountHandler] - An error occurred while communicating with the vehicle during request set_charging_amps: 408: Request Timeout
2023-02-25 12:52:09.299 [DEBUG] [internal.handler.TeslaAccountHandler] - An error occurred while communicating with the vehicle during request charge_start: 408: Request Timeout
2023-02-25 12:52:09.878 [DEBUG] [internal.handler.TeslaAccountHandler] - Invoking: charge_state
2023-02-25 12:52:10.179 [WARN ] [internal.handler.TeslaAccountHandler] - Reached the maximum number of errors (3) for the current interval (15 seconds)
2023-02-25 12:52:10.182 [DEBUG] [internal.handler.TeslaAccountHandler] - An error occurred while communicating with the vehicle during request charge_state: 408: Request Timeout
2023-02-25 12:52:23.516 [DEBUG] [internal.handler.TeslaAccountHandler] - Setting up an authenticated connection to the Tesla back-end
2023-02-25 12:52:23.518 [DEBUG] [internal.handler.TeslaAccountHandler] - Current authentication time 2023-02-25 12:52:23
2023-02-25 12:52:23.520 [DEBUG] [internal.handler.TeslaAccountHandler] - Found a request token from 2023-02-25 08:23:35
2023-02-25 12:52:23.522 [DEBUG] [internal.handler.TeslaAccountHandler] - Access token expiration time 2023-02-25 16:23:35
2023-02-25 12:52:23.524 [DEBUG] [internal.handler.TeslaAccountHandler] - The access token has not expired yet
2023-02-25 12:52:24.006 [DEBUG] [internal.handler.TeslaAccountHandler] - Querying the vehicle: Response: 200: OK
2023-02-25 12:52:24.009 [DEBUG] [internal.handler.TeslaAccountHandler] - Invoking: vehicle_config
2023-02-25 12:52:24.252 [DEBUG] [internal.handler.TeslaAccountHandler] - An error occurred while communicating with the vehicle during request vehicle_config: 408: Request Timeout
2023-02-25 12:52:24.263 [DEBUG] [internal.handler.TeslaAccountHandler] - Retrying to send the command set_charging_amps.
2023-02-25 12:52:24.265 [DEBUG] [internal.handler.TeslaAccountHandler] - Invoking: set_charging_amps
2023-02-25 12:52:24.302 [DEBUG] [internal.handler.TeslaAccountHandler] - Retrying to send the command charge_start.
2023-02-25 12:52:24.304 [DEBUG] [internal.handler.TeslaAccountHandler] - Invoking: charge_start
2023-02-25 12:52:24.547 [DEBUG] [internal.handler.TeslaAccountHandler] - An error occurred while communicating with the vehicle during request set_charging_amps: 408: Request Timeout
2023-02-25 12:52:24.622 [DEBUG] [internal.handler.TeslaAccountHandler] - An error occurred while communicating with the vehicle during request charge_start: 408: Request Timeout
2023-02-25 12:52:33.370 [DEBUG] [internal.handler.TeslaVehicleHandler] - Querying the vehicle, response : 200, OK
2023-02-25 12:52:33.371 [DEBUG] [internal.handler.TeslaVehicleHandler] - Querying the vehicle: VIN 5YJ3E7EB1KF240549
2023-02-25 12:52:33.373 [DEBUG] [internal.handler.TeslaVehicleHandler] - Vehicle state is asleep
2023-02-25 12:52:33.374 [DEBUG] [internal.handler.TeslaVehicleHandler] - Vehicle is asleep.
2023-02-25 12:52:39.549 [DEBUG] [internal.handler.TeslaAccountHandler] - Retrying to send the command set_charging_amps.
2023-02-25 12:52:39.551 [DEBUG] [internal.handler.TeslaAccountHandler] - Invoking: set_charging_amps
2023-02-25 12:52:39.623 [DEBUG] [internal.handler.TeslaAccountHandler] - Retrying to send the command charge_start.
2023-02-25 12:52:39.625 [DEBUG] [internal.handler.TeslaAccountHandler] - Invoking: charge_start
2023-02-25 12:52:39.848 [DEBUG] [internal.handler.TeslaAccountHandler] - An error occurred while communicating with the vehicle during request set_charging_amps: 408: Request Timeout
2023-02-25 12:52:39.878 [DEBUG] [internal.handler.TeslaAccountHandler] - An error occurred while communicating with the vehicle during request charge_start: 408: Request Timeout

@hlemmens
Copy link
Author

Another snippet of logs shows that when the vehicle is not waked up, the charge-start command and set charging amps command fails. After waking up, it works well.

Retrying to send the command set_charging_amps.
2023-02-25 13:02:54.932 [DEBUG] [internal.handler.TeslaAccountHandler] - Invoking: set_charging_amps
2023-02-25 13:02:55.099 [DEBUG] [internal.handler.TeslaAccountHandler] - Retrying to send the command charge_start.
2023-02-25 13:02:55.101 [DEBUG] [internal.handler.TeslaAccountHandler] - Invoking: charge_start
2023-02-25 13:02:55.311 [DEBUG] [internal.handler.TeslaAccountHandler] - An error occurred while communicating with the vehicle during request set_charging_amps: 408: Request Timeout
2023-02-25 13:02:55.372 [DEBUG] [internal.handler.TeslaAccountHandler] - An error occurred while communicating with the vehicle during request charge_start: 408: Request Timeout
2023-02-25 13:03:08.864 [DEBUG] [internal.handler.TeslaVehicleHandler] - handleCommand tesla:model3:b31e2fa7ff:5YJ3E7EB1KF240549:charge ON
2023-02-25 13:03:08.866 [DEBUG] [internal.handler.TeslaVehicleHandler] - Waking vehicle to send command.
2023-02-25 13:03:08.869 [DEBUG] [internal.handler.TeslaAccountHandler] - Invoking: wake_up
2023-02-25 13:03:08.869 [DEBUG] [internal.handler.TeslaAccountHandler] - Invoking: charge_start
2023-02-25 13:03:08.870 [DEBUG] [internal.handler.TeslaAccountHandler] - Invoking: charge_state
2023-02-25 13:03:08.890 [DEBUG] [internal.handler.TeslaVehicleHandler] - handleCommand tesla:model3:b31e2fa7ff:5YJ3E7EB1KF240549:chargingamps 18 A
2023-02-25 13:03:08.895 [DEBUG] [internal.handler.TeslaVehicleHandler] - Waking vehicle to send command.
2023-02-25 13:03:08.896 [DEBUG] [internal.handler.TeslaAccountHandler] - Invoking: wake_up
2023-02-25 13:03:08.896 [DEBUG] [internal.handler.TeslaAccountHandler] - Invoking: set_charging_amps
2023-02-25 13:03:09.328 [DEBUG] [internal.handler.TeslaVehicleHandler] - The request (charge_start) execution was successful, and reported ''
2023-02-25 13:03:09.351 [DEBUG] [internal.handler.TeslaVehicleHandler] - The request (set_charging_amps) execution was successful, and reported ''

@hlemmens
Copy link
Author

It seems to be related to the vehicle state sleeping. the wake-up command doesn't always succeed.

@lsiepel
Copy link
Contributor

lsiepel commented Feb 25, 2023

It seems to be related to the vehicle state sleeping. the wake-up command doesn't always succeed.

But restarting the binding always works?

@hlemmens
Copy link
Author

Not sure. It works when I restart the bridge and the vehicle thing after the access token has expired. I'm not sure I did it before .

2023-02-24 12:42:57.612 [DEBUG] [internal.handler.TeslaAccountHandler] - The access token has expired, trying to get a new one.
2023-02-24 12:42:57.614 [DEBUG] [internal.handler.TeslaAccountHandler] - Current authentication time 2023-02-24 12:42:57
2023-02-24 12:42:57.615 [DEBUG] [internal.handler.TeslaAccountHandler] - Found a request token from 2023-02-24 04:42:48
2023-02-24 12:42:57.617 [DEBUG] [internal.handler.TeslaAccountHandler] - Access token expiration time 2023-02-24 12:42:48
2023-02-24 12:42:57.618 [DEBUG] [internal.handler.TeslaAccountHandler] - The access token has expired
2023-02-24 12:42:57.620 [DEBUG] [sla.internal.handler.TeslaSSOHandler] - Exchanging SSO refresh token for API access token
2023-02-24 12:42:57.648 [DEBUG] [sla.internal.handler.TeslaSSOHandler] - An exception occurred while invoking a HTTP request: 'java.io.EOFException: HttpConnectionOverHTTP@13a9656::DecryptedEndPoint@fe16aa{l=/192.168.0.181:37214,r=auth.tesla.com/2.21.16.79:443,OPEN,fill=-,flush=-,to=28809513/0}'
2023-02-24 12:42:57.650 [DEBUG] [sla.internal.handler.TeslaSSOHandler] - An error occurred during refresh of SSO token: no response
2023-02-24 12:42:57.653 [DEBUG] [internal.handler.TeslaAccountHandler] - An error occurred while communicating with the vehicle during request drive_state: 401: Unauthorized
2023-02-24 14:52:05.363 [DEBUG] [internal.handler.TeslaVehicleHandler] - handleCommand tesla:model3:b31e2fa7ff:5YJ3E7EB1KF240549:chargingamps 15 A
2023-02-24 14:52:05.366 [DEBUG] [internal.handler.TeslaVehicleHandler] - Waking vehicle to send command.
2023-02-24 14:52:11.999 [DEBUG] [internal.handler.TeslaVehicleHandler] - handleCommand tesla:model3:b31e2fa7ff:5YJ3E7EB1KF240549:chargingamps 15 A
2023-02-24 14:52:12.001 [DEBUG] [internal.handler.TeslaVehicleHandler] - Waking vehicle to send command.
2023-02-24 14:52:25.053 [DEBUG] [internal.handler.TeslaVehicleHandler] - handleCommand tesla:model3:b31e2fa7ff:5YJ3E7EB1KF240549:charge ON
2023-02-24 14:52:25.055 [DEBUG] [internal.handler.TeslaVehicleHandler] - Waking vehicle to send command.
2023-02-24 14:52:41.484 [DEBUG] [internal.handler.TeslaAccountHandler] - Disposing the Tesla account handler for tesla:account:Hubertcar
2023-02-24 14:52:42.909 [DEBUG] [internal.handler.TeslaAccountHandler] - Initializing the Tesla account handler for Hubertcar
2023-02-24 14:52:42.914 [DEBUG] [internal.handler.TeslaAccountHandler] - Setting up an authenticated connection to the Tesla back-end
2023-02-24 14:52:42.918 [DEBUG] [internal.handler.TeslaAccountHandler] - Current authentication time 2023-02-24 14:52:42
2023-02-24 14:52:42.921 [DEBUG] [sla.internal.handler.TeslaSSOHandler] - Exchanging SSO refresh token for API access token
2023-02-24 14:52:43.539 [DEBUG] [sla.internal.handler.TeslaSSOHandler] - Access token expires in 28800 seconds at 2023-02-24 22:52:43
2023-02-24 14:52:44.234 [DEBUG] [internal.handler.TeslaAccountHandler] - Querying the vehicle: Response: 200: OK
2023-02-24 14:52:44.241 [DEBUG] [internal.handler.TeslaAccountHandler] - Invoking: vehicle_config
2023-02-24 14:52:44.671 [DEBUG] [scovery.TeslaVehicleDiscoveryService] - Found a model3 vehicle
2023-02-24 14:52:44.707 [DEBUG] [internal.handler.TeslaAccountHandler] - Querying the vehicle: VIN 5YJ3E7EB1KF240549
2023-02-24 14:52:44.710 [DEBUG] [internal.handler.TeslaVehicleHandler] - Vehicle state is initializing or unknown
2023-02-24 14:52:53.230 [DEBUG] [internal.handler.TeslaVehicleHandler] - handleCommand tesla:model3:b31e2fa7ff:5YJ3E7EB1KF240549:charge ON
2023-02-24 14:52:53.233 [DEBUG] [internal.handler.TeslaVehicleHandler] - Waking vehicle to send command.
2023-02-24 14:52:53.237 [DEBUG] [internal.handler.TeslaAccountHandler] - Invoking: charge_start
2023-02-24 14:52:53.237 [DEBUG] [internal.handler.TeslaAccountHandler] - Invoking: wake_up
2023-02-24 14:52:53.239 [DEBUG] [internal.handler.TeslaAccountHandler] - Invoking: charge_state
2023-02-24 14:52:55.560 [DEBUG] [internal.handler.TeslaVehicleHandler] - handleCommand tesla:model3:b31e2fa7ff:5YJ3E7EB1KF240549:charge OFF
2023-02-24 14:52:55.561 [DEBUG] [internal.handler.TeslaVehicleHandler] - Waking vehicle to send command.
2023-02-24 14:52:55.565 [DEBUG] [internal.handler.TeslaAccountHandler] - Invoking: wake_up
2023-02-24 14:52:55.566 [DEBUG] [internal.handler.TeslaAccountHandler] - Invoking: charge_stop
2023-02-24 14:52:55.567 [DEBUG] [internal.handler.TeslaAccountHandler] - Invoking: charge_state
at org.openhab.binding.tesla.internal.handler.TeslaVehicleHandler.queryVehicle(TeslaVehicleHandler.java:821) ~[?:?]
at org.openhab.binding.tesla.internal.handler.TeslaVehicleHandler.queryVehicleAndUpdate(TeslaVehicleHandler.java:855) ~[?:?]
at org.openhab.binding.tesla.internal.handler.TeslaVehicleHandler.lambda$2(TeslaVehicleHandler.java:171) ~[?:?]
2023-02-24 14:53:14.340 [DEBUG] [internal.handler.TeslaVehicleHandler] - Querying the vehicle, response : 200, OK
2023-02-24 14:53:14.346 [DEBUG] [internal.handler.TeslaVehicleHandler] - Querying the vehicle: VIN 5YJ3E7EB1KF240549

At this moment, everything works fine. I will test whenever the communication stops.

@hlemmens
Copy link
Author

Latest logs: no reply on the request for a new access token.

2023-02-25 16:23:35.355 [DEBUG] [internal.handler.TeslaVehicleHandler] - Querying the vehicle, response : 401, Unauthorized
2023-02-25 16:23:35.356 [DEBUG] [internal.handler.TeslaVehicleHandler] - The access token has expired, trying to get a new one.
2023-02-25 16:23:35.358 [DEBUG] [internal.handler.TeslaAccountHandler] - Current authentication time 2023-02-25 16:23:35
2023-02-25 16:23:35.359 [DEBUG] [internal.handler.TeslaAccountHandler] - Found a request token from 2023-02-25 08:23:35
2023-02-25 16:23:35.360 [DEBUG] [internal.handler.TeslaAccountHandler] - Access token expiration time 2023-02-25 16:23:35
2023-02-25 16:23:35.361 [DEBUG] [internal.handler.TeslaAccountHandler] - The access token has expired
2023-02-25 16:23:35.362 [DEBUG] [sla.internal.handler.TeslaSSOHandler] - Exchanging SSO refresh token for API access token
2023-02-25 16:23:35.387 [DEBUG] [sla.internal.handler.TeslaSSOHandler] - An exception occurred while invoking a HTTP request: 'java.io.EOFException: HttpConnectionOverHTTP@1c20e06::DecryptedEndPoint@7d0c51{l=/192.168.0.181:37224,r=auth.tesla.com/2.21.16.79:443,OPEN,fill=-,flush=-,to=28800190/0}'
2023-02-25 16:23:35.388 [DEBUG] [sla.internal.handler.TeslaSSOHandler] - An error occurred during refresh of SSO token: no response
2023-02-25 16:23:35.389 [DEBUG] [internal.handler.TeslaVehicleHandler] - An error occurred while querying the vehicle

@lsiepel
Copy link
Contributor

lsiepel commented Feb 26, 2023

Maybe waking the car prior to refreshing the token maight help, but i'm to unfamilair with the API and i don;t own such a car, so i think @kaikreuzer or @kgoderis might be of more help to proceed with these logs and a workaround.

@lsiepel lsiepel removed the awaiting feedback Awaiting feedback from the pull request author label Feb 26, 2023
@hlemmens
Copy link
Author

Maybe waking the car prior to refreshing the token maight help, but i'm to unfamilair with the API and i don;t own such a car, so i think @kaikreuzer or @kgoderis might be of more help to proceed with these logs and a workaround.

Hope somebody will take the challenge? Personally, I'm not at all familiar with Java and unable to do it.

@hlemmens
Copy link
Author

hlemmens commented Feb 27, 2023

I have the same problem since a few month. Already surfaced the problem in the OH forum here. Eventually I wrote a script which restarts the binding every 8hrs which is not nice but works for me.

@oOMagicOo Would you be so kind to share your script with me?

@lavanden
Copy link

Same issue here.

Since a restart of the binding always works, could it be that the httpClient is acting up?

What if you pass in the httpClientFactory to the TeslaSSOHandler and getting a httpClient every time you call getAccessToken?

@lavanden
Copy link

lavanden commented Apr 13, 2023

@kaikreuzer, @kgoderis ,

Following changes seem to work for me:

in TeslaSSOHandler, in method getAccessToken, create a new httpClient for each call

HttpClient httpClient = httpClientFactory.createHttpClient("teslaSSOClient");
if (!httpClient.isStarted()) {
    try {
        httpClient.start();
    } catch (Exception e) {
        logger.debug("Exception while starting httpClient");
    }
}
final org.eclipse.jetty.client.api.Request request = httpClient.newRequest(URI_SSO + "/" + PATH_TOKEN);

request.content(new StringContentProvider(refreshTokenPayload));
request.header(HttpHeader.CONTENT_TYPE, "application/json");
request.method(HttpMethod.POST);

ContentResponse refreshResponse = executeHttpRequest(request);

if (httpClient.isStarted()) {
    try {
        httpClient.stop();
        httpClient.destroy();
    } catch (Exception e) {
        logger.debug("Exception while stopping httpClient");
    }
}

However, I don't know if creating clients every call is a good idea. There might be better ways but I don't know since I'm not a Java/OpenHab developer.

@thijslemmens
Copy link

@lavanden I implemented your fix for 3.4.4:
https://drive.google.com/file/d/13ntyqtyML22IOovsJbhVaHSTdibzbuUF/view?usp=sharing

This is the commit: thijslemmens@851d569

I can make an official PR, but I don't know if it has a chance of getting accepted.

@lsiepel
Copy link
Contributor

lsiepel commented May 7, 2023

@thijslemmens It probably only hides the real problem. Switching from the common http client to a 'custom' client is not something i would advice. We should find out why the clients needs to be recreated. What property/circumstances is causing this behaviour with the client that it needs to be restarted?

@thijslemmens
Copy link

@thijslemmens It probably only hides the real problem. Switching from the common http client to a 'custom' client is not something i would advice. We should find out why the clients needs to be recreated. What property/circumstances is causing this behaviour with the client that it needs to be restarted?

I agree. I built this version for @hlemmens so he does not need to manually restart the binding every time.
Any suggestions of what we can try to get closer to the real problem? I can build a version with extra debugging, but I'm not sure what to try next.

@lavanden
Copy link

lavanden commented May 8, 2023

@lsiepel ,

I tried debugging the issue, but I could not get to the root. I'm thinking that the connection with the tesla backend gets dropped after 28800 seconds.

@lsiepel
Copy link
Contributor

lsiepel commented May 8, 2023

Previously your logs recorded:

2023-02-25 16:23:35.387 [DEBUG] [sla.internal.handler.TeslaSSOHandler] - An exception occurred while invoking a HTTP request: 'java.io.EOFException: HttpConnectionOverHTTP@1c20e06::DecryptedEndPoint@7d0c51{l=/192.168.0.181:37224,r=auth.tesla.com/2.21.16.79:443,OPEN,fill=-,flush=-,to=28800190/0}'

You could try to log the raw request/response to a file and see how the first (binding init) and last (when it crashed) differ.

If that leads to nothing, you might also handle the EOFException by retrying / resetting all tokens and retry or something. Is that of any help? I don;t own a Teslo so i can't test, but this would be my aproach i guess.

@lsiepel
Copy link
Contributor

lsiepel commented Oct 28, 2023

Some connection related fixes have been merged after 3.4.4. Not sure if it also affects this issue, But could be usefull to check latest 4.1 snapshot or mile stone.

@Rucksackgesicht
Copy link

Hi guys,
have trouble with tesla binding 4.1.1. My account is offline so I can't control anything. It tries to go online, every 15 seconds but switches to offline immediately. I just did an openhab upgrade to 4.1.1 on sunday. No other changes.
Is someone out there with the same problems? Is it possible to downgrade just a single binding?

@J-N-K
Copy link
Member

J-N-K commented Jan 24, 2024

It's an issue with changed API on Tesla's side, I didn't upgrade and see the same issue.

@digitaldan
Copy link
Contributor

see #16318

@lsiepel
Copy link
Contributor

lsiepel commented Sep 9, 2024

While working on a different PR that also has problems with a hard to reproduce / debug EOFException it was discovered this is caused by some transient network issue that cause the httpclient to fail.
Because the issue is fixed with a new httpclient (stop/start) i'm pretty sure it is the same issue related to idleTimeOut. I guess there are multiple variants possible. Give me some time to create a PR.

Would be nice if any of you who experience this issue are available to test an updated jar.

@hlemmens
Copy link
Author

Happy to test, but with the actual binding is not possible to send charging commands to the new Tesla's. Tesla has again changed the protocol for new cars.

@lsiepel
Copy link
Contributor

lsiepel commented Sep 10, 2024

ctual binding is not possible to send charging commands to the new Tesla's. Tesla has again changed the protocol for new cars.

Do you have any details on the change and to what cars / versions / firmware etc it relates?

@hlemmens
Copy link
Author

You can find some information and an implementation example here: /~https://github.com/teslamotors/vehicle-command/blob/main/README.md

And this is the Tesla documentation on this issue: https://developer.tesla.com/docs/fleet-api/getting-started/what-is-fleet-api

Hope this can help. I didn't succeed to make a working python program to send controls to my Tesla.

@lsiepel
Copy link
Contributor

lsiepel commented Sep 11, 2024

You can find some information and an implementation example here: /~https://github.com/teslamotors/vehicle-command/blob/main/README.md

And this is the Tesla documentation on this issue: https://developer.tesla.com/docs/fleet-api/getting-started/what-is-fleet-api

Hope this can help. I didn't succeed to make a working python program to send controls to my Tesla.

As i don't own a Tesla, i can only stick to small bugfixes. For an extensive change like this it is better that someone else picks this up.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug An unexpected problem or unintended behavior of an add-on
Projects
None yet
Development

No branches or pull requests

10 participants