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

Document the Streaming API #97

Open
timdorr opened this issue Dec 11, 2018 · 65 comments
Open

Document the Streaming API #97

timdorr opened this issue Dec 11, 2018 · 65 comments

Comments

@timdorr
Copy link
Owner

timdorr commented Dec 11, 2018

While there is support in the Ruby code for the Streaming API, the docs are completely empty. We should fix that by filling them in. Anyone want to help?

@jonasman
Copy link
Contributor

jonasman commented Mar 23, 2019

Streaming seems to not work on that endpoint anymore. Even for old cars.
Used my iOS lib and got this:

Opening Stream to: https://streaming.vn.teslamotors.com/stream/XX/?values=speed,odometer,soc,elevation,est_heading,est_lat,est_lng,power,shift_state,range,est_range,heading
Stream open
Stream data: <html>
Stream data: <head><title>502 Bad Gateway</title></head>
Stream data: <body bgcolor="white">
Stream data: <center><h1>502 Bad Gateway</h1></center>
Stream data: <hr><center>nginx</center>
Stream data: </body>
Stream data: </html>
Stream error: nil```

@davidhodge
Copy link

Having the same issue as @jonasman

@jonasman
Copy link
Contributor

jonasman commented Jul 8, 2019

Seems like i can get a few values out of the streaming before the 502 starts.

@karekaa
Copy link
Contributor

karekaa commented Jul 19, 2019

I see one possible thing to test out here:
https://www.lifewire.com/502-bad-gateway-error-explained-2622939

«Clear your browser cache [and/or cookies]. Outdated or corrupted files that are being stored by your browser could be causing 502 Bad Gateway issues ... »

@MrgSub
Copy link

MrgSub commented Sep 20, 2019

I tried the streaming API recently and it still doesn't work.

@timdorr
Copy link
Owner Author

timdorr commented Sep 25, 2019

The HTTP streaming endpoint is completely dead. It 502's for my car, which was still supported as of last year.

I've updated the gem to use the new WebSocket endpoint: 353cfc5

@TheSpaceCowboy
Copy link

My experience is that the 502's began in May/19 and have persisted. At that point I switched to a web-socket streaming implementation by dirkvm ( https://github.com/dirkvm/teslams ) forked from teslams. That worked until late summer at which time I began getting "data:error" messages indicating "vehicle_disconnected". At that point the code close the socket and retires with no success. The complete message from the data:subscribe attempt is:
data:error { msg_type: 'data:error', tag: 'XXX my vid XXX', value: 'disconnected', error_type: 'vehicle_disconnected' }
Are there any current streaming endpoint descriptions available, that are known to work?

@timdorr
Copy link
Owner Author

timdorr commented Oct 9, 2019

Mine works. It's actively running as I write this, for a project I'm working on right now.

@TheSpaceCowboy
Copy link

Will look into integrating into my processes. Thanks.

@jonasman
Copy link
Contributor

I will also implement this on TeslaSwift lib as soon as i get some time. Will report if it works. The HTTPSteamEvent stream is totally dead even for older cars.

@andrewgreenwood
Copy link

andrewgreenwood commented Nov 5, 2019

A couple of things to add to this:

You can send a "data:subscribe_oauth" msg_type instead of "data:subscribe". This uses the oauth token string instead of the token returned with the vehicle details.

If you respond to the "data:error" with a "data:subscribe_oauth", it seems to continue sending data so it does not look like closing and reopening the socket is necessary. Probably works the same with "data:subscribe" but I have not tested that.

EDIT: On further testing this does not seem to be as reliable as I had at first thought. And it seems that the Tesla app also performs a disconnect/reconnect if it receives a "data:error" as well.

My guess is that there's probably some message that needs to be sent in response to the "data:update" to indicate that further updates are wanted. Either that or the vehicle sends one update and then disconnects if it is parked and locked? (Would make sense - I've not yet tried streaming any data and had the vehicle in motion but I'll give that a try at some point.)

EDIT: The app does not seem to send anything in response to the "data:update", though I may have missed something. Also there are disconnections even if the vehicle is moving, but that may be due to it switching from WiFi to cell data (I'll test further and update if I find anything else.)

@ddaddy
Copy link

ddaddy commented Nov 18, 2019

I've been playing with this today and i've come to the conclusion that data:error vehicle_disconnected is a time out issue, albeit a very small timeout window.

If I connect to the stream while my car is parked, I get 1 result with data, then a couple of seconds later I get the data:error.

If i'm driving when I connect, it streams fine.

If I come to a stop, but have my heating on, it streams fine as the power(kw) keeps changing between 1 & 2 which pushes data to the stream.

If I then turn off my heater, so none of the data from the stream is changing (Same location, same speed 0, same power etc..) then a few seconds later it disconnects with the error.

I can't yet confirm if the timeout is coming from Tesla or from my code. The web socket connection is greeted with {"msg_type":"control:hello","connection_timeout":0} so I wonder if there is a control command we can send to extend the timeout, or else an alternative command we can send to keep the socket alive before timeout.

EDIT----

Timeout seems to be 10s with no data
I've tried sending all sorts of comment to ping or extend the timeout but nothing seems to give a response.

@timdorr
Copy link
Owner Author

timdorr commented Nov 19, 2019

There is a control:ping on the Summon API. You might try that.

@ddaddy
Copy link

ddaddy commented Nov 19, 2019

Yes I tried that amongst other things. I tried sending the ping every second and although it didn’t return any error, it still timed out after 10s.
The connection to the socket doesn’t close, just the subscription to vehicle data.

What works is simply sending the subscribe command again after you receive vehicle_disconnected.

@TheSpaceCowboy
Copy link

TheSpaceCowboy commented Nov 19, 2019 via email

@andrewgreenwood
Copy link

My partner is borrowing the car today for a short journey so I had an opportunity to observe the data whilst the car was being driven.

Sometimes after a vehicle_disconnected message, even subscribing again does not seem to work, so my previous suggestion might not be useful after all.

Observations:

Generally you'll get 1 or 2 messages if the car is parked and awake before it sends the vehicle_disconnected message. Certain things trigger more frequent messages to be sent (the car being in motion is the obvious one, but simply having the driver-side door open seemed to result in more frequent messages being sent.)

While the car was being driven, I'd get multiple messages per second. The car stopped at a red light and this resulted in a vehicle_disconnected after I received a message indicating its speed being 0. My script sent several subscribe messages 10 seconds apart, and after a minute gave up and reconnected. It then did not receive any messages after attempting to subscribe (on the new connection), and again sent several subscribe messages 10 seconds apart, giving up after a minute. The third connection attempt was successful and I started getting messages, however the car was already moving and had made significant progress along the road at that point.

I suspect if I had just disconnected and reconnected immediately each time upon receiving the vehicle_disconnected message, this would've worked.

@longzheng
Copy link

longzheng commented Oct 14, 2020

I want to confirm if anyone else is seeing this behaviour when using the streaming API in a third-party app like Teslamate while also using the (official) Tesla mobile app.

It appears the streaming API only supports one client at a time, which the Tesla mobile app also uses. While a third-party app is using the streaming API, the Tesla mobile app seems to have issues with the location display while the car is in motion. Frequently it would error (I assume it doesn't handle error responses well) and display the car's location in a random location on the map like in the middle of the ocean or in another continent.

For example while my car was in Melbourne, Australia, it is displayed as in the middle of the Pacific Ocean

If this is a widespread issue, I think it is worth adding some warnings to this API that it may cause issues with the Tesla mobile app.

@scadaguru
Copy link

I want to confirm if anyone else is seeing this behaviour when using the streaming API in a third-party app like Teslamate while also using the (official) Tesla mobile app.

It appears the streaming API only supports one client at a time, which the Tesla mobile app also uses. While a third-party app is using the streaming API, the Tesla mobile app seems to have issues with the location display while the car is in motion. Frequently it would error (I assume it doesn't handle error responses well) and display the car's location in a random location on the map like in the middle of the ocean or in another continent.

For example while my car was in Melbourne, Australia, it is displayed as in the middle of the Pacific Ocean

If this is a widespread issue, I think it is worth adding some warnings to this API that it may cause issues with the Tesla mobile app.

I have noticed same issue and my Android phone doesn't show real time update when my family member is driving Tesla Model 3. I am using TeslaMate which uses real time streaming I guess and that shows real time update on my computer/browser but not Tesla App on my Android phone.

@ddaddy
Copy link

ddaddy commented Oct 20, 2020

I was doing something with the streaming API the other day, and half way through the day I stopped getting any data returned from the car.
I've not been able to get any streaming data since.

I receive the

{"msg_type":"control:hello","connection_timeout":0}

handshake and send the subscribe command

{"msg_type":"data:subscribe","tag":"1305444632","token":"Base64(<email:1stToken>)","value":"speed,soc,power"}

but get absolutely nothing until it times out.
I've tried sitting in the car and messing with the AirCon, driving forwards and backwards. Nothing.

Anyone else seen this before?

@jonasman
Copy link
Contributor

jonasman commented Oct 20, 2020 via email

@ddaddy
Copy link

ddaddy commented Oct 20, 2020

Thanks.
The Tesla app seems to work fine with the correct location. I just get absolutely nothing from the socket without any changes.
I haven't had an update for a while, so hoping things aren't just stuck in the car.

@ktoonsez
Copy link

I keep seeing so many conflicting stories on this subject. Is this something that is still working, any links to something working for android or Windows (I am clueless on ruby)?

@coleged
Copy link

coleged commented Nov 11, 2020

Despite combing through others code in languages/dialects I have no experience with, but confident I've implemented the same interface (in C++) Ive seen nothing except endless {"msg_type":"control:hello","connection_timeout":0} on the streaming websocket. And just today I'm now getting a 408 on the (REST) wake_up endpoint unless I first poke the API with the Tesla app, whereas It was working a week ago

@ktoonsez
Copy link

@coleged, I got some code going today but looks like the wss stopped working due to tesla changing something or some kind of problem. I am not the only one getting the error from what I am reading, which is "Basic Auth Disabled". You get it right after you send the "subscribe" request.

@ddaddy
Copy link

ddaddy commented Nov 12, 2020

They must have shut down the basic auth. Send the oauth header instead #97 (comment)

@timdorr timdorr pinned this issue Jan 31, 2021
Repository owner deleted a comment from ddaddy Mar 29, 2021
Repository owner deleted a comment from ddaddy Mar 29, 2021
Repository owner deleted a comment from ddaddy Mar 29, 2021
Repository owner deleted a comment from IMgoRt Mar 29, 2021
Repository owner deleted a comment from ddaddy Mar 29, 2021
Repository owner deleted a comment from ddaddy Mar 29, 2021
Repository owner deleted a comment from jdemeyer1 Mar 29, 2021
Repository owner deleted a comment from akramaskar May 1, 2021
@TeslaOwnerTips
Copy link

@timdorr what is the current status of the streaming API? I’m using python and would appreciate some pointers on where to start.

@mloyd
Copy link

mloyd commented Jul 14, 2022

While there is support in the Ruby code for the Streaming API, the docs are completely empty. We should fix that by filling them in. Anyone want to help?

Forked. I'll work on it in the next week or so. This might help some in the mean time.

@TeslaOwnerTips
Copy link

@mloyd
Am I correct in understanding that streaming does not hang up while moving and charging? Or is it only while moving?
Is it the speed or is it data charging such as the gps coordinates? So for example if it was on a moving transport it would stream.

@itsMeDavidV
Copy link

itsMeDavidV commented Jul 14, 2022

So for example if it was on a moving transport it would stream.

@TeslaOwnerTips I believe there is a transport mode, so streaming might be stopped in this particular case.

@TeslaOwnerTips
Copy link

@itsMeDavidV okay bad example. My point was in his notes which @mloyd linked to he says parked in the driveway there won't be streaming. I'm trying to get at what the real technical criteria is: zero speed, in park, gps coordinates static etc.

@cguedel
Copy link

cguedel commented Jul 14, 2022

As far as I have seen, the criteria seems to be "something changing". E.g. speed, power consumption, gps and so on.

Edit: for more details, i have seen my car stopped at a red light stopping streaming when the A/C is off (i.e. the power draw is minimal at that point). However, if the A/C is on and/or speed of A/C varies, the connection stays open as long as there is a regular change in the power consumption at the red light, even though speed is always 0.

@itsMeDavidV
Copy link

@TeslaOwnerTips I'd imagine it's dependent on speed per the linked notes:

You'll notice when the car is in motion (assuming good network connectivity, etc), you'll get a record every ~250ms. But as you roll up to a stop light, that starts to taper off. When stopped at a stop light, the stream of data ends and Tesla will eventually hang-up on your websocket.

GPS coordinates would be less accurate than speed and you'd prob still be in Drive at a stop light (though "Hold" could be a criteria in addition to Park). It also seems record intervals are determined by speed. So prob leaning towards speed here.

@mloyd
Copy link

mloyd commented Jul 15, 2022

Good questions. I'll present a scenario from one of my recent drives. See data from log file at the end. I'll include more examples like this in the PR for the documentation.

@TeslaOwnerTips - to your question specifically, the likely scenario transport service provider will put the vehicle in service mode. When that happens, any call to vehicle_data or similar endpoint will fail. If that's a situation you'll need to handle,... you might want to try a GPS tracker or some other mechanism.

General comments about the sample

  • This is a situation where I approach a red light and stop. When it turns green, I turn left and continue the drive. The last few lines of the log cover me coming out of the turn. A visual is also attached below.
  • The difference between the timestamp reported in the websocket record (e.g. 1657180284438 for the 1st record) is roughly 300-350 milliseconds ahead of the log file timestamp at the start of each log line.
  • In most cases, each subsequent record is received almost exactly 250 milliseconds after the record before it.
  • As data readers of the websocket, regardless if it's carson, tesla-api, whoever, we do not have control over the velocity of the data. We simply subscribe and read/handle records as they are fed to us.

Lines 24 - 26

  • I'm coming to a stop. Line 24 says my speed is 1 mph. Line 25 is the first reported record where my speed is 0. Am I really at 0 mph? Dunno. The next record, line 26 is not at its usual 250 milliseconds. Instead, it's exactly 500 milliseconds (according to the timestamp in the record itself, not the log timestamp).
  • Maybe I was going < 0.5 mph. Or maybe the accuracy on the car's GPS was resolved to a better certainty yielding a longitude of -96.619813 instead of -96.619814 on the record before it.
  • This is just a guess (I haven't calculated this), but I'm assuming since there was a change in longitude, it was enough for their system to report a coursing change from 267 deg to 266 deg.
  • Take note of line 26's lat/lon of 33.175984,-96.619813. I'll reference this later.

Line 27

  • Exactly ten seconds later, a disconnect occurs. This is a characteristic of carson. I had experienced situations where longer wait times at a light would never wake back up. Either Tesla simply stopped talking or there was something stuck in a buffer somewhere, I couldn't read any more data from the socket, despite having continued the drive which should have sent more data.
  • Given the ten second timeout, you'll see a new websocket connection was established.

Line 30

  • First record received since subscribed on new websocket.
  • The timestamp reported in the record (again, not the log timestamp) is somewhere between 10.9 and 11.0 seconds since the last record received before the timeout.
  • Remember on line 26 I said to note lat/lon values of 33.175984,-96.619813? Notice the values here on line 30? Hold that thought...

Lines 31 - 32

  • The timestamp in the record on line 31 is 9.001 seconds after value reported on line 30. But line 32 is back to a familiar 250 millisecon interval.
  • Still at the light. Stopped. Only difference appears to be power output increased from 2 on line 30 to 3 and 7 for lines 31 and 32 respectively.

Lines 33 - 35

  • Looks like I'm moving again. You can see my speed increased to 5 mph. Getting consistent 250 millisecond intervals again.
  • Okay, we need to talk... notice lat/lon is still 33.175984,-96.619813! ... the heck?

So...

I had assumed for a while, you probably noticed this too, the same heading, coursing, lat, and lon values are reported in what appear to be batches of four. It sounds very reasonable to me that the car's GPS unit only reports on 1HZ frequency. That's fine. But this doesn't explain the incongruency between lines 26 and 35 where clearly speed/power values are changing. You can't blame a lame/stale socket buffer because we tore it down and established a new connection entirely.

The point of all of that is simply to highlight this is for recreational use only. You'll probably need to write your own patterns for what you are trying to achieve by using this data. Let's document the basics (I'm working on a PR and will submit to Tim if he thinks any of this has value). But it's unlikely you'll get a one-size-fits-all implementation out of any library, regardless of the language/interface. Data doesn't lie, unless the data is lying or has already lied. And this isn't autopilot or black box data. Personally, I'm grateful Tesla has allowed us to geek-out on the data we have.

#  Line
01 2022-07-07 00:51:24,764 D cruiser  b'1657180284438,27,17195.7,68,169,270,33.175982,-96.619492,-50,D,235,245,271'
02 2022-07-07 00:51:25,009 D cruiser  b'1657180284688,26,17195.7,68,169,270,33.175982,-96.619492,-48,D,235,245,271'
03 2022-07-07 00:51:25,264 D cruiser  b'1657180284938,25,17195.7,68,169,271,33.175985,-96.619613,-45,D,235,245,271'
04 2022-07-07 00:51:25,515 D cruiser  b'1657180285188,23,17195.7,68,169,271,33.175985,-96.619613,-43,D,235,245,271'
05 2022-07-07 00:51:25,764 D cruiser  b'1657180285438,22,17195.7,68,169,271,33.175985,-96.619613,-40,D,235,245,271'
06 2022-07-07 00:51:26,014 D cruiser  b'1657180285688,20,17195.7,68,169,271,33.175985,-96.619613,-36,D,235,245,271'
07 2022-07-07 00:51:26,264 D cruiser  b'1657180285938,19,17195.7,68,169,271,33.175987,-96.619714,-33,D,235,245,271'
08 2022-07-07 00:51:26,514 D cruiser  b'1657180286188,17,17195.7,68,169,271,33.175987,-96.619714,-30,D,235,245,271'
09 2022-07-07 00:51:26,764 D cruiser  b'1657180286438,16,17195.7,68,169,271,33.175987,-96.619714,-27,D,235,245,271'
10 2022-07-07 00:51:27,014 D cruiser  b'1657180286689,14,17195.7,68,169,271,33.175987,-96.619714,-24,D,235,245,271'
11 2022-07-07 00:51:27,264 D cruiser  b'1657180286938,13,17195.7,68,169,270,33.175988,-96.619778,-21,D,235,245,271'
12 2022-07-07 00:51:27,514 D cruiser  b'1657180287188,11,17195.7,68,169,270,33.175988,-96.619778,-18,D,235,245,271'
13 2022-07-07 00:51:27,766 D cruiser  b'1657180287438,10,17195.7,68,169,270,33.175988,-96.619778,-15,D,235,245,271'
14 2022-07-07 00:51:28,014 D cruiser  b'1657180287688,8,17195.7,68,169,270,33.175988,-96.619778,-12,D,235,245,271'
15 2022-07-07 00:51:28,264 D cruiser  b'1657180287939,7,17195.7,68,169,268,33.175987,-96.619809,-10,D,235,245,270'
16 2022-07-07 00:51:28,515 D cruiser  b'1657180288188,5,17195.7,68,169,268,33.175987,-96.619809,-7,D,235,245,270' 
17 2022-07-07 00:51:28,764 D cruiser  b'1657180288438,4,17195.7,68,169,268,33.175987,-96.619809,-3,D,235,245,270' 
18 2022-07-07 00:51:29,014 D cruiser  b'1657180288688,3,17195.7,68,169,268,33.175987,-96.619809,-1,D,235,245,270' 
19 2022-07-07 00:51:29,265 D cruiser  b'1657180288938,2,17195.7,68,169,266,33.175985,-96.619818,0,D,235,245,268'  
20 2022-07-07 00:51:29,514 D cruiser  b'1657180289188,2,17195.7,68,169,266,33.175985,-96.619818,1,D,235,245,268'  
21 2022-07-07 00:51:29,764 D cruiser  b'1657180289439,1,17195.7,68,169,266,33.175985,-96.619818,1,D,235,245,268'  
22 2022-07-07 00:51:30,014 D cruiser  b'1657180289688,1,17195.7,68,169,266,33.175985,-96.619818,2,D,235,245,268'  
23 2022-07-07 00:51:30,264 D cruiser  b'1657180289939,1,17195.7,68,169,266,33.175984,-96.619814,2,D,235,245,267'  
24 2022-07-07 00:51:30,514 D cruiser  b'1657180290188,1,17195.7,68,169,266,33.175984,-96.619814,2,D,235,245,267'  
25 2022-07-07 00:51:30,764 D cruiser  b'1657180290438,0,17195.7,68,169,266,33.175984,-96.619814,2,D,235,245,267'  
26 2022-07-07 00:51:31,284 D cruiser  b'1657180290938,0,17195.7,68,169,266,33.175984,-96.619813,2,D,235,245,266'  
27 2022-07-07 00:51:41,284 I cruiser  Disconnected. timeouts=17 disconnects=13 msg_count=6759 waypoints=6759 msg={'msg_type': 'data:error', 'tag': '25...90', 'value': 'disconnected', 'error_type': 'vehicle_disconnected'}
28 2022-07-07 00:51:41,981 I cruiser  Starting stream loop #31. Vehicle('photon' state='online' id=12...89 is_user_present=True miles=17,195 software='2022.12.3.20' battery_level=68 charging_state='Disconnected' shift_state='D' speed=0)
29 2022-07-07 00:51:41,982 D cruiser  subscribe='{"msg_type":"data:subscribe_oauth","token":"abc...xyz","value":"speed,odometer,soc,elevation,est_heading,est_lat,est_lng,power,shift_state,range,est_range,heading","tag":"25...90"}'
30 2022-07-07 00:51:42,847 D cruiser  b'1657180301861,0,17195.7,68,169,266,33.175984,-96.619813,2,D,235,245,266'
31 2022-07-07 00:51:51,184 D cruiser  b'1657180310862,0,17195.7,68,169,266,33.175984,-96.619813,3,D,235,245,266'
32 2022-07-07 00:51:51,434 D cruiser  b'1657180311112,0,17195.7,68,169,266,33.175984,-96.619813,7,D,235,245,266'
33 2022-07-07 00:51:51,684 D cruiser  b'1657180311362,2,17195.7,68,169,266,33.175984,-96.619813,12,D,235,245,266'
34 2022-07-07 00:51:51,934 D cruiser  b'1657180311612,3,17195.7,68,169,266,33.175984,-96.619813,19,D,235,245,266'
35 2022-07-07 00:51:52,184 D cruiser  b'1657180311862,5,17195.7,68,169,266,33.175984,-96.619813,25,D,235,245,266'
36 2022-07-07 00:51:52,435 D cruiser  b'1657180312112,7,17195.7,68,169,266,33.175984,-96.619819,30,D,235,245,266'
37 2022-07-07 00:51:52,685 D cruiser  b'1657180312362,8,17195.7,68,169,266,33.175984,-96.619819,33,D,235,245,266'
38 2022-07-07 00:51:52,934 D cruiser  b'1657180312612,10,17195.7,68,169,266,33.175984,-96.619819,37,D,235,245,266'
39 2022-07-07 00:51:53,184 D cruiser  b'1657180312862,12,17195.7,68,169,266,33.175984,-96.619819,44,D,235,245,266'
40 2022-07-07 00:51:53,435 D cruiser  b'1657180313112,13,17195.7,68,169,264,33.175981,-96.619860,54,D,235,245,266'
41 2022-07-07 00:51:53,684 D cruiser  b'1657180313362,15,17195.7,68,169,264,33.175981,-96.619860,58,D,235,245,266'
42 2022-07-07 00:51:53,934 D cruiser  b'1657180313612,16,17195.7,68,169,264,33.175981,-96.619860,35,D,235,245,266'
43 2022-07-07 00:51:54,185 D cruiser  b'1657180313862,17,17195.7,68,169,264,33.175981,-96.619860,24,D,235,245,266'
44 2022-07-07 00:51:54,434 D cruiser  b'1657180314112,18,17195.7,68,168,260,33.175971,-96.619938,22,D,235,245,264'
45 2022-07-07 00:51:54,684 D cruiser  b'1657180314362,19,17195.7,68,168,260,33.175971,-96.619938,22,D,235,245,264'
46 2022-07-07 00:51:55,177 D cruiser  b'1657180314862,20,17195.7,68,168,260,33.175971,-96.619938,22,D,235,245,264'
47 2022-07-07 00:51:55,427 D cruiser  b'1657180315112,20,17195.7,68,168,252,33.175950,-96.620034,23,D,235,245,260'
48 2022-07-07 00:51:55,681 D cruiser  b'1657180315362,21,17195.7,68,168,252,33.175950,-96.620034,39,D,235,245,260'
49 2022-07-07 00:51:55,934 D cruiser  b'1657180315612,22,17195.7,68,168,252,33.175950,-96.620034,45,D,235,245,260'
50 2022-07-07 00:51:56,185 D cruiser  b'1657180315862,23,17195.7,68,168,252,33.175950,-96.620034,38,D,235,245,260'
51 2022-07-07 00:51:56,422 D cruiser  b'1657180316112,23,17195.7,68,168,240,33.175913,-96.620131,20,D,235,245,260'
52 2022-07-07 00:51:56,684 D cruiser  b'1657180316362,24,17195.7,68,168,240,33.175913,-96.620131,17,D,235,245,260'
53 2022-07-07 00:51:56,934 D cruiser  b'1657180316612,24,17195.7,68,168,240,33.175913,-96.620131,31,D,235,245,260'
54 2022-07-07 00:51:57,184 D cruiser  b'1657180316862,25,17195.7,68,168,240,33.175913,-96.620131,44,D,235,245,260'
55 2022-07-07 00:51:57,442 D cruiser  b'1657180317112,26,17195.7,68,168,229,33.175875,-96.620173,57,D,235,245,253'
56 2022-07-07 00:51:57,685 D cruiser  b'1657180317362,27,17195.7,68,168,229,33.175875,-96.620173,65,D,235,245,253'
57 2022-07-07 00:51:57,936 D cruiser  b'1657180317612,28,17195.7,68,168,229,33.175875,-96.620173,69,D,235,245,253'
58 2022-07-07 00:51:58,172 D cruiser  b'1657180317862,29,17195.7,68,168,229,33.175875,-96.620173,71,D,235,245,253'
59 2022-07-07 00:51:58,422 D cruiser  b'1657180318112,30,17195.7,68,167,212,33.175773,-96.620270,73,D,235,245,226'
60 2022-07-07 00:51:58,673 D cruiser  b'1657180318362,32,17195.7,68,167,212,33.175773,-96.620270,75,D,235,245,226'
61 2022-07-07 00:51:58,927 D cruiser  b'1657180318612,33,17195.7,68,167,212,33.175773,-96.620270,75,D,235,245,226'
62 2022-07-07 00:51:59,184 D cruiser  b'1657180318862,34,17195.7,68,167,212,33.175773,-96.620270,69,D,235,245,226'
63 2022-07-07 00:51:59,434 D cruiser  b'1657180319114,35,17195.7,68,167,203,33.175635,-96.620357,69,D,235,245,213'
64 2022-07-07 00:51:59,684 D cruiser  b'1657180319362,35,17195.7,68,167,203,33.175635,-96.620357,71,D,235,245,213'
65 2022-07-07 00:51:59,935 D cruiser  b'1657180319612,36,17195.7,68,167,203,33.175635,-96.620357,73,D,235,245,213'

image

@TeslaOwnerTips
Copy link

@mloyd thank you for your hard work on this.

So we need FSD to become street legal so that we can sit in the car to code and debug while in motion 😂 or wait for our significant other to go for a drive 😀

Personally I'm interested in streaming to see if a pi zero with a relay could be used to open the garage door for me when my Tesla gets close enough. I'm currently using our arrival home on Apple Home which works quite well. It also opens the garage door when we come home from a walk but I changed my habits to use the garage door to enter the house. I've tried BLE devices as well. I've also tried a dedicated iPod Touch placed in the car but I need to get back to that since I didn't debug why it didn't work.

@GaPhi
Copy link
Contributor

GaPhi commented Jul 15, 2022 via email

@Urkman
Copy link

Urkman commented Jan 11, 2023

I also try to use the Streaming API.
I send this data to authenticate:

{
   "msg_type": "data:subscribe_oauth",   
    "token": "eyJh...", // access_token from login
    "value": "speed,odometer,soc,elevation,est_heading,est_lat,est_lng,power,shift_state,range,est_range,heading",
    "tag": "9296..." // my vehicle_id
}

But I always get a 403 back :( :

{
    "msg_type":"data:error",
    "tag":"9296...",
    "value":"owner_api error: `Got HTTP status: 403 Forbidden for . Response: {\"response\":\"unauthorized\"}`",
    "error_type":"client_error"
}

