Unofficial documentation of the Tesla Model S REST API
github.com
github.com
This was discovered via the Android app in particular: https://play.google.com/store/apps/details?id=com.teslamotor...
I did some sniffing on the traffic, which is SSL encrypted, but luckily it's pretty easy to install your own CA in Android 4.1+.
They have both a Rails app and a nodejs server. The nodejs server is for live streaming car location and driving metrics. I haven't gotten that documented yet (but I'm accepting pull requests!), but some people have already been making use of it: http://www.teslamotorsclub.com/showthread.php/13410-Model-S-...
One guy already has his Model S tweeting: https://twitter.com/pureamps
http://appworld.blackberry.com/webstore/content/23977878/?co...
How does it get updated? An attacker can at least unlock the doors or drain the battery (lights & HVAC control), and possibly it is an entry point for something much worse (unlocking & starting, or disabling controls while enroute). Is this a major security flaw or am I just spreading FUD?
(At least honking the horn doesn't incur permanent state change; unlocking the doors is obviously not safe.)
Edit: idempotency vs safety... I knew I was being stupid.
Always treat mechanical devices in a non-deterministic fashion.
Salesmen have to remind every new customer about this, since sooner or later someone locks themself or someone else in the car and the remote has walked away...
There are techniques to monitor the health of the switch and know when the sensor is failing/has failed. THEN you can whack the solenoid to your heart's content if you believe the sensor is damaged. But if you have a working sensor, there's no need to overstress the solenoid and mechanical linkage.
But if you're locking/unlocking your car over the internet with this funky API and want to be sure it's locked, how do you do it? You don't hit the solenoid 20 times and say "well, good enough".
Wait, perhaps I am understanding it wrong, but if I were to consider a lock sensor as non-deterministic, wouldn't that imply that I always have to send the unlock signal, regardless of lock state, because you don't trust the sensor?
You do not trust that because your boolean in RAM says "locked" that the door is locked.
Now whether you trust the sensor to be functional or not is another story.
It doesn't matter how many times you apply the 'unlock' operation, it has the same effect as applying it once[1]. However, the 'unlock' operation is not safe[2].
Ultimately, I decided that I'm unlikely to lose the key. But I don't like the idea that someone could still scan the parking lot, unlocking cars by radio.
Opening up more data/control wirelessly isn't necessarily a good thing. You CERTAINLY don't want someone to be able to make your car segfault while you're driving down the highway.
That could make for a great scene in some futuristic hacker movie.
On a more serious note, there are many possible solutions to the problem of losing a wireless car entry key. Off the top of my head:
1) Have the user tap out a simple rhythm with the button to unlock the car. Downsides: kind of involved and the rhythm would have to be long to be secure.
2) Put a fingerprint scanner on the key. The one in my laptop is a tiny self-contained module, so I expect it to be possible to fit one inside a wireless car key. Downsides: the scanner can break; can't use in gloves.
3) Have the cars mesh network to detect the "trawling for the right car with a key" behavior. Downsides: complexity; the thief could exploit this to lock you out of your own car.
4) Make the key a wristwatch or a wristband. I think this is the best cheap solution. Downsides: might disagree with your fashion sense.
Or, on the other hand, it's a zen koan. If a car honks in a parking garage and no-one is there to hear it, has it even made a sound?
A RESTful API is more than just using GET to access resources.
[1] http://en.wikipedia.org/wiki/Resource-oriented_architecture
Exampe: POST {"state": "unlocked} to http://doors/front-left/lock
I realize I don't understand this, so your comment, and any further points you have, are sincerely appreciated.
You would GET the lock to see if it's locked, GET the battery to read its charging state.
You could PUT to the battery (or to some more abstract, finer-grained resources) to set the charge mode and turn charging on and off. The HVAC and thermostat would work the same way.
The only tricky stuff is "flash lights" and "honk horn"; they're inherently commands, so you might as well implement them in the RPC style that Tesla has used. They can't benefit from anything REST has to offer anyways.
And as you say, since certain aspects of the API (like honk horn) are unfit for REST, does it make sense to have the other parts of the API in REST? And then you've have two API's at once?
Then you need to have another resource that encompasses the aspects that need to be changed. Sometimes resources have to be somewhat abstract.
> since certain aspects of the API (like honk horn) are unfit for REST, does it make sense to have the other parts of the API in REST?
If the application benefits from the constraints that REST provides then why wouldn't it make sense? It's still one API, "honk" and "flash" don't need to be walled off from the other elements of the API in any way.
It would be better if people just said "HTTP" when they mean "REST," but that's a long shot.
It's absolutely vulnerable to XSRF with cookie only authentication. This is a huge security issue.
>which provides diagnostic and maintenance data according to a standardized format.
Except the values you get won't make any sense outside of your particular model. Its like reading SMART data from a hard drive. Okay, you can generate this csv and have all this data, but without the manufacturer telling what thresholds matter (and these are arguable), its kinda meaningless. SMART was supposed to predict failures and do all sorts of things, but its kind useless in practice. I think most controllers just stupidly rely on bad blocks appearing than trying to interpret the tea leaves of SMART data.
With OBD systems, all this information is internal and we get a fault code when we pass a certain threshold. I think this makes it a lot easier for mechanics and lay people to work with. Data addicts, of course, will never be satisfied unless they can pull every bit out of the system, but that may not be practical or useful. I could see a hybrid system where a car has the old fashioned OBD2 protocol and something else for nerds to download.
I know exactly what you mean. Through random forum postings I found which index my SSD uses for "wear level", only nobody knows what the units are or what they mean.
Even 'simple' CAN protocols, like J1939 used in trucks/agri/marine, are purposely non-standard. It's rather annoying.
I'm curious as to what systems will emerge from Mercedes/VW/BMW (and I guess Google) as more high speed sources like LiDAR, active dampening, etc become the norm. The current BMW 5/7 series and Mercedes' S-class already have separate CAN-like systems for high speed buses.
Also, check out OBDII protocol each car after 1996 implements it up to a certain weight. This is the data available: http://en.wikipedia.org/wiki/OBD-II_PIDs.
Basically there is a way to gather fuel usage, fuel levels, speed, Mass Air Flow Rate, rpm, etc etc. Adding accelerometer and GPS to the mix pretty much gives you a decent start to the vehicle analytics platform.
On heavy vehicles or if you want more data on light duty, tapping into CAN is the only way, but that can get very manufacturer specific...
[1] http://www.mp3car.com/engine-management-obd-ii-engine-diagno...
[2] http://www.canbushack.com/blog/index.php?title=oh-no-odomete...
https://play.google.com/store/apps/details?id=org.prowl.torq...
https://itunes.apple.com/ie/app/dashcommand-obd-ii-gauge-das...
http://www.devtoaster.com/products/rev/
Some of these are massively overpriced, but they are useful looking.
If I had a bit of cash I'd consider putting a 7" Android tablet into the dash (you'd need a double DIN slot) and install the torque app, with a custom moulded surround to make it look stock. Live engine data to satisfy your inner nerd!
Another nerdier but cheaper route is to use Arduino with ELM interpreter: http://www.cs.purdue.edu/homes/millerrv/Ryan_Miller/Projects...
Now that I think about it I'm sure it's not the only car with this, but I didn't realize before
- Wish it used OAuth or some other revocable token mechanism. What if I lose my device? Sell the car? Get a divorce? etc..
- GET for things that change state? Looks like these are all idempotent, so they should be PUT.
- Versioning might be nice. :)
Still, progress! Clean API over HTTP that returns easy-to-parse JSON for a car = win.
All Model S's come with 3 months of cell service and they will be offering data plans shortly. It's running on AT&T, so we should be able to add it to Mobile Share plans (which I plan to do).
/T-Mobile user
They did however say that you'll be able to tether a phone with a data connection to the car via USB to avoid paying a subscription for the car.
/vehicles/{id}/command/door_unlock
I'm honestly surprised that criminal organizations haven't paid/coerced engineers working how to steal certain cars using a remote control, because I'm pretty certain that with some effort, it's possible.