How to use the teslajs.driveStateAsync function in teslajs

To help you get started, we’ve selected a few teslajs examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github DoctorMcKay / node-tesla-data / tesladata.js View on Github external
if (!vehicle) {
			return callback(new Error("Cannot find vehicle"));
		}

		if (!vehicle.tokens || !vehicle.tokens[0]) {
			return callback(new Error("No tokens found"));
		}

		if (['offline', 'asleep'].includes(vehicle.state)) {
			// Wake up the car first
			await Tesla.wakeUpAsync(options);
			await new Promise(resolve => setTimeout(resolve, 5000));
		}

		// Get the car's drive state because we need its coordinates
		let driveState = await Tesla.driveStateAsync(options);
		let latitude = driveState.latitude;
		let longitude = driveState.longitude;

		let success = false;

		let otherVehicleId = vehicle.vehicle_id;
		let token = vehicle.tokens[0];
		let ws = new WS13.WebSocket("wss://" + Config.tesla.email + ":" + token + "@streaming.vn.teslamotors.com/connect/" + otherVehicleId);
		ws.on('connected', () => {
			log("WS connected to Tesla API");
		});

		ws.on('disconnected', (code, reason, initiatedByUs) => {
			if (initiatedByUs) {
				log("Successfully disconnected from Tesla WS API");
			} else {
github mseminatore / alexa-tesla / index.js View on Github external
.then( function(vehicles) {
        var options = req.getSession().get("options");
        
        tjs.driveStateAsync(options)
        .done(function(driveState) {
            var state = driveState.shift_state || "Parked";
            var str ="";
            var dir = compassDirs(driveState.heading);
/*
        var lat = driveState.latitude || 0;
        var long = driveState.longitude || 0;

        request({
            method: 'GET',
            url: "http://api.geonames.org/findNearestAddressJSON?lat=" + lat + "&lng=" + long + "&username=demo",
            headers: { 'Content-Type': 'application/json; charset=utf-8' }
        }, function (error, response, body) {
            var loc = JSON.parse(body).address;

            var address = loc.streetNumber + " " + loc.street + " " + loc.placename + " " + loc.adminCode1;