The W3C Vehicle Information API defines an Open Web Platform standard for HTML5/JavaScript application developers enabling Web connectivity through in-vehicle infotainment systems and vehicle data access protocols. This API can also be leveraged by HTML5/JavaScript applications running on mobile devices that access the data resources of a connected passenger vehicle.
This vehicle data API specification does not dictate or describe the access protocol or transport method used for the data connection. Data may come from numerous sources including OBD-II, CAN, LIN, etc. Bluetooth, WiFi, or cloud connections are all possible.
The key purpose of this specification is to promote an API enabling application development in a consistent manner across all automotive manufacturers. It is recognized, however, that the mechanisms required for access or control of vehicle Properties may differ between automobile manufacturers, makes and models. Furthermore, different automobile manufacturers may expose different Properties that can be read or set by an application.
As a result of these constraints, this specification shall allow for automobile manufacturer-specific extensions or restrictions. Extensions are only permitted for interfaces that are not already described by this API, and must be implemented to conform within the format and guidelines existing in this specification. If a Property is restricted, the automobile manufacturer would omit the optional feature in their implementation (see the Availability Section).
The target platform supported by the specification is exclusively passenger vehicles. Use of this specification for non-passenger applications (transportation, heavy machinery, marine, airline infotainment, military, etc.) is not prohibited, but is not covered in the design or content of the API and therefore may be insufficient.
Initially, a typical use case of Vehicle Information might be the implementation of a 'Virtual Mechanic' application that provides vehicle status information such as tire pressure, engine oil level, washer fluid level, battery status, etc. Future use case innovations in transportation, safety, navigation, smart energy grid and consumer infotainment and customization are all possible through this specification.
Web developers building interoperable applications based upon this W3C Vehicle API standard, will help empower a common web platform across consumer devices and passenger vehicles consistent with the Web of Things.
The Vehicle Information API provides operations to get access to the vehicle data (henceforth "properties") available from vehicle systems and also to change (write) a number of properties. Vehicle data types are available in the Vehicle Data specification.
An example of use is provided below:
var vehicle = navigator.vehicle; vehicle.vehicleSpeed.get().then(function(vehicleSpeed) { console.log("vehicle speed: " + vehicleSpeed.speed); }, function(error) { console.log("There was an error"); }); var vehicleSpeedSub = vehicle.vehicleSpeed.subscribe(function(vehicleSpeed) { console.log("vehicle speed changed to: " + vehicleSpeed.speed); vehicle.vehicleSpeed.unsubscribe(vehicleSpeedSub); }); var zone = new Zone; var zones = vehicle.climateControl.zones; for(var i in zones) { if(i.equals(zone.driver)) { var value = {}; value["acStatus"] = true; vehicle.climateControl.set(value, zone.driver).then(function(){ console.log("successfully set acStatus"); }, function(error) { console.log("there was an error"); }); } }
This specification defines conformance criteria that apply to a single product: the user agent that implements the interfaces that it contains.
Implementations that use ECMAScript to implement the APIs defined in this specification MUST implement them in a manner consistent with the ECMAScript Bindings defined in the Web IDL specification [[!WEBIDL]], as this specification uses that specification and terminology.
The
Promise
provide a convenient way to get access to the result of an operation.
It is expected that security of vehicle APIs described in this document is based on permissions dictated by:
The Vehicle interface represents the initial entry point for getting access to the vehicle information services, i.e. Engine Speed and Tire Pressure.
The Zone interface contains the constants that represent physical zones and logical zones
VehicleInterfaceError is used to identify the type of error encountered during an operation
The VehicleInterface interface represents the base interface to get all vehicle properties.
vehicle.vehicleSpeed.get().then(resolve); function resolve(data) { //data is of type VehicleSpeed console.log("Speed: " + data.speed); console.log("Time Stamp: " + data.timestamp); }
The VehicleConfigurationInterface interface is to be used to provide access to static vehicle information that never changes: external dimensions, identification, transmission type etc...
The VehicleSignalInterface interface represents vehicle signals that, as a rule, and unlike vehicle configurations, can change values, either programmatically (necessitating support for set method) or due to external events and occurrences, as reflected by subscription management.
var zone = Zone vehicle.door.set({"lock" : true}, zone.driver).then(resolve, reject); function resolve() { /// success } function reject(errorData) { console.log("Error occurred during set: " + errorData.message + " code: " + errorData.error); }
The availability API allows for developers to determine what attributes are available or not and if not, why. It also allows for notifications when the availability changes.
if( ( var a = vehicle.vehicleSpeed.availableForRetrieval("speed") ) === "available" ) { // we can use it. } else { // tell us why: console.log(a); }
var canHasVehicleSpeed = vehicle.vehicleSpeed.availableForSubscription("speed") === "available"; vehicle.vehicleSpeed.availabilityChangedListener( function (available) { canHasVehicleSpeed = available === "available"; checkVehicleSpeed(); }); function checkVehicleSpeed() { if(canHasVehicleSpeed) { vehicle.vehicleSpeed.get().then(callback); } }
The History API provides a way for applications to access logged data from the vehicle. What data is available and how much is up to the implementation. This section is OPTIONAL.
/// check if there is data being logged for vehicleSpeed: if(vehicle.vehicleSpeed.history.isLogged) { /// get all vehicleSpeed since it was first logged: vehicle.vehicleSpeed.history.get(vehicle.vehicleSpeed.history.from, vehicle.vehicleSpeed.history.to).then( function ( data ) { console.log(data.length); }); }