This node module lets you communicate over a bluetooth serial port with OBD-II ELM327 Connectors using Node.js.
- Only tested on ELM327 devices.
- Not all OBD-II Commands are implemented yet.
- If it's a Bluetooth ELM327, then it should already be paired! If this hasn't been done, it will cause a connection error.
- bluetooth-serial-port (module that is used by this module, thanks to Eelco) requires libbluetooth-dev package: ** $ sudo apt-get install libbluetooth-dev
- If you're looking for serial RS23 connection, look into serial-obd.
npm install bluetooth-obd
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');
###OBDReader
Emitted when data is read from the OBD-II connector.
- data - the data that was read and parsed to a reply object
Emitted when the connection is set up (port is open).
Emitted when an error is encountered.
Emitted with debugging information.
Creates an instance of OBDReader.
Find a PID-value by name.
- name Name of the PID you want the hexadecimal (in ASCII text) value of.
- string PID in hexadecimal ASCII
Parses a hexadecimal string to a reply object. Uses PIDS. (obdInfo.js)
- string hexString Hexadecimal value in string that is received over the serialport.
- Object reply - The reply.
- string reply.value - The value that is already converted. This can be a PID converted answer or "OK" or "NO DATA".
- string reply.name - The name. --! Only if the reply is a PID.
- string reply.mode - The mode of the PID. --! Only if the reply is a PID.
- string reply.pid - The PID. --! Only if the reply is a PID.
Attempt discovery of the device based on a query string, and call connect() on the first match.
- string query (Optional) string to be matched against address/channel (fuzzy-ish)
Connect/Open the serial port and add events to serialport. Also starts the intervalWriter that is used to write the queue.
- string address MAC-address of device that will be connected to.
- number channel Channel that the serial port service runs on.
Disconnects/closes the port.
Writes a message to the port. (Queued!) All write functions call this function.
- string message The PID or AT Command you want to send. Without \r or \n!
- number replies The number of replies that are expected. Default = 0. 0 --> infinite
Writes a PID value by entering a pid supported name.
- string name Look into obdInfo.js for all PIDS.
Adds a poller to the poller-array.
- string name Name of the poller you want to add.
Removes an poller.
- string name Name of the poller you want to remove.
Removes all pollers.
Writes all active pollers.
Starts polling. Lower interval than activePollers * 50 will probably give buffer overflows.
- number interval Frequency how often all variables should be polled. (in ms) If no value is given, then for each activePoller 75ms will be added.
Stops polling.
This module is available under a Apache 2.0 license, see also the LICENSE file for details.