serial-obd

Package for communicating with a serial/usb OBD-II reader.

npm install serial-obd
6 downloads in the last week
29 downloads in the last month

serial-obd

Serial communication for OBD-II ELM327 devices.

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

Limitations

  • Only tested on Ubuntu
  • Only tested with rfcomm, and not with actual serial port yet.
  • Only tested on ELM327 devices.
  • --WORK IN PROGRESS-- For the moment communicates with /dev/rfcomm0.
  • Not all OBD-II Commands are implemented yet.

This is an alpha version, so don't expect it to work without changing code.

Pre-requests

  • If it's a Bluetooth ELM327, then it should already be paired and connected with rfcomm connect!

    Install

    npm install node-serial-obd

    Documentation

    Basic usage

var OBDReader = require('node-serial-obd');
var serialOBDReader = new OBDReader();
var dataReceivedMarker = new Object();

serialOBDReader.on('dataReceived', function(data){
    console.log(data);
});

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

    this.addPoller("vss");
    this.addPoller("rpm");
    this.addPoller("temp");
    this.startPolling();
    //Time passes
    this.stopPolling();
});


serialOBDReader.connect(); //Connect

API

OBDReader

Event: ('dataReceived', data)

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

  • data - the data that was read and parsed to a reply object

Event: ('connected')

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

  • data - the data that was read and parsed to a reply object

OBDReader()

Creates an instance of OBDReader.

getPIDByName(Name)

Find a PID-value by name.

Params:
  • name Name of the PID you want the hexadecimal (in ASCII text) value of.
Return:
  • string PID in hexadecimal ASCII

parseOBDCommand(hexString)

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

Params:
  • string hexString Hexadecimal value in string that is received over the serialport.
Return:
  • 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.

connect()

Connect/Open the serial port and add events to serialport.

disconnect()

Disconnects/closes the port.

write(message)

Writes a message to the port.

Params:
  • string message The PID or AT Command you want to send. Without \r or \n!

requestValueByName(name)

Writes a PID value by entering a pid supported name.

Params:
  • string name Look into obdInfo.js for all PIDS.

addPoller(name)

Adds a poller to the poller-array.

Params:
  • string name Name of the poller you want to add.

removePoller(name)

Removes an poller.

Params:
  • string name Name of the poller you want to remove.

removeAllPollers()

Removes all pollers.

writePollers()

Writes all active pollers.

startPolling()

Starts polling.

stopPolling()

Stops polling.

LICENSE

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

npm loves you