Welcome to Tesla Motors Club
Discuss Tesla's Model S, Model 3, Model X, Model Y, Cybertruck, Roadster and More.
Register

Model S REST API

This site may earn commission on affiliate links.
A question: It looks like the API, as documented by this group, only covers the functions exposed in the phone app at this point. I am wondering if there might be other functions that could be probed for by those who have built robots for the purpose. In particular, it would be cool if there was a way to remotely change charging current. Has anyone looked at that? Any other guesses people are pursuing?

Well, the previous couple of pages discuss my guess about set_charge_limit and then brianman trying to find the charging current API. All guesses are welcome - it's just hard to do anything better than throwing a bunch of random words at the API and see what returns an error and what doesn't.
 
Thanks for verifying that. My code is based on streaming.js so I clearly "improved" it in a creative way. I need to compare what I have now to your original and see where I went wrong. Maybe the reauthentication after 15 minutes is what fails... I need to look at the timestamps in my log file but that sounds about right.
In case someone else trips over this... it appears that the streaming API sometimes sends older data sets again - i.e. I get data with a timestamp that is older than data I had already seen. This confused my algorithm. Now that I'm no longer making assumptions that timestamps are monotonous it appears that it reauthenticates as designed.
 
In case someone else trips over this... it appears that the streaming API sometimes sends older data sets again - i.e. I get data with a timestamp that is older than data I had already seen. This confused my algorithm. Now that I'm no longer making assumptions that timestamps are monotonous it appears that it reauthenticates as designed.

This is from memory from a month ago so verify it for accuracy ;-) If you complete the full 120 second HTTP long poll you get a new timestamp each time. If you terminate the HTTP session early from your client side app and then try polling again you will get the same old timestamp you got on the previous poll. I think you will get it over and over again for up to 5 minutes or so if I remember correctly.

P.S. I wish they would just use websockets or MQTT or something, anything better and more pubsub or connection oriented than COMET/Long Polling. Lowest common denominator wins again I guess.
 
In case someone else trips over this... it appears that the streaming API sometimes sends older data sets again - i.e. I get data with a timestamp that is older than data I had already seen. This confused my algorithm. Now that I'm no longer making assumptions that timestamps are monotonous it appears that it reauthenticates as designed.
I've never observed this problem in my data files.
 
I've never observed this problem in my data files.
That's strange. I get them all the time. And not only when canceling the http poll as hans suggests above. Also, I get missing segments (there will be something like 10-30 seconds with no data whatsoever...)
I guess I should run the streaming.js in parallel with my app to see if we get the same data... since I'm an absolute JS newbie I wouldn't be surprised at all if there were tons of bugs hiding in my code.
 
Sorry if this is a stupid question, but I how does the streaming API work ? I got the REST API to run in C# but I assume streaming is a kind of open socket connection where I have to listen on server server sending me data ?

Can anybody post some .NET code ?
 
This is from memory from a month ago so verify it for accuracy ;-) If you complete the full 120 second HTTP long poll you get a new timestamp each time. If you terminate the HTTP session early from your client side app and then try polling again you will get the same old timestamp you got on the previous poll. I think you will get it over and over again for up to 5 minutes or so if I remember correctly.

P.S. I wish they would just use websockets or MQTT or something, anything better and more pubsub or connection oriented than COMET/Long Polling. Lowest common denominator wins again I guess.

Tesla's streaming service doesn't send the proper no-cache http headers in the response, so if using straight http gets, your client should cache the responses so you'll get duplicate data. One workaround for this is to add something unique to the querystring that tesla will ignore.
The other WindowsPhone issue with out of memory exceptions, the workaround is to set the connection timeout to less than 60 seconds. I don't have access to the source at the moment to remember what exactly I did for these 2 in my app
 
I now have split my tool into two parts and things are working much better.
The backend is a small modification to streaming.js that stores all the data sets in a mongodb instead of in a flat file.
The frontend uses node.js to create a web server and Google maps to visualize the data in the database. It can replay past driving or show the life diving with automatic (AJAX) updates to the map.

Besides the data that the streaming API is giving us, what other information do people store about their cars? One could poll temperature data for example... So I wonder what others are doing.

Hans - are you interested in pull requests to add this to your project, or should I turn it into a separate project?
 
I now have split my tool into two parts and things are working much better.
The backend is a small modification to streaming.js that stores all the data sets in a mongodb instead of in a flat file.
The frontend uses node.js to create a web server and Google maps to visualize the data in the database. It can replay past driving or show the life diving with automatic (AJAX) updates to the map.

Besides the data that the streaming API is giving us, what other information do people store about their cars? One could poll temperature data for example... So I wonder what others are doing.

Hans - are you interested in pull requests to add this to your project, or should I turn it into a separate project?

Sounds great dirkhh! I would be happy to incorporate your stuff into the existing project. I didn't start it to be "my" project anyway so the more contributors the better.
 
Sounds great dirkhh! I would be happy to incorporate your stuff into the existing project. I didn't start it to be "my" project anyway so the more contributors the better.
Looking at integrating things into streaming.js I ran into a slight problem...
You use request(...).pipe(fs.createWriteStream( argv.file, {'flags': 'a'} )) to directly pipe things into the output file.
I need to use request(...).on('data', function(data){...}) to write things into the database.
I don't know JS well enough to know how to switch between those two without a ton of code duplication. My guess is that the .pipe() could be reimplemented as .on('data',...) - but I don't know exactly how and I don't know if you'd like this.

The alternative would of course be to simply add my file as a new JS file in the repository, but since most of it is identical to the existing file that seems like a waste as well...

Any advice?
 
I just received my car today and started digging around!

I found some extra option code values that are not documented as far as I can tell.

I took my best guess as to what they could mean.

Code:
[FONT=Times]PK00, (parking sensors)[/FONT]
[FONT=Times]CW00, (cold weather package)[/FONT]
[FONT=Times]SP00, (security protection??)[/FONT]
[FONT=Times]YF00, (???)[/FONT]
[FONT=Times]X009, (???)[/FONT]
[FONT=Times]X027, (???)[/FONT]
[FONT=Times]X031, (???)[/FONT]
[FONT=Times]BS00 (???)
[/FONT]
 
Newbie question: Does the car stream its data to the Tesla servers all the time, or only in response to a query initiation?
Strictly speaking this isn't "known" but based on the API surface area and behavior, it appears that it isn't streaming until requested and then it times out (stops streaming) every 15-30 minutes until a new request is sent.