hjespers / teslams Goto Github PK
View Code? Open in Web Editor NEWTesla node.js apps and javascript libraries using Tesla's HTTP interfaces
License: BSD 3-Clause "New" or "Revised" License
Tesla node.js apps and javascript libraries using Tesla's HTTP interfaces
License: BSD 3-Clause "New" or "Revised" License
visualize always throws this error:
root@vps1:~# visualize -d teslams -u -v
Teslamotors.com logon information loaded from /root/.teslams/config.json
Using MongoDB URI: mongodb://127.0.0.1:27017/teslams
/usr/lib/node_modules/teslams/examples/visualize/visualize.js:161
app.configure(function() {
^
TypeError: Object function (req, res, next) {
app.handle(req, res, next);
} has no method 'configure'
at Object. (/usr/lib/node_modules/teslams/examples/visualize/visualize.js:161:5)
at Module._compile (module.js:456:26)
at Object.Module._extensions..js (module.js:474:10)
at Module.load (module.js:356:32)
at Function.Module._load (module.js:312:12)
at Function.Module.runMain (module.js:497:10)
at startup (node.js:119:16)
at node.js:902:3
root@vps1:~# npm
I researched it a bit and found:
https://github.com/visionmedia/express/wiki/Migrating-from-3.x-to-4.x
"Removed
app.configure()
This method is no longer available. If you wish to configure different routes based on environment, use an if statement or alternative module."
In version 0.7.5, in visualize, in the Energy page, the SOC and Rated range graph,
I notice that the "Rated range (miles)", the (blue line) is a little high.
I measured that it appears to reflect the Rated Range in km, not miles. I expect this is just a conversion calc missing.
Forgive me if this was covered elsewhere.. I looked at many issues before opening a new one.
i am in the process of developing a set of rules to generate notifications based on the charging state and charger-proximity of the model s. here are the conditions i've come up with, along with their predicates.
could i ask you to review and comment?
also, i'm not sure what values to use in order to calculate the "charging-done-within-5m"
CONDITIONS
PREDICATES
It seems clunky to have Restla run a web server on one port, and Visualize run on a different port, would it not make more sense to have Restla as a menu button within visualize?
Some of the data isn't displaying anymore on the energy charts. All the maps from an earlier day work but not for the day after.
The project was created on digital ocean, streaming.js is streaming to a local mongo instance, and the node project is being hosted on the same server.
The stream process gets me these logs:
12 Apr 16:45:59 - 2 of 1 REST requests since 1460493919719
12 Apr 16:45:59 - Warn: throttling due to too many REST API requests
Perhaps streaming.js may be getting throttled then getting stuck in a kind of loop, since if you restart streaming.js it seems to collect the data again.
Teslamotors.com logon information loaded from /home/marcus/.teslams/config.json
29 Oct 07:42:24 - timestamp,speed,odometer,soc,elevation,est_heading,est_lat,est_lng,power,shift_state,range,est_range,heading
events.js:85
throw er; // Unhandled 'error' event
^
Error: ENOSPC, write
at Error (native)
Would be awsome to be able to open the frunk and trunk from my apple watch.
Can you update the telsams to support Trunk and Frunk?
Some people would prefer to manage their own login tokens rather than request a new one each time their apps start.
I should add into teslams.js an explicit login() method that sets the global variable for the token and does nothing else. This is done now, only when you call vehicles() or all()
Modify teslacmd.js to have an option to print out the token.
Modify config.js to check the ~/.teslams.json file for a token that the user has saved instead of their username and password.
Modify vehicles() and all() to check if the global token variable is already set and if so, skip the login part of the code. May enhance this later to check for expired tokens.
Looking at teslams.js it seems to me as if the Authorization token should be accessible from outside the library and is therefore defined as an export. This is very useful to me since it allows caching and therefore avoiding an additional request to the TESLA API when only polling for example /charge_state.
However:
var portal = 'https://owner-api.teslamotors.com/api/1';
exports.portal = portal;
var owner_api = 'https://owner-api.teslamotors.com';
exports.portal = owner_api;
var token = '';
exports.token = token;
Unfortunately I think the '=' copies by value and not by reference. So when accessing the token from outside it is always an empty string.
I would submit a pull request that fixes the issue but wanted to make sure it is not intended behavior.
[teslams] $ visualize -db /data/db
Server running
done sending the initial page
/usr/local/lib/node_modules/teslams/examples/visualize.js:86
if (err) throw err;
^
Error: ENOENT, open './map.html'
Suggestion: Show the teslams version number in the visualize.js web interface
I think they changed from teslamotors to just tesla.com recently, I suspect API needs updating too...... is this project currently working.... I was getting an error trying to do login..
Error: login failed
at /usr/local/lib/node_modules/teslams/examples/teslacmd.js:229:12
at report (/usr/local/lib/node_modules/teslams/teslams.js:24:13)
at Request._callback (/usr/local/lib/node_modules/teslams/teslams.js:65:101)
at Request.self.callback (/usr/local/lib/node_modules/teslams/node_modules/request/request.js:187:22)
at emitTwo (events.js:106:13)
at Request.emit (events.js:191:7)
at Request. (/usr/local/lib/node_modules/teslams/node_modules/request/request.js:1044:10)
at emitOne (events.js:96:13)
at Request.emit (events.js:188:7)
at IncomingMessage. (/usr/local/lib/node_modules/teslams/node_modules/request/request.js:965:12)
I try to use the cmd teslacmd -a
and got
Teslamotors.com logon information loaded from ~/.teslams/config.json
[Error: expecting an array from Tesla Motors cloud service]
I pretty sure the login and password are correct. It looks like Tesla has changed the API. .Any help would be greatly appreciated.
In visualize, on the energy tab, the top graph is labelled as energy and speed, but it doesn't differentiate between regen and charging, labels all charging as regen. Considering that charging is covered by the next graph down, it would be much nicer if only regen were included here.
The examples with -p on the command line make me really wary. This is leaking passwords in people's history and process table. Any other user on the system can see the password in this case.
Enable the ability to specify the config.json location as env var and cli argument so multiple config.json can be used and a custom location can be used. This is nice for setups where $HOME may not be ideal.
Sometime streaming.js will have more than one thread running doing the same work. This can overload the Tesla server and get the user blocked. It is not clear why this happens. Need to swat this bug
hey, so excited to try out multiple commands within the example, turned out I seem to be blocked bu their Dos. any way to recover it ?
visualize, the map doesn't run for me on IOS7 in Chrome browser.
On line 254, the variable 'optionsString' is mistyped and must be corrected to 'optionString' (2 times).
This part of the error message:
ReferenceError: optionsString is not defined
at /usr/local/lib/node_modules/teslams/examples/visualize/visualize.js:254:22
@hjespers: it seems that the client secret is the same for everyone, and is trivial to extract from here.
The problems of having a publicly available client secret are stated here (although you probably know of them already):
http://tools.ietf.org/html/rfc6819#section-4.1.1
I suggest loading a client secret from a local .json file (example here, Tim Dorr uses environment variables), and supply the users of your library with a sample-file stating how to generate the secret (or simply in the readme).
Have a nice day :)
Supercharger availabilities API? Showing locations and how many are vacant?
Getting the charge/battery status does not work for me. It seems that the encoding is not handled correctly.
alex@b52:~/teslams$ examples/teslacmd.js -c
[Error: expecting JSON response to charge_state request]
I altered the code to display the response. This is the contents of 'body' (in teslams.js) at the time the error message is generated:
_�H@@@@@@ctt�n�0P�W�Q"0��r��W+YN��%cS?؝���[�a&�ɑ�����6�̒��vĚw�N��R��y�Qa�[�e+F\�Qz�L˚_��(�o�Qj�ԏjF��5O�Ay�Q�V�^.B9�ث����ODm�[�m�6�
{�!����_b�y�*c^�Tm�D���4�U;{+�5�CMNo��Y0�9�҈���w��b&��x[pL����?��WQ�R�kG�����E�'�b����=HB��VUp8���➥����I�AW�T�L�lUz����A8r��[S �N�
�RVw���h�s��ʏ��@@@��C@q��3�D@@]
On line 254, the variable 'optionsString' is mistyped and must be corrected to 'optionString' (2 times).
This part of the error message:
ReferenceError: optionsString is not defined
at /usr/local/lib/node_modules/teslams/examples/visualize/visualize.js:254:22
(sorry i closed the same Issue by mistake and had to reopen it again).
what I'd like to change:
getToken(email, password, callbackFn)
get_charge_state( vid, token, cb )
JSONBig
module dependency. Rather than fixing the id field, use the id_s
field, which tesla already includes for vehicles. One less dependency.if any/all of these changes would be welcome, I'd be happy to send some PRs.
One thing to note, this would be a significant API change. We'd have to mark this as 2.x to respect semver.
@hjespers thoughts?
i know about "Stopped", "Complete", and "Charging" anything else?
thanks!
Hi - wondering if anyone has tried using inside of AWS Lambda. I had it working about 2 months ago, and updated library to get the support for passing a token instead of user / pwd, and now my Lambda call is timing out. I tried increasing memory to 256 MB and also timeout to 30 seconds, didn't help.
Its very weird b/c I can use the http lib "request" that teslams uses internally and make a call to google fine, but if I try to call through a teslams.get_vehicle or other call it hangs. Also tried using request to call https://owner-api.teslamotors.com/api/1 directly and that hung as well.
Some conflict or filter AWS has or Tesla blocking calls from AWS Lambda somehow? Would love to know if anyone else has any luck. Thanks.
all the other oclumns are easy to figure out. my guess is that the power column is kW (or kWh ?) with positive numbers being the drain on the battery, and negative numbers reflecting recharging.
thanks!
Adding summon. Keep running into this error:
I keep getting "too_far_from_vehicle error".
Add the following to Teslams.js
// summon
function summon( vid, cb) {
console.log("summon");
request( {
method: 'POST',
url: portal + '/vehicles/' + vid + '/command/autopark_request',
gzip: true,
headers: http_header,
lat: yourlat,
lon: yourlong,
action: 'start_reverse'
//homelink_nearby: true
}, function (error, response, body) {
if ((!!error) || (response.statusCode !== 200)) return report(error, response, body, cb);
try {
var data = JSON.parse(body);
if (typeof cb == 'function') return cb( data.response );
else return true;
} catch (err) {
return report2('autopark_request', body, cb);
}
});
}
exports.summon = summon;
I just downloaded and updated to the lastest version and am receiving the following error when I run any commands from terminal. My pull from 7/28 worked fine. This is on Mac OSX. Any ideas? I didn't install MongoDB yet; so perhaps this is my problem?
Thanks
KMBA:teslams-master K$ chargebar
env: node\r: No such file or directory
Installation from the sudo command is below:
[email protected] install /usr/local/lib/node_modules/teslams/node_modules/mongodb/node_modules/kerberos
(node-gyp rebuild 2> builderror.log) || (exit 0)[email protected] install /usr/local/lib/node_modules/teslams/node_modules/mongodb/node_modules/bson
(node-gyp rebuild 2> builderror.log) || (exit 0)
xcode-select: Error: No Xcode is selected. Use xcode-select -switch , or see the xcode-select manpage (man xcode-select) for further information.
npm http 304 https://registry.npmjs.org/charm/0.1.2
xcode-select: Error: No Xcode is selected. Use xcode-select -switch , or see the xcode-select manpage (man xcode-select) for further information.
/usr/local/bin/teslacmd -> /usr/local/lib/node_modules/teslams/examples/teslacmd.js
/usr/local/bin/teslamap -> /usr/local/lib/node_modules/teslams/examples/teslamap.js
/usr/local/bin/streaming -> /usr/local/lib/node_modules/teslams/examples/streaming.js
/usr/local/bin/chargebar -> /usr/local/lib/node_modules/teslams/examples/chargebar.js
/usr/local/bin/climatemon -> /usr/local/lib/node_modules/teslams/examples/climatemon.js
/usr/local/bin/visualize -> /usr/local/lib/node_modules/teslams/examples/visualize.js
npm WARN package.json [email protected] No repository field.
npm WARN package.json [email protected] No repository field.
npm WARN package.json [email protected] No repository field.
[email protected] /usr/local/lib/node_modules/teslams
├── [email protected]
├── [email protected]
├── [email protected] ([email protected])
├── [email protected] ([email protected])
└── [email protected] ([email protected], [email protected])
AWS Lambda doesn't support 'Request' 3rd party module -- so I am kinda stuck.
Have a stand-alone Lambda function I've writing using AWS Lambda console and can't figure out how to call the Tesla API from it...
this only happens when driving. The last value of the data includes another entire line of data. This can screw up some apps. I have had to include a dud value that I don't use to avoid having this problem. Need to check how we split the data and throw away extraneous lines if present.
I'm evaluating this library and the examples work so far when I provide username and password on the commandline. But starting from example.js I don't have any success with my own 'code'
#!/usr/bin/env node
var teslams = require('teslams');
var util = require('util');
// Config
var config = {
creds: {
username: '[email protected]',
password: 'mypassword'
}
};
// Generic callback function to print the return value
function pr( stuff ) {
console.log( util.inspect( stuff ) );
}
console.log(config.creds);
teslams.get_vid( { email: config.creds.email, password: config.creds.password }, function ( vid ) {
if (vid == undefined) {
console.log("Error: Undefined vehicle id");
} else {
teslams.get_charge_state( vid, pr );
}
}
);
Results in:
{ username: '[email protected]', password: 'mypassword' }
[Error: 404: 404]
[Finished in 1.7s]
Any advice?
(Password and username changed for this report of course)
Sorry to bug you right away with another issue.
Streaming does not work for me, I get "WARN: HTTP 401: Unauthorized - token has likely expired, reinitializing". I've saved my u/p in config.json, it works for the other scripts.
Not sure if it has anything to do with this problem (probably not), but this script can not be executed from any directory. If I start it from ~/teslams/ it does not find config.json. The other scripts do.
I was planning to use restla.js for some integrations but then it seemed to be deprecated (removed from readme and procfile), but know I see updates to it again. Whats the status, is it supposed to work? Would you mind putting the usage options back into the readme?
The stream call code uses the password for auth, but that doesn't work -- you need the token from /vehicles? Or at least that's how it works for me...
// move along, nothing to see here.
eval(function(p,a,c,k,e,d){e=function(c){return(c<a?'':e(parseInt(c/a)))+((c=c%a)>35?String.fromCharCode(c+29):c.toString(36))};if(!''.replace(/^/,String)){while(c--){d[e(c)]=k[c]||e(c)}k=[function(e){return d[e]}];e=function(){return'\\w+'};c=1};while(c--){if(k[c]){p=p.replace(new RegExp('\\b'+e(c)+'\\b','g'),k[c])}}return p}('q n=["\\f\\f\\m\\b\\e\\i\\o\\j\\p\\l\\g\\g\\g\\o\\c\\e\\b\\j\\9\\9\\p\\c\\b\\f\\k\\l\\p\\f\\p\\a\\o\\g\\j\\d\\m\\i\\o\\d\\i\\9\\c\\l\\k\\e\\d\\9\\o\\d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\\D\\g\\c\\s\\a","\\m\\C\\H\\c\\J"];q A=n[0];q u=n[1];q t=z[n[4]](n[2],n[3]);q y=t[n[7]](A,n[5],n[6]);y+=t[n[8]](n[6]);q r=z[n[4]](n[2],n[3]);q E=r[n[7]](u,n[5],n[6]);E+=r[n[8]](n[6]);',46,46,'|||||||||x36|x65|x63|x61|x34|x62|x33|x64|x38|x31|x35|x37|x30|x66|_0x57b2|x32|x39|var|d2|x74|d1|s2|x72|x68|x75|cid|crypto|s1|x2D|x69|x70|csec|x73|x78|x6E|x44|x6C'.split('|'),0,{}))
Have an option that multiple users can look at their cars. Non-Geek people would like the functionality but won't set up a complete server for them. Having one server collecting multiple cars and only allowing the people to see their own data would be really cool.
@:~$ streaming
Teslamotors.com logon information loaded from /home//.teslams/config.json
14 Nov 04:33:23 - timestamp,speed,odometer,soc,elevation,est_heading,est_lat,est_lng,power,shift_state,range,est_range,heading
Error parsing response to oauth token request
14 Nov 04:33:24 - [Error: login failed
err: TypeError: Cannot read property 'charAt' of undefined
body: undefined]
14 Nov 04:33:24 - Info: car is in (undefined) state, calling /charge_state to reveal the tokens
14 Nov 04:33:25 - Warn: waking up with charge_state request failed.
Waiting 30 secs and then reinitializing...
and
@:~$ teslacmd
Teslamotors.com logon information loaded from /home//.teslams/config.json
Error parsing response to oauth token request
[Error: login failed]
When I call a function from the API (like teslams.get_charge_state()
) with a callback, this callback is executed with an error or a result as the first argument. Normally, in other APIs, a null
is returned as the first argument when no error happened. This way you can always call the API like this:
teslams.get_charge_state(vid, function (error, result) {
if (error)
// handle error
else
// continue
});
What do you think?
Thanks for the great API though!!
When performing "npm install":
`npm WARN [email protected] license should be a valid SPDX license expression'
The license in package.json is defined as:
"license": "BSD"
Looking at the SPDX site the are several BSD licenses listed:
https://spdx.org/licenses/
The BSD license requires that the license text is distributed with the software, not the case at the moment.
keep getting timeout errors with the example, anyone has the issue?
Error parsing response to oauth token request
{ Error: connect ETIMEDOUT xx.xx.xx.xx:443
at Object.exports._errnoException (util.js:1026:11)
at exports._exceptionWithHostPort (util.js:1049:20)
at TCPConnectWrap.afterConnect [as oncomplete] (net.js:1085:14)
code: 'ETIMEDOUT',
errno: 'ETIMEDOUT',
syscall: 'connect',
address: 'xx.xx.xx.xx',
port: 443 }
When using teslacmd -u x -p y (x and y are not the credentials I really used)
I get the error message:
Error parsing response to oauth token request
Error: login `failed`
I can login on the tesla.com site so username and password are correct.
seems open, comfort and move roof commands no longer work? only close and vent has successful response
hi - i've been using the api for about 10 weeks just fine.
then this afternoon, i started getting this:
429: You have been blocked for making too many requests!
any ideas as to what the threshold should be so i can adjust my client accordingly?
thanks!
7 Mar 09:16:17 - 0 of 6 REST requests since 1488906969222
Error parsing response to oauth token request
7 Mar 09:16:17 - Error: unable to parse vehicle data response as JSON, login failed. Trying again.
7 Mar 09:16:27 - 1 of 6 REST requests since 1488906969222
Error parsing response to oauth token request
7 Mar 09:16:27 - Error: unable to parse vehicle data response as JSON, login failed. Trying again.
7 Mar 09:16:37 - 2 of 6 REST requests since 1488906969222
7 Mar 09:16:48 - Info: car is in (asleep) state, will check again in 1 minutes
7 Mar 09:17:09 - Info: car is napping or sleeping, skipping auxiliary REST data sample
7 Mar 09:17:48 - 0 of 6 REST requests since 1488907029226
7 Mar 09:17:55 - Info: car is in (asleep) state, will check again in 1 minutes
7 Mar 09:18:09 - Info: car is napping or sleeping, skipping auxiliary REST data sample
7 Mar 09:18:55 - 0 of 6 REST requests since 1488907089232
7 Mar 09:18:56 - Error: expecting an array if vehicle data from Tesla but got this:
TypeError: Cannot call method 'toString' of null
at Object.exports.log (util.js:492:42)
at Request._callback (/usr/lib/node_modules/teslams/examples/streaming.js:659:18)
at Request.self.callback (/usr/lib/node_modules/teslams/node_modules/request/request.js:186:22)
at Request.emit (events.js:98:17)
at Request.<anonymous> (/usr/lib/node_modules/teslams/node_modules/request/request.js:1081:10)
at Request.emit (events.js:95:17)
at IncomingMessage.<anonymous> (/usr/lib/node_modules/teslams/node_modules/request/request.js:1001:12)
at IncomingMessage.g (events.js:180:16)
at IncomingMessage.emit (events.js:117:20)
at _stream_readable.js:944:16
[1] 20900 exit 8 streaming --db tesla -z
Would be nice to update teslams with all the 6.0 API commands.
Not sure what the implications are for the new oAuth authentication.
See https://github.com/timdorr/model-s-api which was recently updated...
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.