How to use the teslajs.vehicleDataAsync 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
enqueueRequest();
				return;
			}

			// We need to wake up the car
			log('Waking vehicle...');
			await Tesla.wakeUpAsync(options);
			// When this request completes, the vehicle isn't already awoken. It's waking up.
			// The official Tesla app then does the vehicle data request repeatedly until it works
		}

		let result = null;
		for (let i = 1; i <= 20; i++) {
			// Retry at most 20 times
			try {
				result = await Tesla.vehicleDataAsync(options);
				break; // it worked
			} catch (ex) {
				log(`Error retrieving vehicle data on request ${i}: ${ex.message}`);

				if (i == 20) {
					throw ex; // this attempt failed
				}

				// Wait a second and try again
				await new Promise((resolve) => setTimeout(resolve, 1000));
			}
		}

		g_LastPoll = g_CarLastSeenAwake = Date.now();

		g_DataListenerSockets.forEach((socket) => {