Any ideas why this happens?

@Urkman
Copy link

Urkman commented Jan 11, 2023

arrrggg... Found it...
It's not the vehicle.id that we need for the API Requests, it's the vehicle_id...

@Urkman
Copy link

Urkman commented Jan 23, 2023

Is here some actually using the streaming API, because I have some questions...

It seems, that the streaming API is just for driving and charging, right?

1.) Detect the state:

I detect, that the car is driving, when the shift state is != nil.
I detect, that the car is charging, when shift state is == nil and power is < 0.
Is this correct?

2.) About when to connect to the streaming?

When the car goes to sleep, the WebSocket closes.
How do you decide, when to reopen the connection?

3.) Is it for charging?

When Charging, after some time the API stops senden data. So perhaps, the streaming API is just for driving?

4.) What data does the streaming API offer?

Can I request more data than this: speed,odometer,soc,elevation,est_heading,est_lat,est_lng,power,shift_state,range,est_range,heading

Thanks for you help :)

@jdemeyer1
Copy link

Hello @Urkman!

The streaming code is an example of how to get streaming up and running. As you pointed out, it would require additional code to detect specific states of the vehicle's operation.
In my experience, Tesla stops streaming when there is no change in the streaming data. I've seen the streaming stop when the vehicle remains at a stop light for longer than 10 seconds. Additional code is required to determine if the streaming should start again.

