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. Roadrunner13

    Roadrunner13 Member

    Joined:
    Oct 16, 2013
    Messages:
    345
    Location:
    Montreal

    I've been running VisibleTesla for three years with very little hicups and it does record trip information on a daily basis, I would expect via the streaming API (I haven't checked). These recordings stopped completely also on March 7th. Last trip recorded on March 6th!!! Coincidence? Let me know if this starts working again for you.

    Since then connecting with VisibleTesla just to get status or even via Tesla standard app has been horrible! Can't preheat the car, nothing!
    Never had this in 3 years...
     
  2. jayman

    jayman Member

    Joined:
    Aug 31, 2013
    Messages:
    305
    Location:
    Illinois
    Unfortunately, with what @dirkvm did above I’m not getting any streaming data either. Not sure if it’s because of my installation, the fact I live in US or what. I have a 2017 model S so I thought I’d be safe but the 6th of March was my demise as well.
     
  3. dirkvm

    dirkvm Supporting Member

    Joined:
    Apr 4, 2018
    Messages:
    7
    Location:
    Flanders, Belgium
    This is what I get with this websocket test, copy to examples/streamws.js simple test
    (id's and location data removed or edited, only vehicle_id and tokens[0] are used)
    Code:
    { ...
      vehicle_id: NNNNNNNNN,
      tokens: [ 'XXXXXXXXXXXXXX', 'YYYYYYYYYYY' ],
      state: 'asleep',
      in_service: false,
      calendar_enabled: true,
      api_version: 6,
      backseat_token: null,
      backseat_token_updated_at: null }
    16 Mar 08:44:50 - {"msg_type":"control:hello","connection_timeout":0}
    16 Mar 08:44:50 - {"msg_type":"data:error","tag":"NNNNNNNNN","value":"disconnected","error_type":"vehicle_disconnected"}
    
    Car is 'asleep', returns a "data:error" message but stays connected.
    
    { ...
      vehicle_id: NNNNNNNNN,
      tokens: [ 'XXXXXXXXXXXXXX', 'YYYYYYYYYYY' ],
      state: 'online',
      ... }
    16 Mar 09:08:07 - {"msg_type":"control:hello","connection_timeout":0}
    16 Mar 09:08:08 - {"msg_type":"data:update","tag":"NNNNNNNNN","value":"1552723693203,,..."}
    
    After waking up the car, it goes to the 'waking' state then stays in an
    'unknown' state for some time and finally goes to the 'online' state.
    Even if the car doesn't move, it still returns some "data:update" messages.
    Once the car starts moving, the frequency of these messages rises to
    about 4 per second.
    
     
  4. jayman

    jayman Member

    Joined:
    Aug 31, 2013
    Messages:
    305
    Location:
    Illinois
    #2584 jayman, Mar 16, 2019
    Last edited: Mar 16, 2019
    yeah, it appears the test works but dirkvm/teslams did not for me. It just seems to hang without spitting out any data except for the characteristics of the car then empty darkness.
     
  5. dirkvm

    dirkvm Supporting Member

    Joined:
    Apr 4, 2018
    Messages:
    7
    Location:
    Flanders, Belgium
    Note that logging of the messages to the console is disabled. Remove the // from line 290 in your copy of dirkvm/teslams
    if you want the messages listed. Otherwise use "examples/streamws.js -z --file" to list them to the file "streaming.out".
     
  6. jayman

    jayman Member

    Joined:
    Aug 31, 2013
    Messages:
    305
    Location:
    Illinois
    No I've tried having the data be placed in a flat file. I'll sometimes get one row of CSV and that's it. That is despite leaving it running throughout the day. On the console it does appear to be getting rest data but that's it. I'm not able to get any streaming data to a flat file or to Mongo.
     
  7. jayman

    jayman Member

    Joined:
    Aug 31, 2013
    Messages:
    305
    Location:
    Illinois
    It looks like once I uncommented that line it's working. Not sure why that would be. Thanks.
     
  8. tornado

    tornado Member

    Joined:
    Dec 7, 2012
    Messages:
    44
    Location:
    Seattle-Area
    Is there a way to keep the stream going beyond the password timeout? Like a script to auto-reload token? I have this all set up in a Paw document (to get the updated tokens, etc) but it is still manual at this point.
     
  9. zzsf

    zzsf Member

    Joined:
    Aug 17, 2017
    Messages:
    7
    Location:
    SF
    #2589 zzsf, Mar 18, 2019
    Last edited: Mar 18, 2019
    Here's a quick implementation streaming the new websocket based API to CSV with reconnect and reauthentication using the refresh token. It has a partial API client in scala for those who prefer it.

    Pushed a compiled JAR if you don't want to go through the trouble of building it.

    zuyezheng/TeslaApi
     
    • Helpful x 1
  10. dirkvm

    dirkvm Supporting Member

    Joined:
    Apr 4, 2018
    Messages:
    7
    Location:
    Flanders, Belgium
    As far as I can tell, you only need the token and vehicle_id to authenticate a new websocket connection. Streaming remains active until the connection is closed due to an error or because it's closed by the client app.
     
  11. svrist

    svrist New Member

    Joined:
    Apr 1, 2019
    Messages:
    1
    Location:
    Denmark
    Ive seen a couple of instances (3 x M3 and 1x MS) where I can get the

    Code:
    "charger_power":0,
    "charger_voltage":1,
    "charging_state":"Stopped",
    "conn_charge_cable":"IEC"
    
    on a data request but if I then follow it up with charge_start I just get:

    Code:
    {"reason":"charging","result":false}
    and the car doesnt start charging (it's not asleep)

    Has anyone else seen this and had any workarounds?
     
  12. Bandit

    Bandit Member

    Joined:
    May 5, 2018
    Messages:
    91
    Location:
    Burlington, Ontario, Canada
    I've been getting 500 internal server errors for the last few days when calling auto_conditioning_start. Using Postman it seems I get this for all POSTs (set charge limit, set temperatures.) My GETs work and the wake_up POST also works fine.

    Has something changed with respect to required headers, body etc? These should be simple calls and were working for months.
     
  13. Bandit

    Bandit Member

    Joined:
    May 5, 2018
    Messages:
    91
    Location:
    Burlington, Ontario, Canada
    I had been setting the Content-type header. Although they accepted it for quite a while (maybe even required it at one time?) it seems to break things now. With only the Authorization header it works as expected.
     
  14. bassmaster

    bassmaster Member

    Joined:
    Oct 23, 2017
    Messages:
    17
    Location:
    Germany
    I'm connecting to the WebSocket
    wss://streaming.vn.teslamotors.com/connect/{Tesla_vehicle_id}
    With Header:
    "Authorization" = "Basic " + Base64String of Emailadress : Streamingtoken

    After the connection, I send:
    {"msg_type": "data:subscribe", "value": ["speed","odometer","soc","elevation","est_heading","est_lat","est_lng","est_corrected_lat","est_corrected_lng","native_latitude","native_longitude","native_heading","native_type","native_location_supported","power","shift_state"]}

    What I need is the elevation, but what I get is:

    {"heading":266.722578,"latitude":xx.188278,"longitude":xx.901098,"msg_type":"vehicle_data:location","shift_state":"D","speed":25.041258}

    What am I doing wrong?
     
  15. PittCaleb

    PittCaleb Member

    Joined:
    Apr 23, 2019
    Messages:
    29
    Location:
    New Jersey
    Hello... New Tesla owner... Got the API working, can pull down vehicle data, so I've got all that working.

    I know there are websites such as TeslaFi that get more detailed data than I'm seeing from the API. Is there an endpoint to get, for example, data from my last charge? watt-hours added, etc. Or does TeslaFi get this by querying the API at regular intervals and computing it?

    Thanks!
     
  16. dpskipper

    dpskipper Developer

    Joined:
    Aug 4, 2016
    Messages:
    186
    Location:
    Australia
    No mate. What you see is what you get. If Tesla exposes more info people will add it into their projects quick smart.
     

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