EricSmekens / node-bluetooth-obd

Node package for communication with Bluetooth OBD connectors.
Other
262 stars 72 forks source link
bluetooth-obd elm327 obd

NPM

bluetooth-obd - 0.2.5

Bluetooth communication for OBD-II ELM327 devices.

This node module lets you communicate over a bluetooth serial port with OBD-II ELM327 Connectors using Node.js.

Limitations

Pre-Requirements

Serial

Install

npm install bluetooth-obd

Documentation

Basic usage

var OBDReader = require('bluetooth-obd');
var btOBDReader = new OBDReader();
var dataReceivedMarker = {};

btOBDReader.on('connected', function () {
    //this.requestValueByName("vss"); //vss = vehicle speed sensor

    this.addPoller("vss");
    this.addPoller("rpm");
    this.addPoller("temp");
    this.addPoller("load_pct");
    this.addPoller("map");
    this.addPoller("frp");

    this.startPolling(1000); //Request all values each second.
});

btOBDReader.on('dataReceived', function (data) {
    console.log(data);
    dataReceivedMarker = data;
});

// Use first device with 'obd' in the name
btOBDReader.autoconnect('obd');

API

OBDReader

Event: ('dataReceived', data)

Emitted when data is read from the OBD-II connector.

Event: ('connected')

Emitted when the connection is set up (port is open).

Event: ('error', message)

Emitted when an error is encountered.

Event: ('debug', message)

Emitted with debugging information.

OBDReader()

Creates an instance of OBDReader.

getPIDByName(Name)

Find a PID-value by name.

Params:
Return:

parseOBDCommand(hexString)

Parses a hexadecimal string to a reply object. Uses PIDS. (obdInfo.js)

Params:
Return:

autoconnect(query)

Attempt discovery of the device based on a query string, and call connect() on the first match.

Params:

connect(address, channel)

Connect/Open the serial port and add events to serialport. Also starts the intervalWriter that is used to write the queue.

Params:

disconnect()

Disconnects/closes the port.

write(message, replies)

Writes a message to the port. (Queued!) All write functions call this function.

Params:

requestValueByName(name)

Writes a PID value by entering a pid supported name.

Params:

addPoller(name)

Adds a poller to the poller-array.

Params:

removePoller(name)

Removes an poller.

Params:

removeAllPollers()

Removes all pollers.

writePollers()

Writes all active pollers.

startPolling()

Starts polling. Lower interval than activePollers * 50 will probably give buffer overflows.

Params:

stopPolling()

Stops polling.

LICENSE

This module is available under a Apache 2.0 license, see also the LICENSE file for details.