I wrote my streaming in Java based on this model. I implemented a state machine to accommodate vehicle operation while driving. I found it both complex and rewarding to develop. It is still not perfect.

Joe

@Urkman
Copy link

Urkman commented Jan 27, 2023

Hello @jdemeyer1

Thanks for your answer :)

I experience the same with stops in the streaming data. But not only when standing at s stop light. It also happens in mid drive :( See my first screenshot, there it stop at 40 km/h... And don't resume till the end of the drive.
But in another drives, it stop for some time and then resumes after some time by itself. See second screenshot for this...

Now my question:
How do you handle this? Do you reconnect after some time or is there a message I can send to the WebSocket to resume?
I think, there we need a reconnect... I would try something like this: If I'm driving and don't get an for let's say 5 seconds, then I try to reconnect...

What do you think?

Bildschirm­foto 2023-01-27 um 10 49 27

Bildschirm­foto 2023-01-27 um 11 00 06

@jdemeyer1
Copy link

Hello @Urkman!

I have also seen the streaming stop while driving. When that happens, the socket receives data:error message. I start a timer that waits 20 seconds before attempting to subscribe again.

If there is no response, I wait 60 seconds and try again. If there is no response, I wait 80 seconds and try again. If there is no response, I close the socket.

This generates an onStateChange event on the socket where I disconnect from the socket. This generates an onDisconnect event on the socket where I set the socket object to null and create another socket object. Everything starts again on the new socket.

It is a lot of messing around but usually, the socket responds after the first attempt to subscribe. Open to suggestions for simplifying the error recovery process. I have read somewhere that waiting to reconnect is the best method to start the subscription again. I have been using a third-party socket implementation that I would like to simplify but I have been distracted by other projects.

Joe

@carlos-443-diaz
Copy link

Curious if the disconnects are from network issues between cell towers. The behavior may change when connected to mobile hotspot. Without more detail on how the output signals are generated, we're all literally just (intelligent-ish-ly?) guessing. We only get to see the outputs after all.

@timdorr timdorr unpinned this issue Mar 28, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests