Welcome to Tesla Motors Club
Discuss Tesla's Model S, Model 3, Model X, Model Y, Cybertruck, Roadster and More.
Register
  • Want to remove ads? Register an account and login to see fewer ads, and become a Supporting Member to remove almost all ads.
  • Tesla's Supercharger Team was recently laid off. We discuss what this means for the company on today's TMC Podcast streaming live at 1PM PDT. You can watch on X or on YouTube where you can participate in the live chat.

Model S REST API

This site may earn commission on affiliate links.
Solution to "There was an error loading your vehicle" and related on 2013/09/06-07

brianman said:
The REST login server appears to have been down for over a day (since approximately 9:30AM PT on Friday, 2013/09/06). People with "old" cookies got grandfathered for a little while on phones (and full computers) but that's only a lucky few for a limited time.


Please have someone go feed the hamster or somesuch.
teslamotors.com said:
Yesterday, we experienced some problems with our website and some of our servers. I’m not aware if this is related to the problem some customers are reporting with their Mobile App. We recommend cycling the power on the Touch-Screen of your Model S, as well as the mobile device that you’re using to connect to the vehicle.

This worked for me.
 
I can't this thing to install on ubuntu.

I installed mongodb,

matt@host:~$ mongo --version
MongoDB shell version: 2.0.4
matt@host:~$

I tried apt-get and npm to install mongodb, which I don't want to use anyway.

then, sudo npm install -g teslams fails looking for mongodb.


I see the package in ~/.npm/teslams, it is untarballed in there but it still won't execute.

When I try to execute a script, I get this.

matt@host:~/.npm/teslams/0.6.45/package/examples$ ./teslacmd.js


node.js:201
throw e; // process.nextTick error, or 'error' event on first tick
^
Error: Cannot find module 'optimist'
at Function._resolveFilename (module.js:332:11)
at Function._load (module.js:279:25)
at Module.require (module.js:354:17)
at require (module.js:370:17)
at Object.<anonymous> (/home/matt/.npm/teslams/0.6.45/package/examples/teslacmd.js:4:12)
at Module._compile (module.js:441:26)
at Object..js (module.js:459:10)
at Module.load (module.js:348:32)
at Function._load (module.js:308:12)
at Array.0 (module.js:479:10)




Am I missing something simple here?
 
I can't this thing to install on ubuntu.

I installed mongodb,

matt@host:~$ mongo --version
MongoDB shell version: 2.0.4
matt@host:~$

I tried apt-get and npm to install mongodb, which I don't want to use anyway.

then, sudo npm install -g teslams fails looking for mongodb.


I see the package in ~/.npm/teslams, it is untarballed in there but it still won't execute.

When I try to execute a script, I get this.

matt@host:~/.npm/teslams/0.6.45/package/examples$ ./teslacmd.js


node.js:201
throw e; // process.nextTick error, or 'error' event on first tick
^
Error: Cannot find module 'optimist'
at Function._resolveFilename (module.js:332:11)
at Function._load (module.js:279:25)
at Module.require (module.js:354:17)
at require (module.js:370:17)
at Object.<anonymous> (/home/matt/.npm/teslams/0.6.45/package/examples/teslacmd.js:4:12)
at Module._compile (module.js:441:26)
at Object..js (module.js:459:10)
at Module.load (module.js:348:32)
at Function._load (module.js:308:12)
at Array.0 (module.js:479:10)




Am I missing something simple here?


Does not sound like your install worked. I know github was down last night for maintenance so perhaps you missed something.

"npm install -g teslams" (with or without the leading 'sudo' ) should automatically install all the required node modules including "optimist" and put 'teslacmd' in your path so you can run it from any directory.

You should get a long list of HTTP commands followed by a couple pauses while it installs all the necessary node_modules and finally this right before your shell promp comes back
[...]
[email protected] node_modules/teslams
├── [email protected]
├── [email protected]
├── [email protected] ([email protected])
├── [email protected] ([email protected])
├── [email protected] ([email protected], [email protected])
├── [email protected] ([email protected])
├── [email protected] ([email protected], [email protected], [email protected], [email protected], [email protected], [email protected], [email protected], [email protected], [email protected], [email protected], [email protected])
└── [email protected] ([email protected], [email protected])


You do not need to install mongodb if you don't want to use it. teslams will install the mongodb 1.3.19 javascript client libraries (not the database) but they are tiny and you can just ignore them unless you want to use the "visualize" charts and maps.

PM me if you are still having trouble.
 
To the developers in this thread: what is the unit of 'power' from the streaming API? Is it total watt used since the last 250ms (since the data comes in every 250ms). So to obtain the total energy used (as shown in the in-car odometer), one would take this number multiply by 250 and divided by 3600000 to get kw/h used. Then add them all up for the duration of a trip to obtain Total Energy in kw/h? Is my assumption correct?
 
To the developers in this thread: what is the unit of 'power' from the streaming API? Is it total watt used since the last 250ms (since the data comes in every 250ms). So to obtain the total energy used (as shown in the in-car odometer), one would take this number multiply by 250 and divided by 3600000 to get kw/h used. Then add them all up for the duration of a trip to obtain Total Energy in kw/h? Is my assumption correct?

It is an instantaneous sample of the current current ;-)

The power unit (I) is kW, not kWh, nor kW/h. It does not have a time component. You could estimate the amount of kWh used by assuming a constant current for the 250ms time gap between samples.
 
To the developers in this thread: what is the unit of 'power' from the streaming API? Is it total watt used since the last 250ms (since the data comes in every 250ms). So to obtain the total energy used (as shown in the in-car odometer), one would take this number multiply by 250 and divided by 3600000 to get kw/h used. Then add them all up for the duration of a trip to obtain Total Energy in kw/h? Is my assumption correct?

That's how I started. The numbers tended to be way off and consistently higher than the ones on the in car display (trip meter display).
I'm now switching to using the range readings in the charge-state data (and convert this back into kWh). Not great, either, but so far this has given me the most consistent data.
 
It is an instantaneous sample of the current current ;-)

The power unit (I) is kW, not kWh, nor kW/h. It does not have a time component. You could estimate the amount of kWh used by assuming a constant current for the 250ms time gap between samples.

My data observation seemed to indicate that this is not the average over the 250ms. There obviously is no truly instantaneous measurement... I thought for a while that it may be the maximum power during the interval, but I can't prove that, either.
 
@dirkhh - For the data provided, I would expect the best approximation to be a curve fit and measure the area under the curve. A line fit might be a good approximation but a bar graph fit is likely horribly off, as you're seeing.
 
It is an instantaneous sample of the current current ;-)

The power unit (I) is kW, not kWh, nor kW/h. It does not have a time component. You could estimate the amount of kWh used by assuming a constant current for the 250ms time gap between samples.

Actually, current is I (amps), and power is P (watts). E=IR (Ohm's law) and P=IE (Joule Heating law). But I agree with you that the power unit P should be an instantaneous draw; but it's not. I note that it's a quasi-instantaneous number. Just look at the vampire drain over the course of a day. I've noticed that whenever I see a mile come off the range, there is a corresponding static number associated with the power draw that makes it look like it's consumed all at once.

In other news... mmm, P=IE... especially peach.
 
Call for help from metric user

I am trying to make sure the visualization tools (as part of the teslams javascript tools) do the sane thing for people who's cars are setup in metric (showing km).
One part of it is obviously the visualization, labeling, etc (that's easy), but the other question I have is... "what's in the data"?
In the streaming data, are odometer readings and speed in km and km/h? Or are they still in miles and mph?
Either is obviously fine, but I'd love to know which one it is. :)

I'm sure there are Canadians out here who use some of the streaming tools (there are a few others besides teslams at this point - even VisibleTesla has a streaming mode...) who could give me some sample data.

Thanks for the help
 
Okay, how do you get the streaming api to work? I haven't been able to figure it out at all.

I tried the token thing with curl (a while ago, don't remember the exact process now), I know I had the right token but I wasn't able to get any data when I ran curl.
 
Okay, how do you get the streaming api to work? I haven't been able to figure it out at all.

I tried the token thing with curl (a while ago, don't remember the exact process now), I know I had the right token but I wasn't able to get any data when I ran curl.

if you look at teslams there is a streaming.js example program included that does it all for you. And if you then use the MongoDB backend then you can create all these cool visualizations :)
 
Okay, how do you get the streaming api to work? I haven't been able to figure it out at all.

I tried the token thing with curl (a while ago, don't remember the exact process now), I know I had the right token but I wasn't able to get any data when I ran curl.

Are you a programmer? If so, do you have a preferred language? I can give you the exact sequence of curl commands to do streaming from the command line or I can point you to a sample implementation in a programming language that makes the most sense to you.
 
Are you a programmer? If so, do you have a preferred language? I can give you the exact sequence of curl commands to do streaming from the command line or I can point you to a sample implementation in a programming language that makes the most sense to you.

I did finally get streaming.js to work once upgrading to the new version of node, thanks for that tip.

I'd like to get the curl commands when you have a moment could you send them?

I generally just shell script. I whipped up a charge scheduling script that works off a set departure time and requested range that I specify on a php web page which writes a text file somewhere in /var on my box. The script lets the car charge for 10 minutes then grabs the "time to full" value from the car and shuts it off till it needs to start charging again so it is done within a few minutes of the set departure time with the requested range.
 
What is the point of this?
This allows you to set a time at which you want the charge to finish. Let's say you want to leave at 7 in the morning with a fully charged car, but you don't want to have the car sit with a high SOC over night, so you don't start the charge the previous evening instead you program things so that it starts the charge at just the right time so that it is finished charging at 7am -> no time sitting at high SOC.
 
I did finally get streaming.js to work once upgrading to the new version of node, thanks for that tip.

I'd like to get the curl commands when you have a moment could you send them?

I generally just shell script. I whipped up a charge scheduling script that works off a set departure time and requested range that I specify on a php web page which writes a text file somewhere in /var on my box. The script lets the car charge for 10 minutes then grabs the "time to full" value from the car and shuts it off till it needs to start charging again so it is done within a few minutes of the set departure time with the requested range.

I added example curl commands (for both the REST API and Streaming API) to the REST API Wiki page

Since you have teslams installed you can also use the "teslacmd" command for scripting ("teslacmd --help" for all the command line options)
 
I added example curl commands (for both the REST API and Streaming API) to the REST API Wiki page

Since you have teslams installed you can also use the "teslacmd" command for scripting ("teslacmd --help" for all the command line options)


Thanks, I'll play with that! I've gone so far with what I'm doing that I generate XML for all of my queries. I then wrote an xmlgrep script (and function) to reference to find a specific value from the latest or specific time in my "database". which isn't a database, just a directory with a crap ton of XML files.

Its a mess, but it works for me. I'm sure there's more efficient ways to do it.
 
This allows you to set a time at which you want the charge to finish. Let's say you want to leave at 7 in the morning with a fully charged car, but you don't want to have the car sit with a high SOC over night, so you don't start the charge the previous evening instead you program things so that it starts the charge at just the right time so that it is finished charging at 7am -> no time sitting at high SOC.

or you could reduce the charging amps so you would get a slower charge that ends at your chosen time. that way if you have to leave unexpectedly before that you would have more of a charge.
afterthought: can you change the amps through the API?