TMC is an independent, primarily volunteer organization that relies on ad revenue to cover its operating costs. Please consider whitelisting TMC on your ad blocker and becoming a Supporting Member. For more info: Support TMC

Model S REST API

Discussion in 'Model S: User Interface' started by timdorr, Feb 2, 2013.

  1. widodh

    widodh Model S 85 and 100D

    Joined:
    Jan 23, 2011
    Messages:
    6,062
    Location:
    Middelburg, The Netherlands
    I'm working on a PHP-class which can do some cool stuff.

    Although I don't have a car yet, the API seems very straight forward, so just some cURL magic in a PHP class should get you going pretty quickly.

    I'm not so driven with JavaScript, so doing some UI stuff isn't that easy.

    Tesla would be very cool if they kept the API up and just placed a rate limiter should people start hammering it.
     
  2. aviators99

    aviators99 Model S - R140

    Joined:
    Jan 1, 2010
    Messages:
    1,458
    Location:
    Weston, Florida, United States
    curl --cookie cookie.jar -c cookie.jar -k "https://portal.vn.teslamotors.com/vehicles/xxx/command/charge_start"
     
  3. ahimberg

    ahimberg Member

    Joined:
    Aug 8, 2010
    Messages:
    349
    Location:
    Woodinville, WA
    slight annoyance for Windows store (& WindowsPhone) apps -- they do not have access to cookie data that is httponly, which the auth sessions cookies are.
    That means restarting the app will always have to login again and not be able to make use of the 3month cookie session timeout. That's good if you're worried about changing your password not being reflected fast enough by the app, bad in the app is a little slower after every restart (and Tesla's login server has a handle a little more traffic).

    I originally hoped to not need to save a password and just the cookie (even though they're basically the same security wise so the cookie would still need to be secured if saved), and force the user to re-enter the pw every 3 months. Instead I do have to store the password, but just like the cookie would have needed to be, encrypt it in local storage with the per-application-install-session encryption key, so someone can't dump isostore off your phone and see it.
     
  4. PureAmps

    PureAmps Model S P85 (#2817)

    Joined:
    Oct 22, 2012
    Messages:
    359
    Location:
    SF Bay Area
    Decoding Vehicle Option Codes

    The JSON description for the vehicle returns a list of "option_codes". They may or may not be useful, but I was trying to decipher them. The list for my car was "MS01,RENA,TM00,DRLH,PF01,BT85,PMMB,RFBC,WT21,IDOG,IZMT,TR00,SU01,SC01,TP01,AU01,CH00,HP00,PA01,PS01,AD02,X024,X001,X003,X007,X011,X013,X021".

    The codes all seem to be 4-digits, where the first two digits are the code "type", and the last two digits are the "value". They seem to be using a value of "00" and "01" for boolean values.

    So far my interpretation is:

    • MS01 - Model S - true
    • RENA - ??
    • TM00 - Tesla Motors owned vehicle?
    • DRLH - Drive Side - Left Hand
    • PF01 - Performance - true
    • BT85 - Battery Type - 85
    • PMMB - ??
    • RFBC - Roof - Body Color (RFPO - seems to be pano roof)
    • WT21 - Wheel Type - 21"
    • IDOG - Interior - obeche gloss?
    • IZMT - ??
    • TR00 -- ??
    • SU01 - Air suspension?
    • SC01 - Super charger access?
    • TP01 - Tech package?
    • AU01 - Audio package?
    • CH00 - child seats?
    • HP00 - ??
    • PA01 - paint armor?
    • PS01 - ??
    • AD02 - ??
    • Xxxx - Other specific options? Could be grey wheels, spoiler, etc....

    Anybody want to take a guess at the meanings? I noticed tim's example had some different options codes including "PBCW", "IBMB" (related to "PMMB"?).

    I figure the paint color, seat color/type, and single/twin chargers are encoded in there somewhere. I have blue paint, tan leather, and a single charger.
     
    • Informative x 1
  5. ahimberg

    ahimberg Member

    Joined:
    Aug 8, 2010
    Messages:
    349
    Location:
    Woodinville, WA
    there are some comments in the apiary.io doc for most of them.
     
  6. PureAmps

    PureAmps Model S P85 (#2817)

    Joined:
    Oct 22, 2012
    Messages:
    359
    Location:
    SF Bay Area
    Thanks, I hadn't noticed the comments. How did they decode all of the X??? options?
     
  7. ahimberg

    ahimberg Member

    Joined:
    Aug 8, 2010
    Messages:
    349
    Location:
    Woodinville, WA
    that I have no idea about, but they seemed to be right, all the things that differed for me seemed to line up
     
  8. AnOutsider

    AnOutsider S532 # XS27

    Joined:
    Apr 3, 2009
    Messages:
    11,945
    Some of these codes also showed up in the design studio back when I was sniffing the data there
     
  9. aviators99

    aviators99 Model S - R140

    Joined:
    Jan 1, 2010
    Messages:
    1,458
    Location:
    Weston, Florida, United States
    Bingo. Still do.
     
  10. timdorr

    timdorr Model S P1698 / VIN 1657

    Joined:
    Aug 2, 2012
    Messages:
    461
    Location:
    Atlanta, Georgia, United States
    #30 timdorr, Feb 4, 2013
    Last edited: Feb 4, 2013
    *shudder*. Sorry, I have an internal hatred of Java :)

    I think a npm or Ruby gem would be good to have as well. They are using those on the backend, after all! (portal.vn is Rails and streaming.vn is nodejs/Express).
     
  11. Alpha

    Alpha Member

    Joined:
    Dec 4, 2012
    Messages:
    406
    Location:
    Earth
    This is really cool stuff. I personally could make a lot of use out of the REST API -- I just hope Tesla doesn't get all upset about people doing this... best possible thing would be for them to publish this on their own. And maybe they will eventually.
     
  12. widodh

    widodh Model S 85 and 100D

    Joined:
    Jan 23, 2011
    Messages:
    6,062
    Location:
    Middelburg, The Netherlands
    What's wrong with Java? (Don't start!! ;)) I write in it every day.

    Anyway, I don't think JavaScript will work since it doesn't allow HTTP calls to other domains then where you are in.

    My PHP class is going nicely, I'll do a pull request on Github when it's ready so it can go into the repo with a couple of examples.
     
  13. Alpha

    Alpha Member

    Joined:
    Dec 4, 2012
    Messages:
    406
    Location:
    Earth
    Nice thing about a REST api - easy to implement in any language.
     
  14. finout

    finout Member

    Joined:
    Jan 5, 2011
    Messages:
    84
    Well in case anyone wants to actually implement the commands (in addition to the basic vehicle status resources mentioned at http://docs.timdorr.apiary.io/), I mucked around with mine and found the commands I could do (when not plugged in)

    auto_conditioning_start
    auto_conditioning_stop
    charge_max_range
    charge_standard
    charge_port_door_open
    door_lock
    door_unlock
    flash_lights
    honk_horn
    set_temps?passenger_temp=22.222223&driver_temp=22.222223
    <note: temps obviously converted from F in interface to C>

    Code:
    These are all in the same REST format as in the timdorr site (but must include the specified cookies). e.g.:
    
    https://portal.vn.teslamotors.com/vehicles/[I]<vehicle id>[/I]/command/[B]auto_conditioning_start[/B]
     
  15. PureAmps

    PureAmps Model S P85 (#2817)

    Joined:
    Oct 22, 2012
    Messages:
    359
    Location:
    SF Bay Area
    I hadn't seen the reference to streaming.vn, so that peaked my interest this morning. :) Now that I have the iPhone app, I was able to watch the traffic via a proxy this afternoon.

    It is really quite impressive what they've done. Through their streaming API they are providing real-time telematics updates every 250ms. I tested this while driving around with my daughter watching the speedometer and the mobile app at the same time, and the latency appears quite low (well less than 1 second). Considering the data is coming from my vehicle over AT&T's 3G network to some Tesla data center and then sent back over Verizon's LTE network (in my case) to my phone, it is pretty amazing!

    I think nodejs was a good choice on Tesla's part for this application, a pretty good match for the problem they are solving, and should scale well.

    I noticed the authentication used for the streaming API is using one of the two "tokens" provided in the vehicle's JSON description. It kind of make me wonder what the other token is for....
     
  16. timdorr

    timdorr Model S P1698 / VIN 1657

    Joined:
    Aug 2, 2012
    Messages:
    461
    Location:
    Atlanta, Georgia, United States
    Those restrictions come from the browser, whereas nodejs is a backend server application and can do whatever the heck you want. It's the v8 engine from Chrome stripped out and hooked up to run as a server. Check it out, if you haven't heard of it: node.js
     
  17. Alpha

    Alpha Member

    Joined:
    Dec 4, 2012
    Messages:
    406
    Location:
    Earth
    How do you know what they are using on the backend?
     
  18. PureAmps

    PureAmps Model S P85 (#2817)

    Joined:
    Oct 22, 2012
    Messages:
    359
    Location:
    SF Bay Area
    The HTTP Server header in the responses coming back from their servers indicates the server type.
     
  19. Alpha

    Alpha Member

    Joined:
    Dec 4, 2012
    Messages:
    406
    Location:
    Earth
    Oh I see now that chromeo is rails app... Assumed it was something proprietary.

    - - - Updated - - -

    I wish I could participate - can't do much until I get my car :-(
    the app pretty much stops me at signon saying no car registered.
    really exciting to hear about it though...
     
  20. Banahogg

    Banahogg Member

    Joined:
    Jan 22, 2013
    Messages:
    293
    Location:
    San Jose, CA
    FWIW, the curl -u that I mentioned worked for me before seems to have stopped working, so I guess it's back to the cookies.
     

Share This Page

  • About Us

    Formed in 2006, Tesla Motors Club (TMC) was the first independent online Tesla community. Today it remains the largest and most dynamic community of Tesla enthusiasts. Learn more.
  • Do you value your experience at TMC? Consider becoming a Supporting Member of Tesla Motors Club. As a thank you for your contribution, you'll get nearly no ads in the Community and Groups sections. Additional perks are available depending on the level of contribution. Please visit the Account Upgrades page for more details.


    SUPPORT TMC